aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorIceSentry <[email protected]>2020-04-08 22:48:16 +0100
committerIceSentry <[email protected]>2020-04-08 22:48:16 +0100
commit2a582b78a5f9c1fa908fe5f4c9ff4ab2966adb2e (patch)
treedbafffe37940a2a641abc338c1a6139120717f1a /crates
parent779555c1beac90f633c01a773558c4007c99c97f (diff)
Add more heuristics for hiding obvious param hints
This will now hide "value", "pat", "rhs" and "other" These words were selected from the std because they are used in common functions with only a single param and are obvious by their use. I think it would be good to also hide "bytes" if the type is `[u8; n]` but I'm not sure how to get the param type signature It will also hide the hint if the passed param starts or end with the param_name
Diffstat (limited to 'crates')
-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