aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide/src')
-rw-r--r--crates/ra_ide/src/inlay_hints.rs11
-rw-r--r--crates/ra_ide/src/syntax_highlighting.rs3
-rw-r--r--crates/ra_ide/src/syntax_highlighting/tests.rs12
3 files changed, 24 insertions, 2 deletions
diff --git a/crates/ra_ide/src/inlay_hints.rs b/crates/ra_ide/src/inlay_hints.rs
index 45b9f7802..0774fa0a1 100644
--- a/crates/ra_ide/src/inlay_hints.rs
+++ b/crates/ra_ide/src/inlay_hints.rs
@@ -237,7 +237,8 @@ fn should_show_param_hint(
237) -> bool { 237) -> bool {
238 if param_name.is_empty() 238 if param_name.is_empty()
239 || is_argument_similar_to_param(argument, param_name) 239 || is_argument_similar_to_param(argument, param_name)
240 || Some(param_name) == fn_signature.name.as_ref().map(String::as_str) 240 || Some(param_name.trim_start_matches('_'))
241 == fn_signature.name.as_ref().map(|s| s.trim_start_matches('_'))
241 { 242 {
242 return false; 243 return false;
243 } 244 }
@@ -255,6 +256,8 @@ fn should_show_param_hint(
255 256
256fn is_argument_similar_to_param(argument: &ast::Expr, param_name: &str) -> bool { 257fn is_argument_similar_to_param(argument: &ast::Expr, param_name: &str) -> bool {
257 let argument_string = remove_ref(argument.clone()).syntax().to_string(); 258 let argument_string = remove_ref(argument.clone()).syntax().to_string();
259 let param_name = param_name.trim_start_matches('_');
260 let argument_string = argument_string.trim_start_matches('_');
258 argument_string.starts_with(&param_name) || argument_string.ends_with(&param_name) 261 argument_string.starts_with(&param_name) || argument_string.ends_with(&param_name)
259} 262}
260 263
@@ -1094,8 +1097,10 @@ struct Param {}
1094 1097
1095fn different_order(param: &Param) {} 1098fn different_order(param: &Param) {}
1096fn different_order_mut(param: &mut Param) {} 1099fn different_order_mut(param: &mut Param) {}
1100fn has_underscore(_param: bool) {}
1097 1101
1098fn twiddle(twiddle: bool) {} 1102fn twiddle(twiddle: bool) {}
1103fn doo(_doo: bool) {}
1099 1104
1100fn main() { 1105fn main() {
1101 let container: TestVarContainer = TestVarContainer { test_var: 42 }; 1106 let container: TestVarContainer = TestVarContainer { test_var: 42 };
@@ -1112,11 +1117,15 @@ fn main() {
1112 test_processed.frob(false); 1117 test_processed.frob(false);
1113 1118
1114 twiddle(true); 1119 twiddle(true);
1120 doo(true);
1115 1121
1116 let param_begin: Param = Param {}; 1122 let param_begin: Param = Param {};
1117 different_order(&param_begin); 1123 different_order(&param_begin);
1118 different_order(&mut param_begin); 1124 different_order(&mut param_begin);
1119 1125
1126 let param: bool = true;
1127 has_underscore(param);
1128
1120 let a: f64 = 7.0; 1129 let a: f64 = 7.0;
1121 let b: f64 = 4.0; 1130 let b: f64 = 4.0;
1122 let _: f64 = a.div_euclid(b); 1131 let _: f64 = a.div_euclid(b);
diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs
index 83d161f45..7b15b82bd 100644
--- a/crates/ra_ide/src/syntax_highlighting.rs
+++ b/crates/ra_ide/src/syntax_highlighting.rs
@@ -174,7 +174,8 @@ pub(crate) fn highlight(
174 } 174 }
175 175
176 assert_eq!(res.len(), 1, "after DFS traversal, the stack should only contain a single element"); 176 assert_eq!(res.len(), 1, "after DFS traversal, the stack should only contain a single element");
177 let res = res.pop().unwrap(); 177 let mut res = res.pop().unwrap();
178 res.sort_by_key(|range| range.range.start());
178 // Check that ranges are sorted and disjoint 179 // Check that ranges are sorted and disjoint
179 assert!(res 180 assert!(res
180 .iter() 181 .iter()
diff --git a/crates/ra_ide/src/syntax_highlighting/tests.rs b/crates/ra_ide/src/syntax_highlighting/tests.rs
index 110887c2a..73611e23a 100644
--- a/crates/ra_ide/src/syntax_highlighting/tests.rs
+++ b/crates/ra_ide/src/syntax_highlighting/tests.rs
@@ -156,3 +156,15 @@ fn main() {
156 fs::write(dst_file, &actual_html).unwrap(); 156 fs::write(dst_file, &actual_html).unwrap();
157 assert_eq_text!(expected_html, actual_html); 157 assert_eq_text!(expected_html, actual_html);
158} 158}
159
160#[test]
161fn ranges_sorted() {
162 let (analysis, file_id) = single_file(
163 r#"
164#[foo(bar = "bar")]
165macro_rules! test {}
166}"#
167 .trim(),
168 );
169 let _ = analysis.highlight(file_id).unwrap();
170}