Skip to content

Commit 3e7ac2b

Browse files
Merge #8389
8389: Do not import on the fly during fields of record literal syntax r=SomeoneToIgnore a=memoryruins When only fields are relevant during record literal syntax (`Foo { field_$0 }`), RA already avoids completions of in-scope items, but with `rust-analyzer.completion.enableAutoimportCompletions` enabled, more than field names were eagerly suggested. This PR adds a case to `import_on_the_fly` to avoid the extra completions in this context. Closes #8300 Co-authored-by: memoryruins <memoryruinsmusic@gmail.com>
2 parents a35f7cb + e1e6e3b commit 3e7ac2b

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

crates/ide_completion/src/completions/flyimport.rs

Lines changed: 43 additions & 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
if ctx.use_item_syntax.is_some()
114114
|| ctx.attribute_under_caret.is_some()
115115
|| ctx.mod_declaration_under_caret.is_some()
116+
|| ctx.record_lit_syntax.is_some()
116117
{
117118
return None;
118119
}
@@ -1034,4 +1035,46 @@ fn main() {
10341035
expect![[]],
10351036
);
10361037
}
1038+
1039+
#[test]
1040+
fn no_fuzzy_during_fields_of_record_lit_syntax() {
1041+
check(
1042+
r#"
1043+
mod m {
1044+
pub fn some_fn() -> i32 {
1045+
42
1046+
}
1047+
}
1048+
struct Foo {
1049+
some_field: i32,
1050+
}
1051+
fn main() {
1052+
let _ = Foo { so$0 };
1053+
}
1054+
"#,
1055+
expect![[]],
1056+
);
1057+
}
1058+
1059+
#[test]
1060+
fn fuzzy_after_fields_of_record_lit_syntax() {
1061+
check(
1062+
r#"
1063+
mod m {
1064+
pub fn some_fn() -> i32 {
1065+
42
1066+
}
1067+
}
1068+
struct Foo {
1069+
some_field: i32,
1070+
}
1071+
fn main() {
1072+
let _ = Foo { some_field: so$0 };
1073+
}
1074+
"#,
1075+
expect![[r#"
1076+
fn some_fn() (m::some_fn) fn() -> i32
1077+
"#]],
1078+
);
1079+
}
10371080
}

0 commit comments

Comments
 (0)