diff options
Diffstat (limited to 'crates/ra_ide')
-rw-r--r-- | crates/ra_ide/src/completion/completion_context.rs | 5 | ||||
-rw-r--r-- | crates/ra_ide/src/inlay_hints.rs | 52 | ||||
-rw-r--r-- | crates/ra_ide/src/references.rs | 2 | ||||
-rw-r--r-- | crates/ra_ide/src/typing.rs | 2 |
4 files changed, 52 insertions, 9 deletions
diff --git a/crates/ra_ide/src/completion/completion_context.rs b/crates/ra_ide/src/completion/completion_context.rs index f833d2a9a..0e34d85db 100644 --- a/crates/ra_ide/src/completion/completion_context.rs +++ b/crates/ra_ide/src/completion/completion_context.rs | |||
@@ -190,7 +190,10 @@ impl<'a> CompletionContext<'a> { | |||
190 | if let Some(name) = find_node_at_offset::<ast::Name>(&file_with_fake_ident, offset) { | 190 | if let Some(name) = find_node_at_offset::<ast::Name>(&file_with_fake_ident, offset) { |
191 | if let Some(bind_pat) = name.syntax().ancestors().find_map(ast::BindPat::cast) { | 191 | if let Some(bind_pat) = name.syntax().ancestors().find_map(ast::BindPat::cast) { |
192 | self.is_pat_binding_or_const = true; | 192 | self.is_pat_binding_or_const = true; |
193 | if bind_pat.has_at() || bind_pat.is_ref() || bind_pat.is_mutable() { | 193 | if bind_pat.at_token().is_some() |
194 | || bind_pat.ref_kw_token().is_some() | ||
195 | || bind_pat.mut_kw_token().is_some() | ||
196 | { | ||
194 | self.is_pat_binding_or_const = false; | 197 | self.is_pat_binding_or_const = false; |
195 | } | 198 | } |
196 | if bind_pat.syntax().parent().and_then(ast::RecordFieldPatList::cast).is_some() { | 199 | if bind_pat.syntax().parent().and_then(ast::RecordFieldPatList::cast).is_some() { |
diff --git a/crates/ra_ide/src/inlay_hints.rs b/crates/ra_ide/src/inlay_hints.rs index 4b133b19b..da9f55a69 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 | ||
3 | use hir::{Adt, HirDisplay, Semantics, Type}; | 3 | use hir::{Adt, HirDisplay, Semantics, Type}; |
4 | use ra_ide_db::RootDatabase; | 4 | use ra_ide_db::RootDatabase; |
@@ -235,8 +235,7 @@ fn should_show_param_hint( | |||
235 | param_name: &str, | 235 | param_name: &str, |
236 | argument: &ast::Expr, | 236 | argument: &ast::Expr, |
237 | ) -> bool { | 237 | ) -> bool { |
238 | let argument_string = argument.syntax().to_string(); | 238 | if param_name.is_empty() || is_argument_similar_to_param(argument, param_name) { |
239 | if param_name.is_empty() || argument_string.ends_with(param_name) { | ||
240 | return false; | 239 | return false; |
241 | } | 240 | } |
242 | 241 | ||
@@ -245,14 +244,37 @@ fn should_show_param_hint( | |||
245 | } else { | 244 | } else { |
246 | fn_signature.parameters.len() | 245 | fn_signature.parameters.len() |
247 | }; | 246 | }; |
247 | |||
248 | // avoid displaying hints for common functions like map, filter, etc. | 248 | // avoid displaying hints for common functions like map, filter, etc. |
249 | if parameters_len == 1 && (param_name.len() == 1 || param_name == "predicate") { | 249 | // or other obvious words used in std |
250 | if parameters_len == 1 && is_obvious_param(param_name) { | ||
250 | return false; | 251 | return false; |
251 | } | 252 | } |
252 | |||
253 | true | 253 | true |
254 | } | 254 | } |
255 | 255 | ||
256 | fn is_argument_similar_to_param(argument: &ast::Expr, param_name: &str) -> bool { | ||
257 | let argument_string = remove_ref(argument.clone()).syntax().to_string(); | ||
258 | argument_string.starts_with(¶m_name) || argument_string.ends_with(¶m_name) | ||
259 | } | ||
260 | |||
261 | fn remove_ref(expr: ast::Expr) -> ast::Expr { | ||
262 | if let ast::Expr::RefExpr(ref_expr) = &expr { | ||
263 | if let Some(inner) = ref_expr.expr() { | ||
264 | return inner; | ||
265 | } | ||
266 | } | ||
267 | expr | ||
268 | } | ||
269 | |||
270 | fn is_obvious_param(param_name: &str) -> bool { | ||
271 | let is_obvious_param_name = match param_name { | ||
272 | "predicate" | "value" | "pat" | "rhs" | "other" => true, | ||
273 | _ => false, | ||
274 | }; | ||
275 | param_name.len() == 1 || is_obvious_param_name | ||
276 | } | ||
277 | |||
256 | fn get_fn_signature(sema: &Semantics<RootDatabase>, expr: &ast::Expr) -> Option<FunctionSignature> { | 278 | fn get_fn_signature(sema: &Semantics<RootDatabase>, expr: &ast::Expr) -> Option<FunctionSignature> { |
257 | match expr { | 279 | match expr { |
258 | ast::Expr::CallExpr(expr) => { | 280 | ast::Expr::CallExpr(expr) => { |
@@ -1059,9 +1081,18 @@ impl Test { | |||
1059 | self | 1081 | self |
1060 | } | 1082 | } |
1061 | 1083 | ||
1084 | fn field(self, value: i32) -> Self { | ||
1085 | self | ||
1086 | } | ||
1087 | |||
1062 | fn no_hints_expected(&self, _: i32, test_var: i32) {} | 1088 | fn no_hints_expected(&self, _: i32, test_var: i32) {} |
1063 | } | 1089 | } |
1064 | 1090 | ||
1091 | struct Param {} | ||
1092 | |||
1093 | fn different_order(param: &Param) {} | ||
1094 | fn different_order_mut(param: &mut Param) {} | ||
1095 | |||
1065 | fn main() { | 1096 | fn main() { |
1066 | let container: TestVarContainer = TestVarContainer { test_var: 42 }; | 1097 | let container: TestVarContainer = TestVarContainer { test_var: 42 }; |
1067 | let test: Test = Test {}; | 1098 | let test: Test = Test {}; |
@@ -1069,11 +1100,20 @@ fn main() { | |||
1069 | map(22); | 1100 | map(22); |
1070 | filter(33); | 1101 | filter(33); |
1071 | 1102 | ||
1072 | let test_processed: Test = test.map(1).filter(2); | 1103 | let test_processed: Test = test.map(1).filter(2).field(3); |
1073 | 1104 | ||
1074 | let test_var: i32 = 55; | 1105 | let test_var: i32 = 55; |
1075 | test_processed.no_hints_expected(22, test_var); | 1106 | test_processed.no_hints_expected(22, test_var); |
1076 | test_processed.no_hints_expected(33, container.test_var); | 1107 | test_processed.no_hints_expected(33, container.test_var); |
1108 | |||
1109 | let param_begin: Param = Param {}; | ||
1110 | different_order(¶m_begin); | ||
1111 | different_order(&mut param_begin); | ||
1112 | |||
1113 | let a: f64 = 7.0; | ||
1114 | let b: f64 = 4.0; | ||
1115 | let _: f64 = a.div_euclid(b); | ||
1116 | let _: f64 = a.abs_sub(b); | ||
1077 | }"#, | 1117 | }"#, |
1078 | ); | 1118 | ); |
1079 | 1119 | ||
diff --git a/crates/ra_ide/src/references.rs b/crates/ra_ide/src/references.rs index 746cc86ba..ad6fd50aa 100644 --- a/crates/ra_ide/src/references.rs +++ b/crates/ra_ide/src/references.rs | |||
@@ -152,7 +152,7 @@ fn decl_access(def: &Definition, syntax: &SyntaxNode, range: TextRange) -> Optio | |||
152 | if stmt.initializer().is_some() { | 152 | if stmt.initializer().is_some() { |
153 | let pat = stmt.pat()?; | 153 | let pat = stmt.pat()?; |
154 | if let ast::Pat::BindPat(it) = pat { | 154 | if let ast::Pat::BindPat(it) = pat { |
155 | if it.is_mutable() { | 155 | if it.mut_kw_token().is_some() { |
156 | return Some(ReferenceAccess::Write); | 156 | return Some(ReferenceAccess::Write); |
157 | } | 157 | } |
158 | } | 158 | } |
diff --git a/crates/ra_ide/src/typing.rs b/crates/ra_ide/src/typing.rs index cb2cd2479..71d2bcb04 100644 --- a/crates/ra_ide/src/typing.rs +++ b/crates/ra_ide/src/typing.rs | |||
@@ -63,7 +63,7 @@ fn on_char_typed_inner( | |||
63 | fn on_eq_typed(file: &SourceFile, offset: TextUnit) -> Option<SingleFileChange> { | 63 | fn on_eq_typed(file: &SourceFile, offset: TextUnit) -> Option<SingleFileChange> { |
64 | assert_eq!(file.syntax().text().char_at(offset), Some('=')); | 64 | assert_eq!(file.syntax().text().char_at(offset), Some('=')); |
65 | let let_stmt: ast::LetStmt = find_node_at_offset(file.syntax(), offset)?; | 65 | let let_stmt: ast::LetStmt = find_node_at_offset(file.syntax(), offset)?; |
66 | if let_stmt.has_semi() { | 66 | if let_stmt.semi_token().is_some() { |
67 | return None; | 67 | return None; |
68 | } | 68 | } |
69 | if let Some(expr) = let_stmt.initializer() { | 69 | if let Some(expr) = let_stmt.initializer() { |