diff options
Diffstat (limited to 'crates/ra_ide')
-rw-r--r-- | crates/ra_ide/src/call_info.rs | 21 | ||||
-rw-r--r-- | crates/ra_ide/src/completion/complete_pattern.rs | 4 | ||||
-rw-r--r-- | crates/ra_ide/src/completion/complete_record.rs | 2 | ||||
-rw-r--r-- | crates/ra_ide/src/completion/complete_unqualified_path.rs | 9 | ||||
-rw-r--r-- | crates/ra_ide/src/completion/completion_context.rs | 14 | ||||
-rw-r--r-- | crates/ra_ide/src/inlay_hints.rs | 17 |
6 files changed, 50 insertions, 17 deletions
diff --git a/crates/ra_ide/src/call_info.rs b/crates/ra_ide/src/call_info.rs index ca57eceff..f95b6baf3 100644 --- a/crates/ra_ide/src/call_info.rs +++ b/crates/ra_ide/src/call_info.rs | |||
@@ -208,9 +208,20 @@ mod tests { | |||
208 | } | 208 | } |
209 | } | 209 | } |
210 | 210 | ||
211 | fn call_info(text: &str) -> CallInfo { | 211 | fn call_info_helper(text: &str) -> Option<CallInfo> { |
212 | let (analysis, position) = single_file_with_position(text); | 212 | let (analysis, position) = single_file_with_position(text); |
213 | analysis.call_info(position).unwrap().unwrap() | 213 | analysis.call_info(position).unwrap() |
214 | } | ||
215 | |||
216 | fn call_info(text: &str) -> CallInfo { | ||
217 | let info = call_info_helper(text); | ||
218 | assert!(info.is_some()); | ||
219 | info.unwrap() | ||
220 | } | ||
221 | |||
222 | fn no_call_info(text: &str) { | ||
223 | let info = call_info_helper(text); | ||
224 | assert!(info.is_none()); | ||
214 | } | 225 | } |
215 | 226 | ||
216 | #[test] | 227 | #[test] |
@@ -558,9 +569,8 @@ fn main() { | |||
558 | } | 569 | } |
559 | 570 | ||
560 | #[test] | 571 | #[test] |
561 | #[should_panic] | ||
562 | fn cant_call_named_structs() { | 572 | fn cant_call_named_structs() { |
563 | let _ = call_info( | 573 | no_call_info( |
564 | r#" | 574 | r#" |
565 | struct TS { x: u32, y: i32 } | 575 | struct TS { x: u32, y: i32 } |
566 | fn main() { | 576 | fn main() { |
@@ -594,9 +604,8 @@ fn main() { | |||
594 | } | 604 | } |
595 | 605 | ||
596 | #[test] | 606 | #[test] |
597 | #[should_panic] | ||
598 | fn cant_call_enum_records() { | 607 | fn cant_call_enum_records() { |
599 | let _ = call_info( | 608 | no_call_info( |
600 | r#" | 609 | r#" |
601 | enum E { | 610 | enum E { |
602 | /// A Variant | 611 | /// A Variant |
diff --git a/crates/ra_ide/src/completion/complete_pattern.rs b/crates/ra_ide/src/completion/complete_pattern.rs index 1b7d3122f..a8b4ce114 100644 --- a/crates/ra_ide/src/completion/complete_pattern.rs +++ b/crates/ra_ide/src/completion/complete_pattern.rs | |||
@@ -7,6 +7,10 @@ pub(super) fn complete_pattern(acc: &mut Completions, ctx: &CompletionContext) { | |||
7 | if !ctx.is_pat_binding_or_const { | 7 | if !ctx.is_pat_binding_or_const { |
8 | return; | 8 | return; |
9 | } | 9 | } |
10 | if ctx.record_pat_syntax.is_some() { | ||
11 | return; | ||
12 | } | ||
13 | |||
10 | // FIXME: ideally, we should look at the type we are matching against and | 14 | // FIXME: ideally, we should look at the type we are matching against and |
11 | // suggest variants + auto-imports | 15 | // suggest variants + auto-imports |
12 | ctx.scope().process_all_names(&mut |name, res| { | 16 | ctx.scope().process_all_names(&mut |name, res| { |
diff --git a/crates/ra_ide/src/completion/complete_record.rs b/crates/ra_ide/src/completion/complete_record.rs index f46bcee5c..83a553155 100644 --- a/crates/ra_ide/src/completion/complete_record.rs +++ b/crates/ra_ide/src/completion/complete_record.rs | |||
@@ -2,7 +2,7 @@ | |||
2 | use crate::completion::{CompletionContext, Completions}; | 2 | use crate::completion::{CompletionContext, Completions}; |
3 | 3 | ||
4 | pub(super) fn complete_record(acc: &mut Completions, ctx: &CompletionContext) -> Option<()> { | 4 | pub(super) fn complete_record(acc: &mut Completions, ctx: &CompletionContext) -> Option<()> { |
5 | let missing_fields = match (ctx.record_lit_pat.as_ref(), ctx.record_lit_syntax.as_ref()) { | 5 | let missing_fields = match (ctx.record_pat_syntax.as_ref(), ctx.record_lit_syntax.as_ref()) { |
6 | (None, None) => return None, | 6 | (None, None) => return None, |
7 | (Some(_), Some(_)) => unreachable!("A record cannot be both a literal and a pattern"), | 7 | (Some(_), Some(_)) => unreachable!("A record cannot be both a literal and a pattern"), |
8 | (Some(record_pat), _) => ctx.sema.record_pattern_missing_fields(record_pat), | 8 | (Some(record_pat), _) => ctx.sema.record_pattern_missing_fields(record_pat), |
diff --git a/crates/ra_ide/src/completion/complete_unqualified_path.rs b/crates/ra_ide/src/completion/complete_unqualified_path.rs index efde9bf73..2d8e0776c 100644 --- a/crates/ra_ide/src/completion/complete_unqualified_path.rs +++ b/crates/ra_ide/src/completion/complete_unqualified_path.rs | |||
@@ -3,7 +3,14 @@ | |||
3 | use crate::completion::{CompletionContext, Completions}; | 3 | use crate::completion::{CompletionContext, Completions}; |
4 | 4 | ||
5 | pub(super) fn complete_unqualified_path(acc: &mut Completions, ctx: &CompletionContext) { | 5 | pub(super) fn complete_unqualified_path(acc: &mut Completions, ctx: &CompletionContext) { |
6 | if !(ctx.is_trivial_path && !ctx.is_pat_binding_or_const) { | 6 | if !ctx.is_trivial_path { |
7 | return; | ||
8 | } | ||
9 | |||
10 | if ctx.is_pat_binding_or_const | ||
11 | || ctx.record_lit_syntax.is_some() | ||
12 | || ctx.record_pat_syntax.is_some() | ||
13 | { | ||
7 | return; | 14 | return; |
8 | } | 15 | } |
9 | 16 | ||
diff --git a/crates/ra_ide/src/completion/completion_context.rs b/crates/ra_ide/src/completion/completion_context.rs index 6637afaf7..8b3401595 100644 --- a/crates/ra_ide/src/completion/completion_context.rs +++ b/crates/ra_ide/src/completion/completion_context.rs | |||
@@ -30,7 +30,7 @@ pub(crate) struct CompletionContext<'a> { | |||
30 | pub(super) function_syntax: Option<ast::FnDef>, | 30 | pub(super) function_syntax: Option<ast::FnDef>, |
31 | pub(super) use_item_syntax: Option<ast::UseItem>, | 31 | pub(super) use_item_syntax: Option<ast::UseItem>, |
32 | pub(super) record_lit_syntax: Option<ast::RecordLit>, | 32 | pub(super) record_lit_syntax: Option<ast::RecordLit>, |
33 | pub(super) record_lit_pat: Option<ast::RecordPat>, | 33 | pub(super) record_pat_syntax: Option<ast::RecordPat>, |
34 | pub(super) impl_def: Option<ast::ImplDef>, | 34 | pub(super) impl_def: Option<ast::ImplDef>, |
35 | pub(super) is_param: bool, | 35 | pub(super) is_param: bool, |
36 | /// If a name-binding or reference to a const in a pattern. | 36 | /// If a name-binding or reference to a const in a pattern. |
@@ -93,7 +93,7 @@ impl<'a> CompletionContext<'a> { | |||
93 | function_syntax: None, | 93 | function_syntax: None, |
94 | use_item_syntax: None, | 94 | use_item_syntax: None, |
95 | record_lit_syntax: None, | 95 | record_lit_syntax: None, |
96 | record_lit_pat: None, | 96 | record_pat_syntax: None, |
97 | impl_def: None, | 97 | impl_def: None, |
98 | is_param: false, | 98 | is_param: false, |
99 | is_pat_binding_or_const: false, | 99 | is_pat_binding_or_const: false, |
@@ -182,6 +182,11 @@ impl<'a> CompletionContext<'a> { | |||
182 | self.is_param = true; | 182 | self.is_param = true; |
183 | return; | 183 | return; |
184 | } | 184 | } |
185 | // FIXME: remove this (V) duplication and make the check more precise | ||
186 | if name_ref.syntax().ancestors().find_map(ast::RecordFieldPatList::cast).is_some() { | ||
187 | self.record_pat_syntax = | ||
188 | self.sema.find_node_at_offset_with_macros(&original_file, offset); | ||
189 | } | ||
185 | self.classify_name_ref(original_file, name_ref, offset); | 190 | self.classify_name_ref(original_file, name_ref, offset); |
186 | } | 191 | } |
187 | 192 | ||
@@ -211,8 +216,9 @@ impl<'a> CompletionContext<'a> { | |||
211 | self.is_param = true; | 216 | self.is_param = true; |
212 | return; | 217 | return; |
213 | } | 218 | } |
219 | // FIXME: remove this (^) duplication and make the check more precise | ||
214 | if name.syntax().ancestors().find_map(ast::RecordFieldPatList::cast).is_some() { | 220 | if name.syntax().ancestors().find_map(ast::RecordFieldPatList::cast).is_some() { |
215 | self.record_lit_pat = | 221 | self.record_pat_syntax = |
216 | self.sema.find_node_at_offset_with_macros(&original_file, offset); | 222 | self.sema.find_node_at_offset_with_macros(&original_file, offset); |
217 | } | 223 | } |
218 | } | 224 | } |
@@ -227,7 +233,7 @@ impl<'a> CompletionContext<'a> { | |||
227 | self.name_ref_syntax = | 233 | self.name_ref_syntax = |
228 | find_node_at_offset(&original_file, name_ref.syntax().text_range().start()); | 234 | find_node_at_offset(&original_file, name_ref.syntax().text_range().start()); |
229 | let name_range = name_ref.syntax().text_range(); | 235 | let name_range = name_ref.syntax().text_range(); |
230 | if name_ref.syntax().parent().and_then(ast::RecordField::cast).is_some() { | 236 | if ast::RecordField::for_field_name(&name_ref).is_some() { |
231 | self.record_lit_syntax = | 237 | self.record_lit_syntax = |
232 | self.sema.find_node_at_offset_with_macros(&original_file, offset); | 238 | self.sema.find_node_at_offset_with_macros(&original_file, offset); |
233 | } | 239 | } |
diff --git a/crates/ra_ide/src/inlay_hints.rs b/crates/ra_ide/src/inlay_hints.rs index da9f55a69..45b9f7802 100644 --- a/crates/ra_ide/src/inlay_hints.rs +++ b/crates/ra_ide/src/inlay_hints.rs | |||
@@ -235,7 +235,10 @@ 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 | if param_name.is_empty() || is_argument_similar_to_param(argument, param_name) { | 238 | if param_name.is_empty() |
239 | || is_argument_similar_to_param(argument, param_name) | ||
240 | || Some(param_name) == fn_signature.name.as_ref().map(String::as_str) | ||
241 | { | ||
239 | return false; | 242 | return false; |
240 | } | 243 | } |
241 | 244 | ||
@@ -247,10 +250,7 @@ fn should_show_param_hint( | |||
247 | 250 | ||
248 | // avoid displaying hints for common functions like map, filter, etc. | 251 | // avoid displaying hints for common functions like map, filter, etc. |
249 | // or other obvious words used in std | 252 | // or other obvious words used in std |
250 | if parameters_len == 1 && is_obvious_param(param_name) { | 253 | parameters_len != 1 || !is_obvious_param(param_name) |
251 | return false; | ||
252 | } | ||
253 | true | ||
254 | } | 254 | } |
255 | 255 | ||
256 | fn is_argument_similar_to_param(argument: &ast::Expr, param_name: &str) -> bool { | 256 | fn is_argument_similar_to_param(argument: &ast::Expr, param_name: &str) -> bool { |
@@ -1086,6 +1086,8 @@ impl Test { | |||
1086 | } | 1086 | } |
1087 | 1087 | ||
1088 | fn no_hints_expected(&self, _: i32, test_var: i32) {} | 1088 | fn no_hints_expected(&self, _: i32, test_var: i32) {} |
1089 | |||
1090 | fn frob(&self, frob: bool) {} | ||
1089 | } | 1091 | } |
1090 | 1092 | ||
1091 | struct Param {} | 1093 | struct Param {} |
@@ -1093,6 +1095,8 @@ struct Param {} | |||
1093 | fn different_order(param: &Param) {} | 1095 | fn different_order(param: &Param) {} |
1094 | fn different_order_mut(param: &mut Param) {} | 1096 | fn different_order_mut(param: &mut Param) {} |
1095 | 1097 | ||
1098 | fn twiddle(twiddle: bool) {} | ||
1099 | |||
1096 | fn main() { | 1100 | fn main() { |
1097 | let container: TestVarContainer = TestVarContainer { test_var: 42 }; | 1101 | let container: TestVarContainer = TestVarContainer { test_var: 42 }; |
1098 | let test: Test = Test {}; | 1102 | let test: Test = Test {}; |
@@ -1105,6 +1109,9 @@ fn main() { | |||
1105 | let test_var: i32 = 55; | 1109 | let test_var: i32 = 55; |
1106 | test_processed.no_hints_expected(22, test_var); | 1110 | test_processed.no_hints_expected(22, test_var); |
1107 | test_processed.no_hints_expected(33, container.test_var); | 1111 | test_processed.no_hints_expected(33, container.test_var); |
1112 | test_processed.frob(false); | ||
1113 | |||
1114 | twiddle(true); | ||
1108 | 1115 | ||
1109 | let param_begin: Param = Param {}; | 1116 | let param_begin: Param = Param {}; |
1110 | different_order(¶m_begin); | 1117 | different_order(¶m_begin); |