1- use ra_ide_db:: { imports_locator:: ImportsLocator , RootDatabase } ;
2- use ra_syntax:: {
3- ast:: { self , AstNode } ,
4- SyntaxNode ,
5- } ;
6-
71use 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 } ;
1611use ra_prof:: profile;
12+ use ra_syntax:: {
13+ ast:: { self , AstNode } ,
14+ SyntaxNode ,
15+ } ;
1716use rustc_hash:: FxHashSet ;
1817use 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