return;
}
- if let Some(ty) = &ctx.expected_type {
- super::complete_enum_variants(acc, ctx, ty, |acc, ctx, variant, path| {
- acc.add_qualified_variant_pat(ctx, variant, path)
- });
+ if !ctx.is_irrefutable_pat_binding {
+ if let Some(ty) = ctx.expected_type.as_ref() {
+ super::complete_enum_variants(acc, ctx, ty, |acc, ctx, variant, path| {
+ acc.add_qualified_variant_pat(ctx, variant, path.clone());
+ acc.add_qualified_enum_variant(ctx, variant, path);
+ });
+ }
}
// FIXME: ideally, we should look at the type we are matching against and
struct Bar { f: u32 }
fn foo() {
- match E::X { $0 }
+ match E::X { a$0 }
}
"#,
expect![[r#"
enum E { X }
fn foo() {
- m!(match E::X { $0 })
+ m!(match E::X { a$0 })
}
"#,
expect![[r#"
+ ev E::X ()
en E
ma m!(…) macro_rules! m
"#]],
struct Bar { f: u32 }
fn foo() {
- let $0
+ let a$0
}
"#,
expect![[r#"
static FOO: E = E::X;
struct Bar { f: u32 }
-fn foo($0) {
+fn foo(a$0) {
}
"#,
expect![[r#"
struct Bar { f: u32 }
fn foo() {
- let $0
+ let a$0
}
"#,
expect![[r#"
struct Foo { bar: String, baz: String }
struct Bar(String, String);
struct Baz;
-fn outer($0) {}
+fn outer(a$0) {}
"#,
expect![[r#"
bn Foo Foo { bar$1, baz$2 }: Foo$0
struct Bar(String, String);
struct Baz;
fn outer() {
- let $0
+ let a$0
}
"#,
expect![[r#"
struct Baz;
fn outer() {
match () {
- $0
+ a$0
}
}
"#,
fn outer() {
match () {
- $0
+ a$0
}
}
"#,
struct Foo(i32);
fn main() {
match Foo(92) {
- $0(92) => (),
+ a$0(92) => (),
}
}
"#,
impl Foo {
fn foo() {
match () {
- $0
+ a$0
}
}
}
"#]],
)
}
+
+ #[test]
+ fn completes_enum_variant_matcharm() {
+ check(
+ r#"
+enum Foo { Bar, Baz, Quux }
+
+fn main() {
+ let foo = Foo::Quux;
+ match foo { Qu$0 }
+}
+"#,
+ expect![[r#"
+ ev Foo::Bar ()
+ ev Foo::Baz ()
+ ev Foo::Quux ()
+ en Foo
+ "#]],
+ )
+ }
+
+ #[test]
+ fn completes_enum_variant_matcharm_ref() {
+ check(
+ r#"
+enum Foo { Bar, Baz, Quux }
+
+fn main() {
+ let foo = Foo::Quux;
+ match &foo { Qu$0 }
+}
+"#,
+ expect![[r#"
+ ev Foo::Bar ()
+ ev Foo::Baz ()
+ ev Foo::Quux ()
+ en Foo
+ "#]],
+ )
+ }
+
+ #[test]
+ fn completes_enum_variant_iflet() {
+ check(
+ r#"
+enum Foo { Bar, Baz, Quux }
+
+fn main() {
+ let foo = Foo::Quux;
+ if let Qu$0 = foo { }
+}
+"#,
+ expect![[r#"
+ ev Foo::Bar ()
+ ev Foo::Baz ()
+ ev Foo::Quux ()
+ en Foo
+ "#]],
+ )
+ }
+
+ #[test]
+ fn completes_enum_variant_impl() {
+ check(
+ r#"
+enum Foo { Bar, Baz, Quux }
+impl Foo {
+ fn foo() { match Foo::Bar { Q$0 } }
+}
+"#,
+ expect![[r#"
+ ev Self::Bar ()
+ ev Self::Baz ()
+ ev Self::Quux ()
+ ev Foo::Bar ()
+ ev Foo::Baz ()
+ ev Foo::Quux ()
+ sp Self
+ en Foo
+ "#]],
+ )
+ }
}
use crate::{CompletionContext, Completions};
pub(crate) fn complete_unqualified_path(acc: &mut Completions, ctx: &CompletionContext) {
- if !(ctx.is_trivial_path || ctx.is_pat_binding_or_const) {
+ if !ctx.is_trivial_path {
return;
}
if ctx.record_lit_syntax.is_some()
});
}
- if ctx.is_pat_binding_or_const {
- return;
- }
-
ctx.scope.process_all_names(&mut |name, res| {
if let ScopeDef::GenericParam(hir::GenericParam::LifetimeParam(_)) = res {
cov_mark::hit!(skip_lifetime_completion);
);
}
- #[test]
- fn completes_enum_variant_matcharm() {
- check(
- r#"
-enum Foo { Bar, Baz, Quux }
-
-fn main() {
- let foo = Foo::Quux;
- match foo { Qu$0 }
-}
-"#,
- expect![[r#"
- ev Foo::Bar ()
- ev Foo::Baz ()
- ev Foo::Quux ()
- en Foo
- "#]],
- )
- }
-
- #[test]
- fn completes_enum_variant_matcharm_ref() {
- check(
- r#"
-enum Foo { Bar, Baz, Quux }
-
-fn main() {
- let foo = Foo::Quux;
- match &foo { Qu$0 }
-}
-"#,
- expect![[r#"
- ev Foo::Bar ()
- ev Foo::Baz ()
- ev Foo::Quux ()
- en Foo
- "#]],
- )
- }
-
- #[test]
- fn completes_enum_variant_iflet() {
- check(
- r#"
-enum Foo { Bar, Baz, Quux }
-
-fn main() {
- let foo = Foo::Quux;
- if let Qu$0 = foo { }
-}
-"#,
- expect![[r#"
- ev Foo::Bar ()
- ev Foo::Baz ()
- ev Foo::Quux ()
- en Foo
- "#]],
- )
- }
-
#[test]
fn completes_enum_variant_basic_expr() {
check(
)
}
- #[test]
- fn completes_enum_variant_impl() {
- check(
- r#"
-enum Foo { Bar, Baz, Quux }
-impl Foo {
- fn foo() { match Foo::Bar { Q$0 } }
-}
-"#,
- expect![[r#"
- ev Self::Bar ()
- ev Self::Baz ()
- ev Self::Quux ()
- ev Foo::Bar ()
- ev Foo::Baz ()
- ev Foo::Quux ()
- sp Self
- en Foo
- "#]],
- )
- }
-
#[test]
fn dont_complete_attr() {
check(
use crate::{item::CompletionKind, render::RenderContext, CompletionItem, CompletionItemKind};
-fn visible_fields(
- ctx: &RenderContext<'_>,
- fields: &[hir::Field],
- item: impl HasAttrs,
-) -> Option<(Vec<hir::Field>, bool)> {
- let module = ctx.completion.scope.module()?;
- let n_fields = fields.len();
- let fields = fields
- .into_iter()
- .filter(|field| field.is_visible_from(ctx.db(), module))
- .copied()
- .collect::<Vec<_>>();
-
- let fields_omitted =
- n_fields - fields.len() > 0 || item.attrs(ctx.db()).by_key("non_exhaustive").exists();
- Some((fields, fields_omitted))
-}
-
pub(crate) fn render_struct_pat(
ctx: RenderContext<'_>,
strukt: hir::Struct,
name = name
)
}
+
+fn visible_fields(
+ ctx: &RenderContext<'_>,
+ fields: &[hir::Field],
+ item: impl HasAttrs,
+) -> Option<(Vec<hir::Field>, bool)> {
+ let module = ctx.completion.scope.module()?;
+ let n_fields = fields.len();
+ let fields = fields
+ .into_iter()
+ .filter(|field| field.is_visible_from(ctx.db(), module))
+ .copied()
+ .collect::<Vec<_>>();
+
+ let fields_omitted =
+ n_fields - fields.len() > 0 || item.attrs(ctx.db()).by_key("non_exhaustive").exists();
+ Some((fields, fields_omitted))
+}