Skip to content

Commit 1a26af1

Browse files
committed
Add tests checking no value completion in type pos
1 parent 1d74ef1 commit 1a26af1

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

crates/ide_completion/src/completions.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,9 @@ impl Completions {
204204
variant: hir::Variant,
205205
local_name: Option<hir::Name>,
206206
) {
207+
if ctx.expects_type() {
208+
return;
209+
}
207210
let item = render_variant(RenderContext::new(ctx), None, local_name, variant, None);
208211
self.add(item);
209212
}

crates/ide_completion/src/completions/qualified_path.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,36 @@ mod tests {
198198
check(r#"use self::foo$0;"#, expect![[""]]);
199199
}
200200

201+
#[test]
202+
fn dont_complete_values_in_type_pos() {
203+
check(
204+
r#"
205+
const FOO: () = ();
206+
static BAR: () = ();
207+
struct Baz;
208+
fn foo() {
209+
let _: self::$0;
210+
}
211+
"#,
212+
expect![[r#"
213+
st Baz
214+
"#]],
215+
);
216+
}
217+
218+
#[test]
219+
fn dont_complete_enum_variants_in_type_pos() {
220+
check(
221+
r#"
222+
enum Foo { Bar }
223+
fn foo() {
224+
let _: Foo::$0;
225+
}
226+
"#,
227+
expect![[r#""#]],
228+
);
229+
}
230+
201231
#[test]
202232
fn dont_complete_current_use_in_braces_with_glob() {
203233
check(

crates/ide_completion/src/completions/unqualified_path.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,28 @@ mod tests {
6868
expect.assert_eq(&actual)
6969
}
7070

71+
#[test]
72+
fn dont_complete_values_in_type_pos() {
73+
check(
74+
r#"
75+
const FOO: () = ();
76+
static BAR: () = ();
77+
enum Foo {
78+
Bar
79+
}
80+
struct Baz;
81+
fn foo() {
82+
let local = ();
83+
let _: $0;
84+
}
85+
"#,
86+
expect![[r#"
87+
en Foo
88+
st Baz
89+
"#]],
90+
);
91+
}
92+
7193
#[test]
7294
fn only_completes_modules_in_import() {
7395
cov_mark::check!(only_completes_modules_in_import);

0 commit comments

Comments
 (0)