Skip to content

Commit ec24c09

Browse files
committed
Remove const
- Add test for @ matching - Address comments
1 parent eb51abd commit ec24c09

File tree

3 files changed

+48
-6
lines changed

3 files changed

+48
-6
lines changed

crates/ra_ide/src/completion/complete_pattern.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,13 @@ mod tests {
9797
insert: "Z",
9898
kind: Const,
9999
},
100+
CompletionItem {
101+
label: "Z",
102+
source_range: [246; 246),
103+
delete: [246; 246),
104+
insert: "Z",
105+
kind: Const,
106+
},
100107
CompletionItem {
101108
label: "m",
102109
source_range: [246; 246),
@@ -138,6 +145,21 @@ mod tests {
138145
insert: "E",
139146
kind: Enum,
140147
},
148+
CompletionItem {
149+
label: "E",
150+
source_range: [151; 151),
151+
delete: [151; 151),
152+
insert: "E",
153+
kind: Enum,
154+
},
155+
CompletionItem {
156+
label: "m!",
157+
source_range: [151; 151),
158+
delete: [151; 151),
159+
insert: "m!($0)",
160+
kind: Macro,
161+
detail: "macro_rules! m",
162+
},
141163
]
142164
"###);
143165
}

crates/ra_ide/src/completion/complete_scope.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ pub(super) fn complete_scope(acc: &mut Completions, ctx: &CompletionContext) {
1111
ctx.scope().process_all_names(&mut |name, res| match (ctx.is_pat_binding_and_path, &res) {
1212
(true, ScopeDef::ModuleDef(ModuleDef::Function(..))) => (),
1313
(true, ScopeDef::ModuleDef(ModuleDef::Static(..))) => (),
14-
(true, ScopeDef::ModuleDef(ModuleDef::Const(..))) => (),
1514
(true, ScopeDef::Local(..)) => (),
1615
_ => acc.add_resolution(ctx, name.to_string(), &res),
1716
});
@@ -27,6 +26,27 @@ mod tests {
2726
do_completion(ra_fixture, CompletionKind::Reference)
2827
}
2928

29+
#[test]
30+
fn bind_pat_and_path_ignore_at() {
31+
assert_debug_snapshot!(
32+
do_reference_completion(
33+
r"
34+
enum Enum {
35+
A,
36+
B,
37+
}
38+
fn quux(x: Option<Enum>) {
39+
match x {
40+
None => (),
41+
Some(en<|> @ Enum::A) => (),
42+
}
43+
}
44+
"
45+
),
46+
@r###"[]"###
47+
);
48+
}
49+
3050
#[test]
3151
fn bind_pat_and_path_ignore_ref() {
3252
assert_debug_snapshot!(

crates/ra_ide/src/completion/completion_context.rs

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

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-
}
200+
if parent.and_then(ast::RecordFieldPatList::cast).is_none()
201+
&& bind_pat.pat().is_none()
202+
&& !bind_pat.is_ref()
203+
{
204+
self.is_pat_binding_and_path = true;
205205
}
206206
}
207207
if is_node::<ast::Param>(name.syntax()) {

0 commit comments

Comments
 (0)