use hir::ScopeDef;
use syntax::AstNode;
-use test_utils::mark;
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()
- || ctx.record_pat_syntax.is_some()
- || ctx.attribute_under_caret.is_some()
- || ctx.mod_declaration_under_caret.is_some()
- {
+ if ctx.is_path_disallowed() {
return;
}
- if let Some(ty) = &ctx.expected_type {
- super::complete_enum_variants(acc, ctx, ty, |acc, ctx, variant, path| {
+ if let Some(hir::Adt::Enum(e)) =
+ ctx.expected_type.as_ref().and_then(|ty| ty.strip_references().as_adt())
+ {
+ super::complete_enum_variants(acc, ctx, e, |acc, ctx, variant, path| {
acc.add_qualified_enum_variant(ctx, variant, path)
});
}
- if ctx.is_pat_binding_or_const {
- return;
- }
-
ctx.scope.process_all_names(&mut |name, res| {
if let ScopeDef::GenericParam(hir::GenericParam::LifetimeParam(_)) = res {
- mark::hit!(skip_lifetime_completion);
+ cov_mark::hit!(skip_lifetime_completion);
return;
}
if ctx.use_item_syntax.is_some() {
if let (ScopeDef::Unknown, Some(name_ref)) = (&res, &ctx.name_ref_syntax) {
if name_ref.syntax().text() == name.to_string().as_str() {
- mark::hit!(self_fulfilling_completion);
+ cov_mark::hit!(self_fulfilling_completion);
return;
}
}
#[cfg(test)]
mod tests {
use expect_test::{expect, Expect};
- use test_utils::mark;
use crate::{
test_utils::{check_edit, completion_list_with_config, TEST_CONFIG},
#[test]
fn self_fulfilling_completion() {
- mark::check!(self_fulfilling_completion);
+ cov_mark::check!(self_fulfilling_completion);
check(
r#"
use foo$0
}
}
"#,
- expect![[""]],
+ expect![[r#""#]],
);
}
}
}
"#,
- expect![[""]],
+ expect![[r#""#]],
);
}
expect![[r#"
lc y i32
lc x i32
- fn quux(…) -> ()
+ fn quux(…) fn(i32)
"#]],
);
}
expect![[r#"
lc b i32
lc a
- fn quux() -> ()
+ fn quux() fn()
"#]],
);
}
"#,
expect![[r#"
lc x
- fn quux() -> ()
+ fn quux() fn()
"#]],
);
}
#[test]
fn completes_if_prefix_is_keyword() {
- mark::check!(completes_if_prefix_is_keyword);
+ cov_mark::check!(completes_if_prefix_is_keyword);
check_edit(
"wherewolf",
r#"
r#"fn quux<T>() { $0 }"#,
expect![[r#"
tp T
- fn quux() -> ()
+ fn quux() fn()
"#]],
);
check(
r#"fn quux<const C: usize>() { $0 }"#,
expect![[r#"
cp C
- fn quux() -> ()
+ fn quux() fn()
"#]],
);
}
#[test]
fn does_not_complete_lifetimes() {
- mark::check!(skip_lifetime_completion);
+ cov_mark::check!(skip_lifetime_completion);
check(
r#"fn quux<'a>() { $0 }"#,
expect![[r#"
- fn quux() -> ()
+ fn quux() fn()
"#]],
);
}
"#,
expect![[r#"
st S
- fn quux() -> ()
+ fn quux() fn()
en E
"#]],
);
}
"#,
expect![[r#"
- fn quux() -> ()
+ fn quux() fn()
st Bar
"#]],
);
"#,
expect![[r#"
st Foo
- fn x() -> ()
+ fn x() fn()
"#]],
);
}
expect![[r#"
lc bar i32
lc bar i32
- fn foo() -> ()
+ fn foo() fn()
"#]],
);
}
mod prelude { struct Option; }
"#,
expect![[r#"
- fn foo() -> ()
+ fn foo() fn()
md std
st Option
"#]],
}
"#,
expect![[r##"
- fn f() -> ()
+ fn f() fn()
ma concat!(…) #[macro_export] macro_rules! concat
md std
"##]],
mod prelude { struct String; }
"#,
expect![[r#"
- fn foo() -> ()
+ fn foo() fn()
md std
md core
st String
expect![[r##"
md m1
ma baz!(…) #[macro_export] macro_rules! baz
- fn main() -> ()
+ fn main() fn()
md m2
ma bar!(…) macro_rules! bar
ma foo!(…) macro_rules! foo
fn foo() { $0 }
"#,
expect![[r#"
- fn foo() -> ()
+ fn foo() fn()
ma foo!(…) macro_rules! foo
"#]],
);
fn main() { let x: $0 }
"#,
expect![[r#"
- fn main() -> ()
+ fn main() fn()
ma foo!(…) macro_rules! foo
"#]],
);
fn main() { $0 }
"#,
expect![[r#"
- fn main() -> ()
+ fn main() fn()
ma foo!(…) macro_rules! foo
"#]],
);
}
"#,
expect![[r#"
- fn frobnicate() -> ()
- fn main() -> ()
+ fn frobnicate() fn()
+ fn main() fn()
"#]],
);
}
expect![[r#"
lc y i32
lc x i32
- fn quux(…) -> ()
+ fn quux(…) fn(i32)
ma m!(…) macro_rules! m
"#]],
);
expect![[r#"
lc y i32
lc x i32
- fn quux(…) -> ()
+ fn quux(…) fn(i32)
ma m!(…) macro_rules! m
"#]],
);
expect![[r#"
lc y i32
lc x i32
- fn quux(…) -> ()
+ fn quux(…) fn(i32)
ma m!(…) macro_rules! m
"#]],
);
fn main() { $0 }
"#,
expect![[r#"
- fn main() -> ()
+ fn main() fn()
?? Quux
"#]],
);
}
- #[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(
ev Foo::Baz ()
ev Foo::Quux ()
en Foo
- fn main() -> ()
+ fn main() fn()
"#]],
)
}
expect![[r#"
ev m::E::V ()
md m
- fn f() -> E
- "#]],
- )
- }
-
- #[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
+ fn f() fn() -> E
"#]],
)
}