aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKirill Bulatov <[email protected]>2020-02-12 11:21:12 +0000
committerKirill Bulatov <[email protected]>2020-02-12 15:18:42 +0000
commit07058cbf9f16591b8c250ce59026117ddae71c61 (patch)
tree5667cabf39e6223b2e45bfea6cb979d8689a8cb1
parent24f7028d3f21b578b424a2b95998c2b9568aea80 (diff)
Adjust the assist group name
-rw-r--r--crates/ra_assists/src/handlers/auto_import.rs34
1 files changed, 25 insertions, 9 deletions
diff --git a/crates/ra_assists/src/handlers/auto_import.rs b/crates/ra_assists/src/handlers/auto_import.rs
index 2dcea3766..c564f5027 100644
--- a/crates/ra_assists/src/handlers/auto_import.rs
+++ b/crates/ra_assists/src/handlers/auto_import.rs
@@ -1,9 +1,3 @@
1use ra_ide_db::{imports_locator::ImportsLocator, RootDatabase};
2use ra_syntax::{
3 ast::{self, AstNode},
4 SyntaxNode,
5};
6
7use crate::{ 1use crate::{
8 assist_ctx::{Assist, AssistCtx}, 2 assist_ctx::{Assist, AssistCtx},
9 insert_use_statement, AssistId, 3 insert_use_statement, AssistId,
@@ -13,7 +7,12 @@ use hir::{
13 AssocContainerId, AssocItem, Crate, Function, ModPath, Module, ModuleDef, PathResolution, 7 AssocContainerId, AssocItem, Crate, Function, ModPath, Module, ModuleDef, PathResolution,
14 SourceAnalyzer, Trait, Type, 8 SourceAnalyzer, Trait, Type,
15}; 9};
10use ra_ide_db::{imports_locator::ImportsLocator, RootDatabase};
16use ra_prof::profile; 11use ra_prof::profile;
12use ra_syntax::{
13 ast::{self, AstNode},
14 SyntaxNode,
15};
17use rustc_hash::FxHashSet; 16use rustc_hash::FxHashSet;
18use std::collections::BTreeSet; 17use std::collections::BTreeSet;
19 18
@@ -50,9 +49,13 @@ pub(crate) fn auto_import(ctx: AssistCtx) -> Option<Assist> {
50 return None; 49 return None;
51 } 50 }
52 51
53 let mut group = 52 let assist_group_name = if proposed_imports.len() == 1 {
54 // TODO kb create another method and add something about traits there 53 format!("Import `{}`", proposed_imports.iter().next().unwrap())
55 ctx.add_assist_group(format!("Import {}", auto_import_assets.get_search_query())); 54 } else {
55 auto_import_assets.get_import_group_message()
56 };
57
58 let mut group = ctx.add_assist_group(assist_group_name);
56 for import in proposed_imports { 59 for import in proposed_imports {
57 group.add_assist(AssistId("auto_import"), format!("Import `{}`", &import), |edit| { 60 group.add_assist(AssistId("auto_import"), format!("Import `{}`", &import), |edit| {
58 edit.target(auto_import_assets.syntax_under_caret.text_range()); 61 edit.target(auto_import_assets.syntax_under_caret.text_range());
@@ -119,6 +122,19 @@ impl AutoImportAssets {
119 } 122 }
120 } 123 }
121 124
125 fn get_import_group_message(&self) -> String {
126 match &self.import_candidate {
127 ImportCandidate::UnqualifiedName(name_ref)
128 | ImportCandidate::QualifierStart(name_ref) => format!("Import {}", name_ref.syntax()),
129 ImportCandidate::TraitFunction(_, trait_function) => {
130 format!("Import a trait for function {}", trait_function.syntax())
131 }
132 ImportCandidate::TraitMethod(_, trait_method) => {
133 format!("Import a trait for method {}", trait_method.syntax())
134 }
135 }
136 }
137
122 fn search_for_imports( 138 fn search_for_imports(
123 &self, 139 &self,
124 db: &RootDatabase, 140 db: &RootDatabase,