aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide/src/completion
diff options
context:
space:
mode:
authorBenjamin Coenen <[email protected]>2020-04-14 18:20:30 +0100
committerBenjamin Coenen <[email protected]>2020-04-14 18:20:30 +0100
commitb092bbc83d13af6a79f8f282632ec1ea0a1560bd (patch)
tree2638559990ee6a93cd3b6d6d957b67063eb75c2d /crates/ra_ide/src/completion
parent064095742980d4c825391f643e437520599f51d8 (diff)
parentc82e7696e6f86cc0843c5aab9f09b5d6dd0d4bac (diff)
Merge branch 'master' of github.com:rust-analyzer/rust-analyzer
Diffstat (limited to 'crates/ra_ide/src/completion')
-rw-r--r--crates/ra_ide/src/completion/complete_pattern.rs4
-rw-r--r--crates/ra_ide/src/completion/complete_record.rs2
-rw-r--r--crates/ra_ide/src/completion/complete_unqualified_path.rs9
-rw-r--r--crates/ra_ide/src/completion/completion_context.rs12
4 files changed, 22 insertions, 5 deletions
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 @@
2use crate::completion::{CompletionContext, Completions}; 2use crate::completion::{CompletionContext, Completions};
3 3
4pub(super) fn complete_record(acc: &mut Completions, ctx: &CompletionContext) -> Option<()> { 4pub(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 0b0da6ee4..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 @@
3use crate::completion::{CompletionContext, Completions}; 3use crate::completion::{CompletionContext, Completions};
4 4
5pub(super) fn complete_unqualified_path(acc: &mut Completions, ctx: &CompletionContext) { 5pub(super) fn complete_unqualified_path(acc: &mut Completions, ctx: &CompletionContext) {
6 if !(ctx.is_trivial_path && !ctx.is_pat_binding_or_const && !ctx.record_lit_syntax.is_some()) { 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 eb8016dd1..da054f7a2 100644
--- a/crates/ra_ide/src/completion/completion_context.rs
+++ b/crates/ra_ide/src/completion/completion_context.rs
@@ -31,7 +31,7 @@ pub(crate) struct CompletionContext<'a> {
31 pub(super) function_syntax: Option<ast::FnDef>, 31 pub(super) function_syntax: Option<ast::FnDef>,
32 pub(super) use_item_syntax: Option<ast::UseItem>, 32 pub(super) use_item_syntax: Option<ast::UseItem>,
33 pub(super) record_lit_syntax: Option<ast::RecordLit>, 33 pub(super) record_lit_syntax: Option<ast::RecordLit>,
34 pub(super) record_lit_pat: Option<ast::RecordPat>, 34 pub(super) record_pat_syntax: Option<ast::RecordPat>,
35 pub(super) impl_def: Option<ast::ImplDef>, 35 pub(super) impl_def: Option<ast::ImplDef>,
36 pub(super) call_info: Option<CallInfo>, 36 pub(super) call_info: Option<CallInfo>,
37 pub(super) is_param: bool, 37 pub(super) is_param: bool,
@@ -97,7 +97,7 @@ impl<'a> CompletionContext<'a> {
97 call_info: None, 97 call_info: None,
98 use_item_syntax: None, 98 use_item_syntax: None,
99 record_lit_syntax: None, 99 record_lit_syntax: None,
100 record_lit_pat: None, 100 record_pat_syntax: None,
101 impl_def: None, 101 impl_def: None,
102 is_param: false, 102 is_param: false,
103 is_pat_binding_or_const: false, 103 is_pat_binding_or_const: false,
@@ -186,6 +186,11 @@ impl<'a> CompletionContext<'a> {
186 self.is_param = true; 186 self.is_param = true;
187 return; 187 return;
188 } 188 }
189 // FIXME: remove this (V) duplication and make the check more precise
190 if name_ref.syntax().ancestors().find_map(ast::RecordFieldPatList::cast).is_some() {
191 self.record_pat_syntax =
192 self.sema.find_node_at_offset_with_macros(&original_file, offset);
193 }
189 self.classify_name_ref(original_file, name_ref, offset); 194 self.classify_name_ref(original_file, name_ref, offset);
190 } 195 }
191 196
@@ -215,8 +220,9 @@ impl<'a> CompletionContext<'a> {
215 self.is_param = true; 220 self.is_param = true;
216 return; 221 return;
217 } 222 }
223 // FIXME: remove this (^) duplication and make the check more precise
218 if name.syntax().ancestors().find_map(ast::RecordFieldPatList::cast).is_some() { 224 if name.syntax().ancestors().find_map(ast::RecordFieldPatList::cast).is_some() {
219 self.record_lit_pat = 225 self.record_pat_syntax =
220 self.sema.find_node_at_offset_with_macros(&original_file, offset); 226 self.sema.find_node_at_offset_with_macros(&original_file, offset);
221 } 227 }
222 } 228 }