|| ctx.is_path_disallowed()
|| ctx.expects_item()
|| ctx.expects_assoc_item()
+ || ctx.expects_variant()
{
return None;
}
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))
}
StmtList,
ItemList,
TypeBound,
+ Variant,
/// Fake file ast node
Attribute(ast::Attr),
/// Fake file ast node
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 {
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)
+ "#]],
+ )
+}