aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide
diff options
context:
space:
mode:
authorSteffen Lyngbaek <[email protected]>2020-03-12 03:14:39 +0000
committerSteffen Lyngbaek <[email protected]>2020-03-12 03:14:39 +0000
commit58248e24cd45adcbfd7bfd00e1487df196b4a8c6 (patch)
tree7221dea8daa9dcede6ffaede88c890de17586c51 /crates/ra_ide
parent974ed7155acccb5da0c2aeac09d7052c4f75902d (diff)
Switch from Vec<InlayKind> to object with props
- Instead of a single object type, use several individual nested types to allow toggling from the settings GUI - Remove unused struct definitions - Install and test that the toggles work
Diffstat (limited to 'crates/ra_ide')
-rw-r--r--crates/ra_ide/src/inlay_hints.rs23
1 files changed, 12 insertions, 11 deletions
diff --git a/crates/ra_ide/src/inlay_hints.rs b/crates/ra_ide/src/inlay_hints.rs
index 8454a975b..59922e14c 100644
--- a/crates/ra_ide/src/inlay_hints.rs
+++ b/crates/ra_ide/src/inlay_hints.rs
@@ -12,13 +12,14 @@ use crate::{FileId, FunctionSignature};
12 12
13#[derive(Clone, Debug, PartialEq, Eq)] 13#[derive(Clone, Debug, PartialEq, Eq)]
14pub struct InlayConfig { 14pub struct InlayConfig {
15 pub display_type: Vec<InlayKind>, 15 pub type_hints: bool,
16 pub parameter_hints: bool,
16 pub max_length: Option<usize>, 17 pub max_length: Option<usize>,
17} 18}
18 19
19impl Default for InlayConfig { 20impl Default for InlayConfig {
20 fn default() -> Self { 21 fn default() -> Self {
21 Self { display_type: vec![InlayKind::TypeHint, InlayKind::ParameterHint], max_length: None } 22 Self { type_hints: true, parameter_hints: true, max_length: None }
22 } 23 }
23} 24}
24 25
@@ -64,7 +65,7 @@ fn get_param_name_hints(
64 inlay_hint_opts: &InlayConfig, 65 inlay_hint_opts: &InlayConfig,
65 expr: ast::Expr, 66 expr: ast::Expr,
66) -> Option<()> { 67) -> Option<()> {
67 if !inlay_hint_opts.display_type.contains(&InlayKind::ParameterHint) { 68 if !inlay_hint_opts.parameter_hints {
68 return None; 69 return None;
69 } 70 }
70 71
@@ -104,7 +105,7 @@ fn get_bind_pat_hints(
104 inlay_hint_opts: &InlayConfig, 105 inlay_hint_opts: &InlayConfig,
105 pat: ast::BindPat, 106 pat: ast::BindPat,
106) -> Option<()> { 107) -> Option<()> {
107 if !inlay_hint_opts.display_type.contains(&InlayKind::TypeHint) { 108 if !inlay_hint_opts.type_hints {
108 return None; 109 return None;
109 } 110 }
110 111
@@ -223,7 +224,7 @@ fn get_fn_signature(sema: &Semantics<RootDatabase>, expr: &ast::Expr) -> Option<
223 224
224#[cfg(test)] 225#[cfg(test)]
225mod tests { 226mod tests {
226 use crate::inlay_hints::{InlayConfig, InlayKind}; 227 use crate::inlay_hints::InlayConfig;
227 use insta::assert_debug_snapshot; 228 use insta::assert_debug_snapshot;
228 229
229 use crate::mock_analysis::single_file; 230 use crate::mock_analysis::single_file;
@@ -237,7 +238,7 @@ mod tests {
237 let _x = foo(4, 4); 238 let _x = foo(4, 4);
238 }"#, 239 }"#,
239 ); 240 );
240 assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayConfig{ display_type: vec![InlayKind::ParameterHint], max_length: None}).unwrap(), @r###" 241 assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayConfig{ parameter_hints: true, type_hints: false, max_length: None}).unwrap(), @r###"
241 [ 242 [
242 InlayHint { 243 InlayHint {
243 range: [106; 107), 244 range: [106; 107),
@@ -261,7 +262,7 @@ mod tests {
261 let _x = foo(4, 4); 262 let _x = foo(4, 4);
262 }"#, 263 }"#,
263 ); 264 );
264 assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayConfig{ display_type: vec![], max_length: None}).unwrap(), @r###"[]"###); 265 assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayConfig{ type_hints: false, parameter_hints: false, max_length: None}).unwrap(), @r###"[]"###);
265 } 266 }
266 267
267 #[test] 268 #[test]
@@ -273,7 +274,7 @@ mod tests {
273 let _x = foo(4, 4); 274 let _x = foo(4, 4);
274 }"#, 275 }"#,
275 ); 276 );
276 assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayConfig{ display_type: vec![InlayKind::TypeHint], max_length: None}).unwrap(), @r###" 277 assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayConfig{ type_hints: true, parameter_hints: false, max_length: None}).unwrap(), @r###"
277 [ 278 [
278 InlayHint { 279 InlayHint {
279 range: [97; 99), 280 range: [97; 99),
@@ -810,7 +811,7 @@ fn main() {
810}"#, 811}"#,
811 ); 812 );
812 813
813 assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayConfig { display_type: vec![InlayKind::TypeHint, InlayKind::ParameterHint], max_length: Some(8) }).unwrap(), @r###" 814 assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayConfig { max_length: Some(8), ..Default::default() }).unwrap(), @r###"
814 [ 815 [
815 InlayHint { 816 InlayHint {
816 range: [74; 75), 817 range: [74; 75),
@@ -1020,7 +1021,7 @@ fn main() {
1020}"#, 1021}"#,
1021 ); 1022 );
1022 1023
1023 assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayConfig { display_type: vec![InlayKind::TypeHint, InlayKind::ParameterHint], max_length: Some(8) }).unwrap(), @r###" 1024 assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayConfig { max_length: Some(8), ..Default::default() }).unwrap(), @r###"
1024 [] 1025 []
1025 "### 1026 "###
1026 ); 1027 );
@@ -1046,7 +1047,7 @@ fn main() {
1046}"#, 1047}"#,
1047 ); 1048 );
1048 1049
1049 assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayConfig { display_type: vec![InlayKind::TypeHint, InlayKind::ParameterHint], max_length: Some(8) }).unwrap(), @r###" 1050 assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayConfig { max_length: Some(8), ..Default::default() }).unwrap(), @r###"
1050 [] 1051 []
1051 "### 1052 "###
1052 ); 1053 );