Skip to content

Commit 212095a

Browse files
bors[bot]xffxff
andauthored
Merge #10762
10762: Fix: trigger flyimport on enum variants r=lnicola a=XFFXFF fixes #10749 Co-authored-by: zhoufan <[email protected]>
2 parents 766b52b + 5666046 commit 212095a

File tree

4 files changed

+38
-0
lines changed

4 files changed

+38
-0
lines changed

crates/ide_completion/src/completions/flyimport.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ pub(crate) fn import_on_the_fly(acc: &mut Completions, ctx: &CompletionContext)
113113
|| ctx.is_path_disallowed()
114114
|| ctx.expects_item()
115115
|| ctx.expects_assoc_item()
116+
|| ctx.expects_variant()
116117
{
117118
return None;
118119
}

crates/ide_completion/src/context.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,10 @@ impl<'a> CompletionContext<'a> {
171171
matches!(self.completion_location, Some(ImmediateLocation::Trait | ImmediateLocation::Impl))
172172
}
173173

174+
pub(crate) fn expects_variant(&self) -> bool {
175+
matches!(self.completion_location, Some(ImmediateLocation::Variant))
176+
}
177+
174178
pub(crate) fn expects_non_trait_assoc_item(&self) -> bool {
175179
matches!(self.completion_location, Some(ImmediateLocation::Impl))
176180
}

crates/ide_completion/src/patterns.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ pub(crate) enum ImmediateLocation {
4545
StmtList,
4646
ItemList,
4747
TypeBound,
48+
Variant,
4849
/// Fake file ast node
4950
Attribute(ast::Attr),
5051
/// Fake file ast node
@@ -213,6 +214,7 @@ pub(crate) fn determine_location(
213214
ast::SourceFile(_it) => ImmediateLocation::ItemList,
214215
ast::ItemList(_it) => ImmediateLocation::ItemList,
215216
ast::RefExpr(_it) => ImmediateLocation::RefExpr,
217+
ast::Variant(_it) => ImmediateLocation::Variant,
216218
ast::RecordField(it) => if it.ty().map_or(false, |it| it.syntax().text_range().contains(offset)) {
217219
return None;
218220
} else {

crates/ide_completion/src/tests/flyimport.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,3 +1012,34 @@ use self as Str$0;
10121012
expect![[r#""#]],
10131013
);
10141014
}
1015+
1016+
#[test]
1017+
fn flyimport_enum_variant() {
1018+
check(
1019+
r#"
1020+
mod foo {
1021+
pub struct Barbara;
1022+
}
1023+
1024+
enum Foo {
1025+
Barba$0()
1026+
}
1027+
}"#,
1028+
expect![[r#""#]],
1029+
);
1030+
1031+
check(
1032+
r#"
1033+
mod foo {
1034+
pub struct Barbara;
1035+
}
1036+
1037+
enum Foo {
1038+
Barba(Barba$0)
1039+
}
1040+
}"#,
1041+
expect![[r#"
1042+
st Barbara (use foo::Barbara)
1043+
"#]],
1044+
)
1045+
}

0 commit comments

Comments
 (0)