mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-13 13:48:50 +00:00
fix: flyimport triggers on enum variant declarations
This commit is contained in:
parent
766b52b598
commit
5666046ec9
4 changed files with 38 additions and 0 deletions
|
@ -113,6 +113,7 @@ pub(crate) fn import_on_the_fly(acc: &mut Completions, ctx: &CompletionContext)
|
|||
|| ctx.is_path_disallowed()
|
||||
|| ctx.expects_item()
|
||||
|| ctx.expects_assoc_item()
|
||||
|| ctx.expects_variant()
|
||||
{
|
||||
return None;
|
||||
}
|
||||
|
|
|
@ -171,6 +171,10 @@ impl<'a> CompletionContext<'a> {
|
|||
matches!(self.completion_location, Some(ImmediateLocation::Trait | ImmediateLocation::Impl))
|
||||
}
|
||||
|
||||
pub(crate) fn expects_variant(&self) -> bool {
|
||||
matches!(self.completion_location, Some(ImmediateLocation::Variant))
|
||||
}
|
||||
|
||||
pub(crate) fn expects_non_trait_assoc_item(&self) -> bool {
|
||||
matches!(self.completion_location, Some(ImmediateLocation::Impl))
|
||||
}
|
||||
|
|
|
@ -45,6 +45,7 @@ pub(crate) enum ImmediateLocation {
|
|||
StmtList,
|
||||
ItemList,
|
||||
TypeBound,
|
||||
Variant,
|
||||
/// Fake file ast node
|
||||
Attribute(ast::Attr),
|
||||
/// Fake file ast node
|
||||
|
@ -213,6 +214,7 @@ pub(crate) fn determine_location(
|
|||
ast::SourceFile(_it) => ImmediateLocation::ItemList,
|
||||
ast::ItemList(_it) => ImmediateLocation::ItemList,
|
||||
ast::RefExpr(_it) => ImmediateLocation::RefExpr,
|
||||
ast::Variant(_it) => ImmediateLocation::Variant,
|
||||
ast::RecordField(it) => if it.ty().map_or(false, |it| it.syntax().text_range().contains(offset)) {
|
||||
return None;
|
||||
} else {
|
||||
|
|
|
@ -1012,3 +1012,34 @@ use self as Str$0;
|
|||
expect![[r#""#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn flyimport_enum_variant() {
|
||||
check(
|
||||
r#"
|
||||
mod foo {
|
||||
pub struct Barbara;
|
||||
}
|
||||
|
||||
enum Foo {
|
||||
Barba$0()
|
||||
}
|
||||
}"#,
|
||||
expect![[r#""#]],
|
||||
);
|
||||
|
||||
check(
|
||||
r#"
|
||||
mod foo {
|
||||
pub struct Barbara;
|
||||
}
|
||||
|
||||
enum Foo {
|
||||
Barba(Barba$0)
|
||||
}
|
||||
}"#,
|
||||
expect![[r#"
|
||||
st Barbara (use foo::Barbara)
|
||||
"#]],
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue