diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-04-07 00:47:39 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2021-04-07 00:47:39 +0100 |
commit | 3e7ac2b830f692fd993a9b30b6be96a4206b8229 (patch) | |
tree | 0067e28fc96755b5b145a6816fea1d4c9f020026 /crates/ide_completion | |
parent | a35f7cb6355f00a71a24338eb2d3bfc2920eccb4 (diff) | |
parent | e1e6e3b925bf7e0f6ca6cbc0d63d59572752653d (diff) |
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 <[email protected]>
Diffstat (limited to 'crates/ide_completion')
-rw-r--r-- | crates/ide_completion/src/completions/flyimport.rs | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/crates/ide_completion/src/completions/flyimport.rs b/crates/ide_completion/src/completions/flyimport.rs index 1ad017198..9ace13e41 100644 --- a/crates/ide_completion/src/completions/flyimport.rs +++ b/crates/ide_completion/src/completions/flyimport.rs | |||
@@ -113,6 +113,7 @@ pub(crate) fn import_on_the_fly(acc: &mut Completions, ctx: &CompletionContext) | |||
113 | if ctx.use_item_syntax.is_some() | 113 | if ctx.use_item_syntax.is_some() |
114 | || ctx.attribute_under_caret.is_some() | 114 | || ctx.attribute_under_caret.is_some() |
115 | || ctx.mod_declaration_under_caret.is_some() | 115 | || ctx.mod_declaration_under_caret.is_some() |
116 | || ctx.record_lit_syntax.is_some() | ||
116 | { | 117 | { |
117 | return None; | 118 | return None; |
118 | } | 119 | } |
@@ -1034,4 +1035,46 @@ fn main() { | |||
1034 | expect![[]], | 1035 | expect![[]], |
1035 | ); | 1036 | ); |
1036 | } | 1037 | } |
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 | } | ||
1037 | } | 1080 | } |