mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 06:11:35 +00:00
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>
This commit is contained in:
commit
3e7ac2b830
1 changed files with 43 additions and 0 deletions
|
@ -113,6 +113,7 @@ pub(crate) fn import_on_the_fly(acc: &mut Completions, ctx: &CompletionContext)
|
||||||
if ctx.use_item_syntax.is_some()
|
if ctx.use_item_syntax.is_some()
|
||||||
|| ctx.attribute_under_caret.is_some()
|
|| ctx.attribute_under_caret.is_some()
|
||||||
|| ctx.mod_declaration_under_caret.is_some()
|
|| ctx.mod_declaration_under_caret.is_some()
|
||||||
|
|| ctx.record_lit_syntax.is_some()
|
||||||
{
|
{
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
@ -1034,4 +1035,46 @@ fn main() {
|
||||||
expect![[]],
|
expect![[]],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn no_fuzzy_during_fields_of_record_lit_syntax() {
|
||||||
|
check(
|
||||||
|
r#"
|
||||||
|
mod m {
|
||||||
|
pub fn some_fn() -> i32 {
|
||||||
|
42
|
||||||
|
}
|
||||||
|
}
|
||||||
|
struct Foo {
|
||||||
|
some_field: i32,
|
||||||
|
}
|
||||||
|
fn main() {
|
||||||
|
let _ = Foo { so$0 };
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
expect![[]],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn fuzzy_after_fields_of_record_lit_syntax() {
|
||||||
|
check(
|
||||||
|
r#"
|
||||||
|
mod m {
|
||||||
|
pub fn some_fn() -> i32 {
|
||||||
|
42
|
||||||
|
}
|
||||||
|
}
|
||||||
|
struct Foo {
|
||||||
|
some_field: i32,
|
||||||
|
}
|
||||||
|
fn main() {
|
||||||
|
let _ = Foo { some_field: so$0 };
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
fn some_fn() (m::some_fn) fn() -> i32
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue