diff options
Diffstat (limited to 'crates/ra_ide/src/inlay_hints.rs')
-rw-r--r-- | crates/ra_ide/src/inlay_hints.rs | 68 |
1 files changed, 34 insertions, 34 deletions
diff --git a/crates/ra_ide/src/inlay_hints.rs b/crates/ra_ide/src/inlay_hints.rs index f4f0751c0..d06fc03d3 100644 --- a/crates/ra_ide/src/inlay_hints.rs +++ b/crates/ra_ide/src/inlay_hints.rs | |||
@@ -11,14 +11,14 @@ use ra_syntax::{ | |||
11 | use crate::{FileId, FunctionSignature}; | 11 | use crate::{FileId, FunctionSignature}; |
12 | 12 | ||
13 | #[derive(Clone, Debug, PartialEq, Eq)] | 13 | #[derive(Clone, Debug, PartialEq, Eq)] |
14 | pub struct InlayHintsOptions { | 14 | pub struct InlayHintsConfig { |
15 | pub type_hints: bool, | 15 | pub type_hints: bool, |
16 | pub parameter_hints: bool, | 16 | pub parameter_hints: bool, |
17 | pub chaining_hints: bool, | 17 | pub chaining_hints: bool, |
18 | pub max_length: Option<usize>, | 18 | pub max_length: Option<usize>, |
19 | } | 19 | } |
20 | 20 | ||
21 | impl Default for InlayHintsOptions { | 21 | impl Default for InlayHintsConfig { |
22 | fn default() -> Self { | 22 | fn default() -> Self { |
23 | Self { type_hints: true, parameter_hints: true, chaining_hints: true, max_length: None } | 23 | Self { type_hints: true, parameter_hints: true, chaining_hints: true, max_length: None } |
24 | } | 24 | } |
@@ -41,7 +41,7 @@ pub struct InlayHint { | |||
41 | pub(crate) fn inlay_hints( | 41 | pub(crate) fn inlay_hints( |
42 | db: &RootDatabase, | 42 | db: &RootDatabase, |
43 | file_id: FileId, | 43 | file_id: FileId, |
44 | options: &InlayHintsOptions, | 44 | config: &InlayHintsConfig, |
45 | ) -> Vec<InlayHint> { | 45 | ) -> Vec<InlayHint> { |
46 | let _p = profile("inlay_hints"); | 46 | let _p = profile("inlay_hints"); |
47 | let sema = Semantics::new(db); | 47 | let sema = Semantics::new(db); |
@@ -50,14 +50,14 @@ pub(crate) fn inlay_hints( | |||
50 | let mut res = Vec::new(); | 50 | let mut res = Vec::new(); |
51 | for node in file.syntax().descendants() { | 51 | for node in file.syntax().descendants() { |
52 | if let Some(expr) = ast::Expr::cast(node.clone()) { | 52 | if let Some(expr) = ast::Expr::cast(node.clone()) { |
53 | get_chaining_hints(&mut res, &sema, options, expr); | 53 | get_chaining_hints(&mut res, &sema, config, expr); |
54 | } | 54 | } |
55 | 55 | ||
56 | match_ast! { | 56 | match_ast! { |
57 | match node { | 57 | match node { |
58 | ast::CallExpr(it) => { get_param_name_hints(&mut res, &sema, options, ast::Expr::from(it)); }, | 58 | ast::CallExpr(it) => { get_param_name_hints(&mut res, &sema, config, ast::Expr::from(it)); }, |
59 | ast::MethodCallExpr(it) => { get_param_name_hints(&mut res, &sema, options, ast::Expr::from(it)); }, | 59 | ast::MethodCallExpr(it) => { get_param_name_hints(&mut res, &sema, config, ast::Expr::from(it)); }, |
60 | ast::BindPat(it) => { get_bind_pat_hints(&mut res, &sema, options, it); }, | 60 | ast::BindPat(it) => { get_bind_pat_hints(&mut res, &sema, config, it); }, |
61 | _ => (), | 61 | _ => (), |
62 | } | 62 | } |
63 | } | 63 | } |
@@ -68,10 +68,10 @@ pub(crate) fn inlay_hints( | |||
68 | fn get_chaining_hints( | 68 | fn get_chaining_hints( |
69 | acc: &mut Vec<InlayHint>, | 69 | acc: &mut Vec<InlayHint>, |
70 | sema: &Semantics<RootDatabase>, | 70 | sema: &Semantics<RootDatabase>, |
71 | options: &InlayHintsOptions, | 71 | config: &InlayHintsConfig, |
72 | expr: ast::Expr, | 72 | expr: ast::Expr, |
73 | ) -> Option<()> { | 73 | ) -> Option<()> { |
74 | if !options.chaining_hints { | 74 | if !config.chaining_hints { |
75 | return None; | 75 | return None; |
76 | } | 76 | } |
77 | 77 | ||
@@ -95,7 +95,7 @@ fn get_chaining_hints( | |||
95 | let next = tokens.next()?.kind(); | 95 | let next = tokens.next()?.kind(); |
96 | let next_next = tokens.next()?.kind(); | 96 | let next_next = tokens.next()?.kind(); |
97 | if next == SyntaxKind::WHITESPACE && next_next == SyntaxKind::DOT { | 97 | if next == SyntaxKind::WHITESPACE && next_next == SyntaxKind::DOT { |
98 | let label = ty.display_truncated(sema.db, options.max_length).to_string(); | 98 | let label = ty.display_truncated(sema.db, config.max_length).to_string(); |
99 | acc.push(InlayHint { | 99 | acc.push(InlayHint { |
100 | range: expr.syntax().text_range(), | 100 | range: expr.syntax().text_range(), |
101 | kind: InlayKind::ChainingHint, | 101 | kind: InlayKind::ChainingHint, |
@@ -108,10 +108,10 @@ fn get_chaining_hints( | |||
108 | fn get_param_name_hints( | 108 | fn get_param_name_hints( |
109 | acc: &mut Vec<InlayHint>, | 109 | acc: &mut Vec<InlayHint>, |
110 | sema: &Semantics<RootDatabase>, | 110 | sema: &Semantics<RootDatabase>, |
111 | options: &InlayHintsOptions, | 111 | config: &InlayHintsConfig, |
112 | expr: ast::Expr, | 112 | expr: ast::Expr, |
113 | ) -> Option<()> { | 113 | ) -> Option<()> { |
114 | if !options.parameter_hints { | 114 | if !config.parameter_hints { |
115 | return None; | 115 | return None; |
116 | } | 116 | } |
117 | 117 | ||
@@ -148,10 +148,10 @@ fn get_param_name_hints( | |||
148 | fn get_bind_pat_hints( | 148 | fn get_bind_pat_hints( |
149 | acc: &mut Vec<InlayHint>, | 149 | acc: &mut Vec<InlayHint>, |
150 | sema: &Semantics<RootDatabase>, | 150 | sema: &Semantics<RootDatabase>, |
151 | options: &InlayHintsOptions, | 151 | config: &InlayHintsConfig, |
152 | pat: ast::BindPat, | 152 | pat: ast::BindPat, |
153 | ) -> Option<()> { | 153 | ) -> Option<()> { |
154 | if !options.type_hints { | 154 | if !config.type_hints { |
155 | return None; | 155 | return None; |
156 | } | 156 | } |
157 | 157 | ||
@@ -164,7 +164,7 @@ fn get_bind_pat_hints( | |||
164 | acc.push(InlayHint { | 164 | acc.push(InlayHint { |
165 | range: pat.syntax().text_range(), | 165 | range: pat.syntax().text_range(), |
166 | kind: InlayKind::TypeHint, | 166 | kind: InlayKind::TypeHint, |
167 | label: ty.display_truncated(sema.db, options.max_length).to_string().into(), | 167 | label: ty.display_truncated(sema.db, config.max_length).to_string().into(), |
168 | }); | 168 | }); |
169 | Some(()) | 169 | Some(()) |
170 | } | 170 | } |
@@ -270,7 +270,7 @@ fn get_fn_signature(sema: &Semantics<RootDatabase>, expr: &ast::Expr) -> Option< | |||
270 | 270 | ||
271 | #[cfg(test)] | 271 | #[cfg(test)] |
272 | mod tests { | 272 | mod tests { |
273 | use crate::inlay_hints::InlayHintsOptions; | 273 | use crate::inlay_hints::InlayHintsConfig; |
274 | use insta::assert_debug_snapshot; | 274 | use insta::assert_debug_snapshot; |
275 | 275 | ||
276 | use crate::mock_analysis::single_file; | 276 | use crate::mock_analysis::single_file; |
@@ -284,7 +284,7 @@ mod tests { | |||
284 | let _x = foo(4, 4); | 284 | let _x = foo(4, 4); |
285 | }"#, | 285 | }"#, |
286 | ); | 286 | ); |
287 | assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsOptions{ parameter_hints: true, type_hints: false, chaining_hints: false, max_length: None}).unwrap(), @r###" | 287 | assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig{ parameter_hints: true, type_hints: false, chaining_hints: false, max_length: None}).unwrap(), @r###" |
288 | [ | 288 | [ |
289 | InlayHint { | 289 | InlayHint { |
290 | range: [106; 107), | 290 | range: [106; 107), |
@@ -308,7 +308,7 @@ mod tests { | |||
308 | let _x = foo(4, 4); | 308 | let _x = foo(4, 4); |
309 | }"#, | 309 | }"#, |
310 | ); | 310 | ); |
311 | assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsOptions{ type_hints: false, parameter_hints: false, chaining_hints: false, max_length: None}).unwrap(), @r###"[]"###); | 311 | assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig{ type_hints: false, parameter_hints: false, chaining_hints: false, max_length: None}).unwrap(), @r###"[]"###); |
312 | } | 312 | } |
313 | 313 | ||
314 | #[test] | 314 | #[test] |
@@ -320,7 +320,7 @@ mod tests { | |||
320 | let _x = foo(4, 4); | 320 | let _x = foo(4, 4); |
321 | }"#, | 321 | }"#, |
322 | ); | 322 | ); |
323 | assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsOptions{ type_hints: true, parameter_hints: false, chaining_hints: false, max_length: None}).unwrap(), @r###" | 323 | assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig{ type_hints: true, parameter_hints: false, chaining_hints: false, max_length: None}).unwrap(), @r###" |
324 | [ | 324 | [ |
325 | InlayHint { | 325 | InlayHint { |
326 | range: [97; 99), | 326 | range: [97; 99), |
@@ -344,7 +344,7 @@ fn main() { | |||
344 | }"#, | 344 | }"#, |
345 | ); | 345 | ); |
346 | 346 | ||
347 | assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsOptions::default()).unwrap(), @r###" | 347 | assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig::default()).unwrap(), @r###" |
348 | [ | 348 | [ |
349 | InlayHint { | 349 | InlayHint { |
350 | range: [69; 71), | 350 | range: [69; 71), |
@@ -401,7 +401,7 @@ fn main() { | |||
401 | }"#, | 401 | }"#, |
402 | ); | 402 | ); |
403 | 403 | ||
404 | assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsOptions::default()).unwrap(), @r###" | 404 | assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig::default()).unwrap(), @r###" |
405 | [ | 405 | [ |
406 | InlayHint { | 406 | InlayHint { |
407 | range: [193; 197), | 407 | range: [193; 197), |
@@ -481,7 +481,7 @@ fn main() { | |||
481 | }"#, | 481 | }"#, |
482 | ); | 482 | ); |
483 | 483 | ||
484 | assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsOptions::default()).unwrap(), @r###" | 484 | assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig::default()).unwrap(), @r###" |
485 | [ | 485 | [ |
486 | InlayHint { | 486 | InlayHint { |
487 | range: [21; 30), | 487 | range: [21; 30), |
@@ -545,7 +545,7 @@ fn main() { | |||
545 | }"#, | 545 | }"#, |
546 | ); | 546 | ); |
547 | 547 | ||
548 | assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsOptions::default()).unwrap(), @r###" | 548 | assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig::default()).unwrap(), @r###" |
549 | [ | 549 | [ |
550 | InlayHint { | 550 | InlayHint { |
551 | range: [21; 30), | 551 | range: [21; 30), |
@@ -595,7 +595,7 @@ fn main() { | |||
595 | }"#, | 595 | }"#, |
596 | ); | 596 | ); |
597 | 597 | ||
598 | assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsOptions::default()).unwrap(), @r###" | 598 | assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig::default()).unwrap(), @r###" |
599 | [ | 599 | [ |
600 | InlayHint { | 600 | InlayHint { |
601 | range: [188; 192), | 601 | range: [188; 192), |
@@ -690,7 +690,7 @@ fn main() { | |||
690 | }"#, | 690 | }"#, |
691 | ); | 691 | ); |
692 | 692 | ||
693 | assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsOptions::default()).unwrap(), @r###" | 693 | assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig::default()).unwrap(), @r###" |
694 | [ | 694 | [ |
695 | InlayHint { | 695 | InlayHint { |
696 | range: [188; 192), | 696 | range: [188; 192), |
@@ -785,7 +785,7 @@ fn main() { | |||
785 | }"#, | 785 | }"#, |
786 | ); | 786 | ); |
787 | 787 | ||
788 | assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsOptions::default()).unwrap(), @r###" | 788 | assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig::default()).unwrap(), @r###" |
789 | [ | 789 | [ |
790 | InlayHint { | 790 | InlayHint { |
791 | range: [252; 256), | 791 | range: [252; 256), |
@@ -857,7 +857,7 @@ fn main() { | |||
857 | }"#, | 857 | }"#, |
858 | ); | 858 | ); |
859 | 859 | ||
860 | assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsOptions { max_length: Some(8), ..Default::default() }).unwrap(), @r###" | 860 | assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig { max_length: Some(8), ..Default::default() }).unwrap(), @r###" |
861 | [ | 861 | [ |
862 | InlayHint { | 862 | InlayHint { |
863 | range: [74; 75), | 863 | range: [74; 75), |
@@ -945,7 +945,7 @@ fn main() { | |||
945 | }"#, | 945 | }"#, |
946 | ); | 946 | ); |
947 | 947 | ||
948 | assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsOptions::default()).unwrap(), @r###" | 948 | assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig::default()).unwrap(), @r###" |
949 | [ | 949 | [ |
950 | InlayHint { | 950 | InlayHint { |
951 | range: [798; 809), | 951 | range: [798; 809), |
@@ -1067,7 +1067,7 @@ fn main() { | |||
1067 | }"#, | 1067 | }"#, |
1068 | ); | 1068 | ); |
1069 | 1069 | ||
1070 | assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsOptions { max_length: Some(8), ..Default::default() }).unwrap(), @r###" | 1070 | assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig { max_length: Some(8), ..Default::default() }).unwrap(), @r###" |
1071 | [] | 1071 | [] |
1072 | "### | 1072 | "### |
1073 | ); | 1073 | ); |
@@ -1093,7 +1093,7 @@ fn main() { | |||
1093 | }"#, | 1093 | }"#, |
1094 | ); | 1094 | ); |
1095 | 1095 | ||
1096 | assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsOptions { max_length: Some(8), ..Default::default() }).unwrap(), @r###" | 1096 | assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig { max_length: Some(8), ..Default::default() }).unwrap(), @r###" |
1097 | [] | 1097 | [] |
1098 | "### | 1098 | "### |
1099 | ); | 1099 | ); |
@@ -1115,7 +1115,7 @@ fn main() { | |||
1115 | .into_c(); | 1115 | .into_c(); |
1116 | }"#, | 1116 | }"#, |
1117 | ); | 1117 | ); |
1118 | assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsOptions{ parameter_hints: false, type_hints: false, chaining_hints: true, max_length: None}).unwrap(), @r###" | 1118 | assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig{ parameter_hints: false, type_hints: false, chaining_hints: true, max_length: None}).unwrap(), @r###" |
1119 | [ | 1119 | [ |
1120 | InlayHint { | 1120 | InlayHint { |
1121 | range: [232; 269), | 1121 | range: [232; 269), |
@@ -1144,7 +1144,7 @@ fn main() { | |||
1144 | let c = A(B(C)).into_b().into_c(); | 1144 | let c = A(B(C)).into_b().into_c(); |
1145 | }"#, | 1145 | }"#, |
1146 | ); | 1146 | ); |
1147 | assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsOptions{ parameter_hints: false, type_hints: false, chaining_hints: true, max_length: None}).unwrap(), @r###"[]"###); | 1147 | assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig{ parameter_hints: false, type_hints: false, chaining_hints: true, max_length: None}).unwrap(), @r###"[]"###); |
1148 | } | 1148 | } |
1149 | 1149 | ||
1150 | #[test] | 1150 | #[test] |
@@ -1162,7 +1162,7 @@ fn main() { | |||
1162 | .0; | 1162 | .0; |
1163 | }"#, | 1163 | }"#, |
1164 | ); | 1164 | ); |
1165 | assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsOptions{ parameter_hints: false, type_hints: false, chaining_hints: true, max_length: None}).unwrap(), @r###" | 1165 | assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig{ parameter_hints: false, type_hints: false, chaining_hints: true, max_length: None}).unwrap(), @r###" |
1166 | [ | 1166 | [ |
1167 | InlayHint { | 1167 | InlayHint { |
1168 | range: [150; 221), | 1168 | range: [150; 221), |
@@ -1204,7 +1204,7 @@ fn main() { | |||
1204 | .into_c(); | 1204 | .into_c(); |
1205 | }"#, | 1205 | }"#, |
1206 | ); | 1206 | ); |
1207 | 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, &InlayHintsConfig{ parameter_hints: false, type_hints: false, chaining_hints: true, max_length: None}).unwrap(), @r###" |
1208 | [ | 1208 | [ |
1209 | InlayHint { | 1209 | InlayHint { |
1210 | range: [403; 452), | 1210 | range: [403; 452), |