aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_assists
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-03-06 10:10:16 +0000
committerGitHub <[email protected]>2020-03-06 10:10:16 +0000
commitd75577fcee79aac06bdddb01fde431f26432c36c (patch)
tree693a4d4c970cbc88feed6dbadd0656a04449242e /crates/ra_assists
parent670895a49c271751bf275f0ca1303a1bca7aad5a (diff)
parent0ff8c55246d242af2f2fc4f88e67395320d00865 (diff)
Merge #3483
3483: Unfold groups with single assists into plain assists r=matklad a=SomeoneToIgnore A follow-up of https://github.com/rust-analyzer/rust-analyzer/pull/3120/files#r378788698 , made to show more detailed label when the assist group contains a single element Co-authored-by: Kirill Bulatov <[email protected]>
Diffstat (limited to 'crates/ra_assists')
-rw-r--r--crates/ra_assists/src/assist_ctx.rs7
-rw-r--r--crates/ra_assists/src/handlers/auto_import.rs7
2 files changed, 6 insertions, 8 deletions
diff --git a/crates/ra_assists/src/assist_ctx.rs b/crates/ra_assists/src/assist_ctx.rs
index c25d2e323..62182cf03 100644
--- a/crates/ra_assists/src/assist_ctx.rs
+++ b/crates/ra_assists/src/assist_ctx.rs
@@ -166,8 +166,11 @@ impl<'a> AssistGroup<'a> {
166 } 166 }
167 167
168 pub(crate) fn finish(self) -> Option<Assist> { 168 pub(crate) fn finish(self) -> Option<Assist> {
169 assert!(!self.assists.is_empty()); 169 if self.assists.is_empty() {
170 Some(Assist(self.assists)) 170 None
171 } else {
172 Some(Assist(self.assists))
173 }
171 } 174 }
172} 175}
173 176
diff --git a/crates/ra_assists/src/handlers/auto_import.rs b/crates/ra_assists/src/handlers/auto_import.rs
index c8bf181f9..4b62aac48 100644
--- a/crates/ra_assists/src/handlers/auto_import.rs
+++ b/crates/ra_assists/src/handlers/auto_import.rs
@@ -42,12 +42,7 @@ pub(crate) fn auto_import(ctx: AssistCtx) -> Option<Assist> {
42 return None; 42 return None;
43 } 43 }
44 44
45 let assist_group_name = if proposed_imports.len() == 1 { 45 let mut group = ctx.add_assist_group(auto_import_assets.get_import_group_message());
46 format!("Import `{}`", proposed_imports.iter().next().unwrap())
47 } else {
48 auto_import_assets.get_import_group_message()
49 };
50 let mut group = ctx.add_assist_group(assist_group_name);
51 for import in proposed_imports { 46 for import in proposed_imports {
52 group.add_assist(AssistId("auto_import"), format!("Import `{}`", &import), |edit| { 47 group.add_assist(AssistId("auto_import"), format!("Import `{}`", &import), |edit| {
53 edit.target(auto_import_assets.syntax_under_caret.text_range()); 48 edit.target(auto_import_assets.syntax_under_caret.text_range());