diff options
Diffstat (limited to 'crates/ra_ide')
-rw-r--r-- | crates/ra_ide/src/inlay_hints.rs | 22 |
1 files changed, 9 insertions, 13 deletions
diff --git a/crates/ra_ide/src/inlay_hints.rs b/crates/ra_ide/src/inlay_hints.rs index 293944206..07aab45ee 100644 --- a/crates/ra_ide/src/inlay_hints.rs +++ b/crates/ra_ide/src/inlay_hints.rs | |||
@@ -5,7 +5,7 @@ use ra_ide_db::RootDatabase; | |||
5 | use ra_prof::profile; | 5 | use ra_prof::profile; |
6 | use ra_syntax::{ | 6 | use ra_syntax::{ |
7 | ast::{self, ArgListOwner, AstNode, TypeAscriptionOwner}, | 7 | ast::{self, ArgListOwner, AstNode, TypeAscriptionOwner}, |
8 | match_ast, SmolStr, TextRange, NodeOrToken, SyntaxKind, Direction | 8 | match_ast, Direction, NodeOrToken, SmolStr, SyntaxKind, TextRange, |
9 | }; | 9 | }; |
10 | 10 | ||
11 | use crate::{FileId, FunctionSignature}; | 11 | use crate::{FileId, FunctionSignature}; |
@@ -20,12 +20,7 @@ pub struct InlayHintsOptions { | |||
20 | 20 | ||
21 | impl Default for InlayHintsOptions { | 21 | impl Default for InlayHintsOptions { |
22 | fn default() -> Self { | 22 | fn default() -> Self { |
23 | Self { | 23 | Self { type_hints: true, parameter_hints: true, chaining_hints: true, max_length: None } |
24 | type_hints: true, | ||
25 | parameter_hints: true, | ||
26 | chaining_hints: true, | ||
27 | max_length: None | ||
28 | } | ||
29 | } | 24 | } |
30 | } | 25 | } |
31 | 26 | ||
@@ -86,7 +81,8 @@ fn get_chaining_hints( | |||
86 | return None; | 81 | return None; |
87 | } | 82 | } |
88 | 83 | ||
89 | let mut tokens = expr.syntax() | 84 | let mut tokens = expr |
85 | .syntax() | ||
90 | .siblings_with_tokens(Direction::Next) | 86 | .siblings_with_tokens(Direction::Next) |
91 | .filter_map(NodeOrToken::into_token) | 87 | .filter_map(NodeOrToken::into_token) |
92 | .filter(|t| match t.kind() { | 88 | .filter(|t| match t.kind() { |
@@ -99,7 +95,7 @@ fn get_chaining_hints( | |||
99 | // Ignoring extra whitespace and comments | 95 | // Ignoring extra whitespace and comments |
100 | let next = tokens.next()?.kind(); | 96 | let next = tokens.next()?.kind(); |
101 | let next_next = tokens.next()?.kind(); | 97 | let next_next = tokens.next()?.kind(); |
102 | if next == SyntaxKind::WHITESPACE && next_next == SyntaxKind::DOT { | 98 | if next == SyntaxKind::WHITESPACE && next_next == SyntaxKind::DOT { |
103 | acc.push(InlayHint { | 99 | acc.push(InlayHint { |
104 | range: expr.syntax().text_range(), | 100 | range: expr.syntax().text_range(), |
105 | kind: InlayKind::ChainingHint, | 101 | kind: InlayKind::ChainingHint, |
@@ -1190,11 +1186,11 @@ fn main() { | |||
1190 | fn generic_chaining_hints() { | 1186 | fn generic_chaining_hints() { |
1191 | let (analysis, file_id) = single_file( | 1187 | let (analysis, file_id) = single_file( |
1192 | r#" | 1188 | r#" |
1193 | struct A<T>(T); | 1189 | struct A<T>(T); |
1194 | struct B<T>(T); | 1190 | struct B<T>(T); |
1195 | struct C<T>(T); | 1191 | struct C<T>(T); |
1196 | struct X<T,R>(T, R); | 1192 | struct X<T,R>(T, R); |
1197 | 1193 | ||
1198 | impl<T> A<T> { | 1194 | impl<T> A<T> { |
1199 | fn new(t: T) -> Self { A(t) } | 1195 | fn new(t: T) -> Self { A(t) } |
1200 | fn into_b(self) -> B<T> { B(self.0) } | 1196 | fn into_b(self) -> B<T> { B(self.0) } |
@@ -1211,12 +1207,12 @@ fn main() { | |||
1211 | assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsOptions{ parameter_hints: false, type_hints: false, chaining_hints: true, max_length: None}).unwrap(), @r###" | 1207 | assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsOptions{ parameter_hints: false, type_hints: false, chaining_hints: true, max_length: None}).unwrap(), @r###" |
1212 | [ | 1208 | [ |
1213 | InlayHint { | 1209 | InlayHint { |
1214 | range: [416; 465), | 1210 | range: [403; 452), |
1215 | kind: ChainingHint, | 1211 | kind: ChainingHint, |
1216 | label: "B<X<i32, bool>>", | 1212 | label: "B<X<i32, bool>>", |
1217 | }, | 1213 | }, |
1218 | InlayHint { | 1214 | InlayHint { |
1219 | range: [416; 435), | 1215 | range: [403; 422), |
1220 | kind: ChainingHint, | 1216 | kind: ChainingHint, |
1221 | label: "A<X<i32, bool>>", | 1217 | label: "A<X<i32, bool>>", |
1222 | }, | 1218 | }, |