@@ -71,7 +71,6 @@ fn complete_enum_variants(acc: &mut Completions, ctx: &CompletionContext, ty: &T
7171 }
7272}
7373
74- // TODO kb add a setting toggle for this feature?
7574fn fuzzy_completion ( acc : & mut Completions , ctx : & CompletionContext ) -> Option < ( ) > {
7675 let _p = profile:: span ( "fuzzy_completion®" ) ;
7776 let current_module = ctx. scope . module ( ) ?;
@@ -97,23 +96,35 @@ fn fuzzy_completion(acc: &mut Completions, ctx: &CompletionContext) -> Option<()
9796 } )
9897 . filter ( |( mod_path, _) | mod_path. len ( ) > 1 )
9998 . filter_map ( |( mod_path, definition) | {
100- let mut resolution_with_missing_import = render_resolution (
101- RenderContext :: new ( ctx) ,
102- mod_path. segments . last ( ) ?. to_string ( ) ,
103- & definition,
104- ) ?;
99+ let use_to_insert = mod_path_to_ast ( & mod_path) ;
100+ let mut mod_path_without_last_segment = mod_path;
101+ let name_after_import = mod_path_without_last_segment. segments . pop ( ) ?. to_string ( ) ;
102+
103+ let resolution_with_missing_import =
104+ render_resolution ( RenderContext :: new ( ctx) , name_after_import, & definition) ?;
105+ let lookup_string = resolution_with_missing_import. lookup ( ) . to_owned ( ) ;
105106
106107 let mut text_edits =
107108 resolution_with_missing_import. text_edit ( ) . to_owned ( ) . into_builder ( ) ;
108-
109- let rewriter =
110- insert_use ( & import_scope, mod_path_to_ast ( & mod_path) , ctx. config . merge ) ;
109+ let rewriter = insert_use ( & import_scope, use_to_insert, ctx. config . merge ) ;
111110 let old_ast = rewriter. rewrite_root ( ) ?;
112111 algo:: diff ( & old_ast, & rewriter. rewrite ( & old_ast) ) . into_text_edit ( & mut text_edits) ;
113112
114- resolution_with_missing_import. update_text_edit ( text_edits. finish ( ) ) ;
115-
116- Some ( resolution_with_missing_import)
113+ let qualifier_string = mod_path_without_last_segment. to_string ( ) ;
114+ let qualified_label = if qualifier_string. is_empty ( ) {
115+ resolution_with_missing_import. label ( ) . to_owned ( )
116+ } else {
117+ format ! ( "{}::{}" , qualifier_string, resolution_with_missing_import. label( ) )
118+ } ;
119+
120+ Some (
121+ resolution_with_missing_import
122+ . into_builder ( )
123+ . text_edit ( text_edits. finish ( ) )
124+ . label ( qualified_label)
125+ . lookup_by ( lookup_string)
126+ . build ( ) ,
127+ )
117128 } )
118129 . take ( 20 ) ;
119130
0 commit comments