Skip to content

Commit eb51abd

Browse files
committed
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
1 parent 6941a7f commit eb51abd

File tree

3 files changed

+38
-15
lines changed

3 files changed

+38
-15
lines changed

crates/ra_ide/src/completion/complete_pattern.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,20 @@ mod tests {
5555
);
5656
assert_debug_snapshot!(completions, @r###"
5757
[
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+
},
5872
CompletionItem {
5973
label: "E",
6074
source_range: [246; 246),
@@ -69,6 +83,13 @@ mod tests {
6983
insert: "X",
7084
kind: EnumVariant,
7185
},
86+
CompletionItem {
87+
label: "X",
88+
source_range: [246; 246),
89+
delete: [246; 246),
90+
insert: "X",
91+
kind: EnumVariant,
92+
},
7293
CompletionItem {
7394
label: "Z",
7495
source_range: [246; 246),
@@ -83,6 +104,13 @@ mod tests {
83104
insert: "m",
84105
kind: Module,
85106
},
107+
CompletionItem {
108+
label: "m",
109+
source_range: [246; 246),
110+
delete: [246; 246),
111+
insert: "m",
112+
kind: Module,
113+
},
86114
]
87115
"###);
88116
}

crates/ra_ide/src/completion/complete_scope.rs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
//! Completion of names from the current scope, e.g. locals and imported items.
22
33
use crate::completion::{CompletionContext, Completions};
4-
use hir::ScopeDef;
4+
use hir::{ModuleDef, ScopeDef};
55

66
pub(super) fn complete_scope(acc: &mut Completions, ctx: &CompletionContext) {
77
if !ctx.is_trivial_path && !ctx.is_pat_binding_and_path {
88
return;
99
}
1010

1111
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(..)) => (),
1316
_ => acc.add_resolution(ctx, name.to_string(), &res),
1417
});
1518
}
@@ -71,16 +74,6 @@ mod tests {
7174
insert: "Enum",
7275
kind: Enum,
7376
},
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-
},
8477
]
8578
"###
8679
);

crates/ra_ide/src/completion/completion_context.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,11 @@ impl<'a> CompletionContext<'a> {
197197
self.is_pat_binding = true;
198198
}
199199

200-
let bind_pat_string = bind_pat.syntax().to_string();
201-
if !bind_pat_string.contains("ref ") && !bind_pat_string.contains(" @ ") {
202-
self.is_pat_binding_and_path = true;
200+
if parent.and_then(ast::RecordFieldPatList::cast).is_none() {
201+
let bind_pat_string = bind_pat.syntax().to_string();
202+
if !bind_pat_string.contains("ref ") && !bind_pat_string.contains(" @ ") {
203+
self.is_pat_binding_and_path = true;
204+
}
203205
}
204206
}
205207
if is_node::<ast::Param>(name.syntax()) {

0 commit comments

Comments
 (0)