mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-27 20:35:09 +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.is_path_disallowed()
|
||||||
|| ctx.expects_item()
|
|| ctx.expects_item()
|
||||||
|| ctx.expects_assoc_item()
|
|| ctx.expects_assoc_item()
|
||||||
|
|| ctx.expects_variant()
|
||||||
{
|
{
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
|
@ -171,6 +171,10 @@ impl<'a> CompletionContext<'a> {
|
||||||
matches!(self.completion_location, Some(ImmediateLocation::Trait | ImmediateLocation::Impl))
|
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 {
|
pub(crate) fn expects_non_trait_assoc_item(&self) -> bool {
|
||||||
matches!(self.completion_location, Some(ImmediateLocation::Impl))
|
matches!(self.completion_location, Some(ImmediateLocation::Impl))
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,6 +45,7 @@ pub(crate) enum ImmediateLocation {
|
||||||
StmtList,
|
StmtList,
|
||||||
ItemList,
|
ItemList,
|
||||||
TypeBound,
|
TypeBound,
|
||||||
|
Variant,
|
||||||
/// Fake file ast node
|
/// Fake file ast node
|
||||||
Attribute(ast::Attr),
|
Attribute(ast::Attr),
|
||||||
/// Fake file ast node
|
/// Fake file ast node
|
||||||
|
@ -213,6 +214,7 @@ pub(crate) fn determine_location(
|
||||||
ast::SourceFile(_it) => ImmediateLocation::ItemList,
|
ast::SourceFile(_it) => ImmediateLocation::ItemList,
|
||||||
ast::ItemList(_it) => ImmediateLocation::ItemList,
|
ast::ItemList(_it) => ImmediateLocation::ItemList,
|
||||||
ast::RefExpr(_it) => ImmediateLocation::RefExpr,
|
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)) {
|
ast::RecordField(it) => if it.ty().map_or(false, |it| it.syntax().text_range().contains(offset)) {
|
||||||
return None;
|
return None;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1012,3 +1012,34 @@ use self as Str$0;
|
||||||
expect![[r#""#]],
|
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