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
This commit is contained in:
parent
6941a7faba
commit
eb51abdc64
3 changed files with 38 additions and 15 deletions
|
@ -55,6 +55,20 @@ mod tests {
|
||||||
);
|
);
|
||||||
assert_debug_snapshot!(completions, @r###"
|
assert_debug_snapshot!(completions, @r###"
|
||||||
[
|
[
|
||||||
|
CompletionItem {
|
||||||
|
label: "Bar",
|
||||||
|
source_range: [246; 246),
|
||||||
|
delete: [246; 246),
|
||||||
|
insert: "Bar",
|
||||||
|
kind: Struct,
|
||||||
|
},
|
||||||
|
CompletionItem {
|
||||||
|
label: "E",
|
||||||
|
source_range: [246; 246),
|
||||||
|
delete: [246; 246),
|
||||||
|
insert: "E",
|
||||||
|
kind: Enum,
|
||||||
|
},
|
||||||
CompletionItem {
|
CompletionItem {
|
||||||
label: "E",
|
label: "E",
|
||||||
source_range: [246; 246),
|
source_range: [246; 246),
|
||||||
|
@ -69,6 +83,13 @@ mod tests {
|
||||||
insert: "X",
|
insert: "X",
|
||||||
kind: EnumVariant,
|
kind: EnumVariant,
|
||||||
},
|
},
|
||||||
|
CompletionItem {
|
||||||
|
label: "X",
|
||||||
|
source_range: [246; 246),
|
||||||
|
delete: [246; 246),
|
||||||
|
insert: "X",
|
||||||
|
kind: EnumVariant,
|
||||||
|
},
|
||||||
CompletionItem {
|
CompletionItem {
|
||||||
label: "Z",
|
label: "Z",
|
||||||
source_range: [246; 246),
|
source_range: [246; 246),
|
||||||
|
@ -83,6 +104,13 @@ mod tests {
|
||||||
insert: "m",
|
insert: "m",
|
||||||
kind: Module,
|
kind: Module,
|
||||||
},
|
},
|
||||||
|
CompletionItem {
|
||||||
|
label: "m",
|
||||||
|
source_range: [246; 246),
|
||||||
|
delete: [246; 246),
|
||||||
|
insert: "m",
|
||||||
|
kind: Module,
|
||||||
|
},
|
||||||
]
|
]
|
||||||
"###);
|
"###);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
//! Completion of names from the current scope, e.g. locals and imported items.
|
//! Completion of names from the current scope, e.g. locals and imported items.
|
||||||
|
|
||||||
use crate::completion::{CompletionContext, Completions};
|
use crate::completion::{CompletionContext, Completions};
|
||||||
use hir::ScopeDef;
|
use hir::{ModuleDef, ScopeDef};
|
||||||
|
|
||||||
pub(super) fn complete_scope(acc: &mut Completions, ctx: &CompletionContext) {
|
pub(super) fn complete_scope(acc: &mut Completions, ctx: &CompletionContext) {
|
||||||
if !ctx.is_trivial_path && !ctx.is_pat_binding_and_path {
|
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) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.scope().process_all_names(&mut |name, res| match (ctx.is_pat_binding_and_path, &res) {
|
ctx.scope().process_all_names(&mut |name, res| match (ctx.is_pat_binding_and_path, &res) {
|
||||||
(true, ScopeDef::Local(..)) => {}
|
(true, ScopeDef::ModuleDef(ModuleDef::Function(..))) => (),
|
||||||
|
(true, ScopeDef::ModuleDef(ModuleDef::Static(..))) => (),
|
||||||
|
(true, ScopeDef::ModuleDef(ModuleDef::Const(..))) => (),
|
||||||
|
(true, ScopeDef::Local(..)) => (),
|
||||||
_ => acc.add_resolution(ctx, name.to_string(), &res),
|
_ => acc.add_resolution(ctx, name.to_string(), &res),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -71,16 +74,6 @@ mod tests {
|
||||||
insert: "Enum",
|
insert: "Enum",
|
||||||
kind: Enum,
|
kind: Enum,
|
||||||
},
|
},
|
||||||
CompletionItem {
|
|
||||||
label: "quux(…)",
|
|
||||||
source_range: [231; 233),
|
|
||||||
delete: [231; 233),
|
|
||||||
insert: "quux(${1:x})$0",
|
|
||||||
kind: Function,
|
|
||||||
lookup: "quux",
|
|
||||||
detail: "fn quux(x: Option<Enum>)",
|
|
||||||
trigger_call_info: true,
|
|
||||||
},
|
|
||||||
]
|
]
|
||||||
"###
|
"###
|
||||||
);
|
);
|
||||||
|
|
|
@ -197,9 +197,11 @@ impl<'a> CompletionContext<'a> {
|
||||||
self.is_pat_binding = true;
|
self.is_pat_binding = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
let bind_pat_string = bind_pat.syntax().to_string();
|
if parent.and_then(ast::RecordFieldPatList::cast).is_none() {
|
||||||
if !bind_pat_string.contains("ref ") && !bind_pat_string.contains(" @ ") {
|
let bind_pat_string = bind_pat.syntax().to_string();
|
||||||
self.is_pat_binding_and_path = true;
|
if !bind_pat_string.contains("ref ") && !bind_pat_string.contains(" @ ") {
|
||||||
|
self.is_pat_binding_and_path = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if is_node::<ast::Param>(name.syntax()) {
|
if is_node::<ast::Param>(name.syntax()) {
|
||||||
|
|
Loading…
Reference in a new issue