aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api/src/completion/completion_context.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide_api/src/completion/completion_context.rs')
-rw-r--r--crates/ra_ide_api/src/completion/completion_context.rs14
1 files changed, 14 insertions, 0 deletions
diff --git a/crates/ra_ide_api/src/completion/completion_context.rs b/crates/ra_ide_api/src/completion/completion_context.rs
index d351be054..724d0dfbf 100644
--- a/crates/ra_ide_api/src/completion/completion_context.rs
+++ b/crates/ra_ide_api/src/completion/completion_context.rs
@@ -23,6 +23,9 @@ pub(crate) struct CompletionContext<'a> {
23 pub(super) use_item_syntax: Option<&'a ast::UseItem>, 23 pub(super) use_item_syntax: Option<&'a ast::UseItem>,
24 pub(super) struct_lit_syntax: Option<&'a ast::StructLit>, 24 pub(super) struct_lit_syntax: Option<&'a ast::StructLit>,
25 pub(super) is_param: bool, 25 pub(super) is_param: bool,
26 /// If a name-binding or reference to a const in a pattern.
27 /// Irrefutable patterns (like let) are excluded.
28 pub(super) is_pat_binding: bool,
26 /// A single-indent path, like `foo`. `::foo` should not be considered a trivial path. 29 /// A single-indent path, like `foo`. `::foo` should not be considered a trivial path.
27 pub(super) is_trivial_path: bool, 30 pub(super) is_trivial_path: bool,
28 /// If not a trivial, path, the prefix (qualifier). 31 /// If not a trivial, path, the prefix (qualifier).
@@ -58,6 +61,7 @@ impl<'a> CompletionContext<'a> {
58 use_item_syntax: None, 61 use_item_syntax: None,
59 struct_lit_syntax: None, 62 struct_lit_syntax: None,
60 is_param: false, 63 is_param: false,
64 is_pat_binding: false,
61 is_trivial_path: false, 65 is_trivial_path: false,
62 path_prefix: None, 66 path_prefix: None,
63 after_if: false, 67 after_if: false,
@@ -102,12 +106,22 @@ impl<'a> CompletionContext<'a> {
102 // Otherwise, see if this is a declaration. We can use heuristics to 106 // Otherwise, see if this is a declaration. We can use heuristics to
103 // suggest declaration names, see `CompletionKind::Magic`. 107 // suggest declaration names, see `CompletionKind::Magic`.
104 if let Some(name) = find_node_at_offset::<ast::Name>(file.syntax(), offset) { 108 if let Some(name) = find_node_at_offset::<ast::Name>(file.syntax(), offset) {
109 if is_node::<ast::BindPat>(name.syntax()) {
110 let bind_pat = name.syntax().ancestors().find_map(ast::BindPat::cast).unwrap();
111 let parent = bind_pat.syntax().parent();
112 if parent.and_then(ast::MatchArm::cast).is_some()
113 || parent.and_then(ast::Condition::cast).is_some()
114 {
115 self.is_pat_binding = true;
116 }
117 }
105 if is_node::<ast::Param>(name.syntax()) { 118 if is_node::<ast::Param>(name.syntax()) {
106 self.is_param = true; 119 self.is_param = true;
107 return; 120 return;
108 } 121 }
109 } 122 }
110 } 123 }
124
111 fn classify_name_ref(&mut self, original_file: &'a SourceFile, name_ref: &ast::NameRef) { 125 fn classify_name_ref(&mut self, original_file: &'a SourceFile, name_ref: &ast::NameRef) {
112 let name_range = name_ref.syntax().range(); 126 let name_range = name_ref.syntax().range();
113 if name_ref.syntax().parent().and_then(ast::NamedField::cast).is_some() { 127 if name_ref.syntax().parent().and_then(ast::NamedField::cast).is_some() {