Remove const

- Add test for @ matching
- Address comments
This commit is contained in:
Steffen Lyngbaek 2020-03-19 00:11:25 -07:00
parent eb51abdc64
commit ec24c09006
3 changed files with 48 additions and 6 deletions

View File

@ -97,6 +97,13 @@ mod tests {
insert: "Z",
kind: Const,
},
CompletionItem {
label: "Z",
source_range: [246; 246),
delete: [246; 246),
insert: "Z",
kind: Const,
},
CompletionItem {
label: "m",
source_range: [246; 246),
@ -138,6 +145,21 @@ mod tests {
insert: "E",
kind: Enum,
},
CompletionItem {
label: "E",
source_range: [151; 151),
delete: [151; 151),
insert: "E",
kind: Enum,
},
CompletionItem {
label: "m!",
source_range: [151; 151),
delete: [151; 151),
insert: "m!($0)",
kind: Macro,
detail: "macro_rules! m",
},
]
"###);
}

View File

@ -11,7 +11,6 @@ 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) {
(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),
});
@ -27,6 +26,27 @@ mod tests {
do_completion(ra_fixture, CompletionKind::Reference)
}
#[test]
fn bind_pat_and_path_ignore_at() {
assert_debug_snapshot!(
do_reference_completion(
r"
enum Enum {
A,
B,
}
fn quux(x: Option<Enum>) {
match x {
None => (),
Some(en<|> @ Enum::A) => (),
}
}
"
),
@r###"[]"###
);
}
#[test]
fn bind_pat_and_path_ignore_ref() {
assert_debug_snapshot!(

View File

@ -197,11 +197,11 @@ impl<'a> CompletionContext<'a> {
self.is_pat_binding = true;
}
if parent.and_then(ast::RecordFieldPatList::cast).is_none() {
let bind_pat_string = bind_pat.syntax().to_string();
if !bind_pat_string.contains("ref ") && !bind_pat_string.contains(" @ ") {
self.is_pat_binding_and_path = true;
}
if parent.and_then(ast::RecordFieldPatList::cast).is_none()
&& bind_pat.pat().is_none()
&& !bind_pat.is_ref()
{
self.is_pat_binding_and_path = true;
}
}
if is_node::<ast::Param>(name.syntax()) {