aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide/src/inlay_hints.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide/src/inlay_hints.rs')
-rw-r--r--crates/ra_ide/src/inlay_hints.rs34
1 files changed, 30 insertions, 4 deletions
diff --git a/crates/ra_ide/src/inlay_hints.rs b/crates/ra_ide/src/inlay_hints.rs
index 4b133b19b..6a4fe15fd 100644
--- a/crates/ra_ide/src/inlay_hints.rs
+++ b/crates/ra_ide/src/inlay_hints.rs
@@ -1,4 +1,4 @@
1//! FIXME: write short doc here 1//! This module defines multiple types of inlay hints and their visibility
2 2
3use hir::{Adt, HirDisplay, Semantics, Type}; 3use hir::{Adt, HirDisplay, Semantics, Type};
4use ra_ide_db::RootDatabase; 4use ra_ide_db::RootDatabase;
@@ -236,7 +236,10 @@ fn should_show_param_hint(
236 argument: &ast::Expr, 236 argument: &ast::Expr,
237) -> bool { 237) -> bool {
238 let argument_string = argument.syntax().to_string(); 238 let argument_string = argument.syntax().to_string();
239 if param_name.is_empty() || argument_string.ends_with(param_name) { 239 if param_name.is_empty()
240 || argument_string.ends_with(&param_name)
241 || argument_string.starts_with(&param_name)
242 {
240 return false; 243 return false;
241 } 244 }
242 245
@@ -245,8 +248,15 @@ fn should_show_param_hint(
245 } else { 248 } else {
246 fn_signature.parameters.len() 249 fn_signature.parameters.len()
247 }; 250 };
251
248 // avoid displaying hints for common functions like map, filter, etc. 252 // avoid displaying hints for common functions like map, filter, etc.
249 if parameters_len == 1 && (param_name.len() == 1 || param_name == "predicate") { 253 // or other obvious words used in std
254 // TODO ignore "bytes" if the type is [u8; n]
255 let is_obvious_param_name = match param_name {
256 "predicate" | "value" | "pat" | "rhs" | "other" => true,
257 _ => false,
258 };
259 if parameters_len == 1 && (param_name.len() == 1 || is_obvious_param_name) {
250 return false; 260 return false;
251 } 261 }
252 262
@@ -1059,9 +1069,17 @@ impl Test {
1059 self 1069 self
1060 } 1070 }
1061 1071
1072 fn field(self, value: i32) -> Self {
1073 self
1074 }
1075
1062 fn no_hints_expected(&self, _: i32, test_var: i32) {} 1076 fn no_hints_expected(&self, _: i32, test_var: i32) {}
1063} 1077}
1064 1078
1079struct Param {}
1080
1081fn different_order(param: Param) {}
1082
1065fn main() { 1083fn main() {
1066 let container: TestVarContainer = TestVarContainer { test_var: 42 }; 1084 let container: TestVarContainer = TestVarContainer { test_var: 42 };
1067 let test: Test = Test {}; 1085 let test: Test = Test {};
@@ -1069,11 +1087,19 @@ fn main() {
1069 map(22); 1087 map(22);
1070 filter(33); 1088 filter(33);
1071 1089
1072 let test_processed: Test = test.map(1).filter(2); 1090 let test_processed: Test = test.map(1).filter(2).field(3);
1073 1091
1074 let test_var: i32 = 55; 1092 let test_var: i32 = 55;
1075 test_processed.no_hints_expected(22, test_var); 1093 test_processed.no_hints_expected(22, test_var);
1076 test_processed.no_hints_expected(33, container.test_var); 1094 test_processed.no_hints_expected(33, container.test_var);
1095
1096 let param_begin: Param = Param {};
1097 different_order(param_begin);
1098
1099 let a: f64 = 7.0;
1100 let b: f64 = 4.0;
1101 let _: f64 = a.div_euclid(b);
1102 let _: f64 = a.abs_sub(b);
1077}"#, 1103}"#,
1078 ); 1104 );
1079 1105