diff options
-rw-r--r-- | crates/ra_ide_api/src/inlay_hints.rs | 42 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/main_loop/handlers.rs | 9 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/req.rs | 7 |
3 files changed, 15 insertions, 43 deletions
diff --git a/crates/ra_ide_api/src/inlay_hints.rs b/crates/ra_ide_api/src/inlay_hints.rs index a524e014f..60a2c7cf5 100644 --- a/crates/ra_ide_api/src/inlay_hints.rs +++ b/crates/ra_ide_api/src/inlay_hints.rs | |||
@@ -9,14 +9,9 @@ use ra_syntax::{ | |||
9 | SmolStr, SyntaxKind, SyntaxNode, TextRange, | 9 | SmolStr, SyntaxKind, SyntaxNode, TextRange, |
10 | }; | 10 | }; |
11 | 11 | ||
12 | #[derive(Debug, PartialEq, Eq, Clone)] | 12 | #[derive(Debug, PartialEq, Eq)] |
13 | pub enum InlayKind { | 13 | pub enum InlayKind { |
14 | LetBindingType, | 14 | TypeHint, |
15 | ClosureParameterType, | ||
16 | ForExpressionBindingType, | ||
17 | IfExpressionType, | ||
18 | WhileLetExpressionType, | ||
19 | MatchArmType, | ||
20 | } | 15 | } |
21 | 16 | ||
22 | #[derive(Debug)] | 17 | #[derive(Debug)] |
@@ -46,7 +41,7 @@ fn get_inlay_hints( | |||
46 | } | 41 | } |
47 | let pat = let_statement.pat()?; | 42 | let pat = let_statement.pat()?; |
48 | let analyzer = SourceAnalyzer::new(db, file_id, let_statement.syntax(), None); | 43 | let analyzer = SourceAnalyzer::new(db, file_id, let_statement.syntax(), None); |
49 | Some(get_pat_hints(db, &analyzer, pat, InlayKind::LetBindingType, false)) | 44 | Some(get_pat_type_hints(db, &analyzer, pat, false)) |
50 | }) | 45 | }) |
51 | .visit(|closure_parameter: LambdaExpr| { | 46 | .visit(|closure_parameter: LambdaExpr| { |
52 | let analyzer = SourceAnalyzer::new(db, file_id, closure_parameter.syntax(), None); | 47 | let analyzer = SourceAnalyzer::new(db, file_id, closure_parameter.syntax(), None); |
@@ -55,15 +50,7 @@ fn get_inlay_hints( | |||
55 | .params() | 50 | .params() |
56 | .filter(|closure_param| closure_param.ascribed_type().is_none()) | 51 | .filter(|closure_param| closure_param.ascribed_type().is_none()) |
57 | .filter_map(|closure_param| closure_param.pat()) | 52 | .filter_map(|closure_param| closure_param.pat()) |
58 | .map(|root_pat| { | 53 | .map(|root_pat| get_pat_type_hints(db, &analyzer, root_pat, false)) |
59 | get_pat_hints( | ||
60 | db, | ||
61 | &analyzer, | ||
62 | root_pat, | ||
63 | InlayKind::ClosureParameterType, | ||
64 | false, | ||
65 | ) | ||
66 | }) | ||
67 | .flatten() | 54 | .flatten() |
68 | .collect() | 55 | .collect() |
69 | }) | 56 | }) |
@@ -71,17 +58,17 @@ fn get_inlay_hints( | |||
71 | .visit(|for_expression: ForExpr| { | 58 | .visit(|for_expression: ForExpr| { |
72 | let pat = for_expression.pat()?; | 59 | let pat = for_expression.pat()?; |
73 | let analyzer = SourceAnalyzer::new(db, file_id, for_expression.syntax(), None); | 60 | let analyzer = SourceAnalyzer::new(db, file_id, for_expression.syntax(), None); |
74 | Some(get_pat_hints(db, &analyzer, pat, InlayKind::ForExpressionBindingType, false)) | 61 | Some(get_pat_type_hints(db, &analyzer, pat, false)) |
75 | }) | 62 | }) |
76 | .visit(|if_expr: IfExpr| { | 63 | .visit(|if_expr: IfExpr| { |
77 | let pat = if_expr.condition()?.pat()?; | 64 | let pat = if_expr.condition()?.pat()?; |
78 | let analyzer = SourceAnalyzer::new(db, file_id, if_expr.syntax(), None); | 65 | let analyzer = SourceAnalyzer::new(db, file_id, if_expr.syntax(), None); |
79 | Some(get_pat_hints(db, &analyzer, pat, InlayKind::IfExpressionType, true)) | 66 | Some(get_pat_type_hints(db, &analyzer, pat, true)) |
80 | }) | 67 | }) |
81 | .visit(|while_expr: WhileExpr| { | 68 | .visit(|while_expr: WhileExpr| { |
82 | let pat = while_expr.condition()?.pat()?; | 69 | let pat = while_expr.condition()?.pat()?; |
83 | let analyzer = SourceAnalyzer::new(db, file_id, while_expr.syntax(), None); | 70 | let analyzer = SourceAnalyzer::new(db, file_id, while_expr.syntax(), None); |
84 | Some(get_pat_hints(db, &analyzer, pat, InlayKind::WhileLetExpressionType, true)) | 71 | Some(get_pat_type_hints(db, &analyzer, pat, true)) |
85 | }) | 72 | }) |
86 | .visit(|match_arm_list: MatchArmList| { | 73 | .visit(|match_arm_list: MatchArmList| { |
87 | let analyzer = SourceAnalyzer::new(db, file_id, match_arm_list.syntax(), None); | 74 | let analyzer = SourceAnalyzer::new(db, file_id, match_arm_list.syntax(), None); |
@@ -90,9 +77,7 @@ fn get_inlay_hints( | |||
90 | .arms() | 77 | .arms() |
91 | .map(|match_arm| match_arm.pats()) | 78 | .map(|match_arm| match_arm.pats()) |
92 | .flatten() | 79 | .flatten() |
93 | .map(|root_pat| { | 80 | .map(|root_pat| get_pat_type_hints(db, &analyzer, root_pat, true)) |
94 | get_pat_hints(db, &analyzer, root_pat, InlayKind::MatchArmType, true) | ||
95 | }) | ||
96 | .flatten() | 81 | .flatten() |
97 | .collect(), | 82 | .collect(), |
98 | ) | 83 | ) |
@@ -100,11 +85,10 @@ fn get_inlay_hints( | |||
100 | .accept(&node)? | 85 | .accept(&node)? |
101 | } | 86 | } |
102 | 87 | ||
103 | fn get_pat_hints( | 88 | fn get_pat_type_hints( |
104 | db: &RootDatabase, | 89 | db: &RootDatabase, |
105 | analyzer: &SourceAnalyzer, | 90 | analyzer: &SourceAnalyzer, |
106 | root_pat: Pat, | 91 | root_pat: Pat, |
107 | kind: InlayKind, | ||
108 | skip_root_pat_hint: bool, | 92 | skip_root_pat_hint: bool, |
109 | ) -> Vec<InlayHint> { | 93 | ) -> Vec<InlayHint> { |
110 | let original_pat = &root_pat.clone(); | 94 | let original_pat = &root_pat.clone(); |
@@ -118,7 +102,7 @@ fn get_pat_hints( | |||
118 | }) | 102 | }) |
119 | .map(|(range, pat_type)| InlayHint { | 103 | .map(|(range, pat_type)| InlayHint { |
120 | range, | 104 | range, |
121 | kind: kind.clone(), | 105 | kind: InlayKind::TypeHint, |
122 | label: pat_type.display(db).to_string().into(), | 106 | label: pat_type.display(db).to_string().into(), |
123 | }) | 107 | }) |
124 | .collect() | 108 | .collect() |
@@ -364,7 +348,7 @@ fn main() { | |||
364 | if let CustomOption::Some(Test { a: CustomOption::Some(x), b: y }) = &test {}; | 348 | if let CustomOption::Some(Test { a: CustomOption::Some(x), b: y }) = &test {}; |
365 | if let CustomOption::Some(Test { a: CustomOption::None, b: y }) = &test {}; | 349 | if let CustomOption::Some(Test { a: CustomOption::None, b: y }) = &test {}; |
366 | if let CustomOption::Some(Test { b: y, .. }) = &test {}; | 350 | if let CustomOption::Some(Test { b: y, .. }) = &test {}; |
367 | 351 | ||
368 | if test == CustomOption::None {} | 352 | if test == CustomOption::None {} |
369 | }"#, | 353 | }"#, |
370 | ); | 354 | ); |
@@ -425,7 +409,7 @@ fn main() { | |||
425 | while let CustomOption::Some(Test { a: CustomOption::Some(x), b: y }) = &test {}; | 409 | while let CustomOption::Some(Test { a: CustomOption::Some(x), b: y }) = &test {}; |
426 | while let CustomOption::Some(Test { a: CustomOption::None, b: y }) = &test {}; | 410 | while let CustomOption::Some(Test { a: CustomOption::None, b: y }) = &test {}; |
427 | while let CustomOption::Some(Test { b: y, .. }) = &test {}; | 411 | while let CustomOption::Some(Test { b: y, .. }) = &test {}; |
428 | 412 | ||
429 | while test == CustomOption::None {} | 413 | while test == CustomOption::None {} |
430 | }"#, | 414 | }"#, |
431 | ); | 415 | ); |
@@ -445,7 +429,7 @@ fn main() { | |||
445 | let (analysis, file_id) = single_file( | 429 | let (analysis, file_id) = single_file( |
446 | r#" | 430 | r#" |
447 | #[derive(PartialEq)] | 431 | #[derive(PartialEq)] |
448 | enum CustomOption<T> { | 432 | enum CustomOption<T> { |
449 | None, | 433 | None, |
450 | Some(T), | 434 | Some(T), |
451 | } | 435 | } |
diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index c2a44ffa0..a6dc1f964 100644 --- a/crates/ra_lsp_server/src/main_loop/handlers.rs +++ b/crates/ra_lsp_server/src/main_loop/handlers.rs | |||
@@ -894,14 +894,7 @@ pub fn handle_inlay_hints( | |||
894 | label: api_type.label.to_string(), | 894 | label: api_type.label.to_string(), |
895 | range: api_type.range.conv_with(&line_index), | 895 | range: api_type.range.conv_with(&line_index), |
896 | kind: match api_type.kind { | 896 | kind: match api_type.kind { |
897 | ra_ide_api::InlayKind::LetBindingType => InlayKind::LetBindingType, | 897 | ra_ide_api::InlayKind::TypeHint => InlayKind::TypeHint, |
898 | ra_ide_api::InlayKind::ClosureParameterType => InlayKind::ClosureParameterType, | ||
899 | ra_ide_api::InlayKind::ForExpressionBindingType => { | ||
900 | InlayKind::ForExpressionBindingType | ||
901 | } | ||
902 | ra_ide_api::InlayKind::IfExpressionType => InlayKind::IfExpressionType, | ||
903 | ra_ide_api::InlayKind::WhileLetExpressionType => InlayKind::WhileLetExpressionType, | ||
904 | ra_ide_api::InlayKind::MatchArmType => InlayKind::MatchArmType, | ||
905 | }, | 898 | }, |
906 | }) | 899 | }) |
907 | .collect()) | 900 | .collect()) |
diff --git a/crates/ra_lsp_server/src/req.rs b/crates/ra_lsp_server/src/req.rs index 570438643..6b986bcc9 100644 --- a/crates/ra_lsp_server/src/req.rs +++ b/crates/ra_lsp_server/src/req.rs | |||
@@ -213,12 +213,7 @@ pub struct InlayHintsParams { | |||
213 | 213 | ||
214 | #[derive(Debug, PartialEq, Eq, Deserialize, Serialize)] | 214 | #[derive(Debug, PartialEq, Eq, Deserialize, Serialize)] |
215 | pub enum InlayKind { | 215 | pub enum InlayKind { |
216 | LetBindingType, | 216 | TypeHint, |
217 | ClosureParameterType, | ||
218 | ForExpressionBindingType, | ||
219 | IfExpressionType, | ||
220 | WhileLetExpressionType, | ||
221 | MatchArmType, | ||
222 | } | 217 | } |
223 | 218 | ||
224 | #[derive(Debug, Deserialize, Serialize)] | 219 | #[derive(Debug, Deserialize, Serialize)] |