aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorSteffen Lyngbaek <[email protected]>2020-03-18 23:15:32 +0000
committerSteffen Lyngbaek <[email protected]>2020-03-19 21:12:00 +0000
commiteb51abdc646e11b8c23fee83b6f052d3dde87985 (patch)
tree1459c46b52fa33545a1ba5854cea6fdf053255cd /crates
parent6941a7faba49b3927df3106b70b780857d1bab17 (diff)
Fixes to more accurately give complete_scope completions
- Exclude const, static, functions form is_pat_binding_and_path (there might be more?) - Add a check to filter out Record Fields - Fix tests
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_ide/src/completion/complete_pattern.rs28
-rw-r--r--crates/ra_ide/src/completion/complete_scope.rs17
-rw-r--r--crates/ra_ide/src/completion/completion_context.rs8
3 files changed, 38 insertions, 15 deletions
diff --git a/crates/ra_ide/src/completion/complete_pattern.rs b/crates/ra_ide/src/completion/complete_pattern.rs
index cb84bb934..e8e676a4c 100644
--- a/crates/ra_ide/src/completion/complete_pattern.rs
+++ b/crates/ra_ide/src/completion/complete_pattern.rs
@@ -56,6 +56,20 @@ mod tests {
56 assert_debug_snapshot!(completions, @r###" 56 assert_debug_snapshot!(completions, @r###"
57 [ 57 [
58 CompletionItem { 58 CompletionItem {
59 label: "Bar",
60 source_range: [246; 246),
61 delete: [246; 246),
62 insert: "Bar",
63 kind: Struct,
64 },
65 CompletionItem {
66 label: "E",
67 source_range: [246; 246),
68 delete: [246; 246),
69 insert: "E",
70 kind: Enum,
71 },
72 CompletionItem {
59 label: "E", 73 label: "E",
60 source_range: [246; 246), 74 source_range: [246; 246),
61 delete: [246; 246), 75 delete: [246; 246),
@@ -70,6 +84,13 @@ mod tests {
70 kind: EnumVariant, 84 kind: EnumVariant,
71 }, 85 },
72 CompletionItem { 86 CompletionItem {
87 label: "X",
88 source_range: [246; 246),
89 delete: [246; 246),
90 insert: "X",
91 kind: EnumVariant,
92 },
93 CompletionItem {
73 label: "Z", 94 label: "Z",
74 source_range: [246; 246), 95 source_range: [246; 246),
75 delete: [246; 246), 96 delete: [246; 246),
@@ -83,6 +104,13 @@ mod tests {
83 insert: "m", 104 insert: "m",
84 kind: Module, 105 kind: Module,
85 }, 106 },
107 CompletionItem {
108 label: "m",
109 source_range: [246; 246),
110 delete: [246; 246),
111 insert: "m",
112 kind: Module,
113 },
86 ] 114 ]
87 "###); 115 "###);
88 } 116 }
diff --git a/crates/ra_ide/src/completion/complete_scope.rs b/crates/ra_ide/src/completion/complete_scope.rs
index 6b0621081..1cb2ed070 100644
--- a/crates/ra_ide/src/completion/complete_scope.rs
+++ b/crates/ra_ide/src/completion/complete_scope.rs
@@ -1,7 +1,7 @@
1//! Completion of names from the current scope, e.g. locals and imported items. 1//! Completion of names from the current scope, e.g. locals and imported items.
2 2
3use crate::completion::{CompletionContext, Completions}; 3use crate::completion::{CompletionContext, Completions};
4use hir::ScopeDef; 4use hir::{ModuleDef, ScopeDef};
5 5
6pub(super) fn complete_scope(acc: &mut Completions, ctx: &CompletionContext) { 6pub(super) fn complete_scope(acc: &mut Completions, ctx: &CompletionContext) {
7 if !ctx.is_trivial_path && !ctx.is_pat_binding_and_path { 7 if !ctx.is_trivial_path && !ctx.is_pat_binding_and_path {
@@ -9,7 +9,10 @@ pub(super) fn complete_scope(acc: &mut Completions, ctx: &CompletionContext) {
9 } 9 }
10 10
11 ctx.scope().process_all_names(&mut |name, res| match (ctx.is_pat_binding_and_path, &res) { 11 ctx.scope().process_all_names(&mut |name, res| match (ctx.is_pat_binding_and_path, &res) {
12 (true, ScopeDef::Local(..)) => {} 12 (true, ScopeDef::ModuleDef(ModuleDef::Function(..))) => (),
13 (true, ScopeDef::ModuleDef(ModuleDef::Static(..))) => (),
14 (true, ScopeDef::ModuleDef(ModuleDef::Const(..))) => (),
15 (true, ScopeDef::Local(..)) => (),
13 _ => acc.add_resolution(ctx, name.to_string(), &res), 16 _ => acc.add_resolution(ctx, name.to_string(), &res),
14 }); 17 });
15} 18}
@@ -71,16 +74,6 @@ mod tests {
71 insert: "Enum", 74 insert: "Enum",
72 kind: Enum, 75 kind: Enum,
73 }, 76 },
74 CompletionItem {
75 label: "quux(…)",
76 source_range: [231; 233),
77 delete: [231; 233),
78 insert: "quux(${1:x})$0",
79 kind: Function,
80 lookup: "quux",
81 detail: "fn quux(x: Option<Enum>)",
82 trigger_call_info: true,
83 },
84 ] 77 ]
85 "### 78 "###
86 ); 79 );
diff --git a/crates/ra_ide/src/completion/completion_context.rs b/crates/ra_ide/src/completion/completion_context.rs
index f9d4154d8..65bdac182 100644
--- a/crates/ra_ide/src/completion/completion_context.rs
+++ b/crates/ra_ide/src/completion/completion_context.rs
@@ -197,9 +197,11 @@ impl<'a> CompletionContext<'a> {
197 self.is_pat_binding = true; 197 self.is_pat_binding = true;
198 } 198 }
199 199
200 let bind_pat_string = bind_pat.syntax().to_string(); 200 if parent.and_then(ast::RecordFieldPatList::cast).is_none() {
201 if !bind_pat_string.contains("ref ") && !bind_pat_string.contains(" @ ") { 201 let bind_pat_string = bind_pat.syntax().to_string();
202 self.is_pat_binding_and_path = true; 202 if !bind_pat_string.contains("ref ") && !bind_pat_string.contains(" @ ") {
203 self.is_pat_binding_and_path = true;
204 }
203 } 205 }
204 } 206 }
205 if is_node::<ast::Param>(name.syntax()) { 207 if is_node::<ast::Param>(name.syntax()) {