mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 12:54:58 +00:00
Merge #7703
7703: Allow comments between newlines in chaining hints r=Veykril a=unratito Currently, chaining hints are not generated if there are comments between newlines, which is a very common pattern: ```rust let vec = (0..10) // Multiply by 2 .map(|x| x * 2) // Add 3 .map(|x| x + 3) .collect::<Vec<i32>>(); ``` Besides, it seems a bit weird that this piece of code generates a chaining hint: ```rust let vec = (0..10) .collect::<Vec<i32>>(); ``` But this one doesn't: ```rust let vec = (0..10) // This is a comment .collect::<Vec<i32>>(); ``` Co-authored-by: Paco Soberón <unratito@gmail.com>
This commit is contained in:
commit
b3c848ee28
1 changed files with 22 additions and 16 deletions
|
@ -109,8 +109,12 @@ fn get_chaining_hints(
|
|||
// Chaining can be defined as an expression whose next sibling tokens are newline and dot
|
||||
// Ignoring extra whitespace and comments
|
||||
let next = tokens.next()?.kind();
|
||||
let next_next = tokens.next()?.kind();
|
||||
if next == SyntaxKind::WHITESPACE && next_next == T![.] {
|
||||
if next == SyntaxKind::WHITESPACE {
|
||||
let mut next_next = tokens.next()?.kind();
|
||||
while next_next == SyntaxKind::WHITESPACE {
|
||||
next_next = tokens.next()?.kind();
|
||||
}
|
||||
if next_next == T![.] {
|
||||
let ty = sema.type_of_expr(&expr)?;
|
||||
if ty.is_unknown() {
|
||||
return None;
|
||||
|
@ -130,6 +134,7 @@ fn get_chaining_hints(
|
|||
}),
|
||||
});
|
||||
}
|
||||
}
|
||||
Some(())
|
||||
}
|
||||
|
||||
|
@ -983,6 +988,7 @@ struct C;
|
|||
fn main() {
|
||||
let c = A(B(C))
|
||||
.into_b() // This is a comment
|
||||
// This is another comment
|
||||
.into_c();
|
||||
}
|
||||
"#,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue