Skip to content

Commit 07058cb

Browse files
Adjust the assist group name
1 parent 24f7028 commit 07058cb

File tree

1 file changed

+25
-9
lines changed

1 file changed

+25
-9
lines changed

crates/ra_assists/src/handlers/auto_import.rs

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
use ra_ide_db::{imports_locator::ImportsLocator, RootDatabase};
2-
use ra_syntax::{
3-
ast::{self, AstNode},
4-
SyntaxNode,
5-
};
6-
71
use crate::{
82
assist_ctx::{Assist, AssistCtx},
93
insert_use_statement, AssistId,
@@ -13,7 +7,12 @@ use hir::{
137
AssocContainerId, AssocItem, Crate, Function, ModPath, Module, ModuleDef, PathResolution,
148
SourceAnalyzer, Trait, Type,
159
};
10+
use ra_ide_db::{imports_locator::ImportsLocator, RootDatabase};
1611
use ra_prof::profile;
12+
use ra_syntax::{
13+
ast::{self, AstNode},
14+
SyntaxNode,
15+
};
1716
use rustc_hash::FxHashSet;
1817
use std::collections::BTreeSet;
1918

@@ -50,9 +49,13 @@ pub(crate) fn auto_import(ctx: AssistCtx) -> Option<Assist> {
5049
return None;
5150
}
5251

53-
let mut group =
54-
// TODO kb create another method and add something about traits there
55-
ctx.add_assist_group(format!("Import {}", auto_import_assets.get_search_query()));
52+
let assist_group_name = if proposed_imports.len() == 1 {
53+
format!("Import `{}`", proposed_imports.iter().next().unwrap())
54+
} else {
55+
auto_import_assets.get_import_group_message()
56+
};
57+
58+
let mut group = ctx.add_assist_group(assist_group_name);
5659
for import in proposed_imports {
5760
group.add_assist(AssistId("auto_import"), format!("Import `{}`", &import), |edit| {
5861
edit.target(auto_import_assets.syntax_under_caret.text_range());
@@ -119,6 +122,19 @@ impl AutoImportAssets {
119122
}
120123
}
121124

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+
122138
fn search_for_imports(
123139
&self,
124140
db: &RootDatabase,

0 commit comments

Comments
 (0)