@@ -281,8 +281,8 @@ pub(crate) fn render_resolution_with_import(
281
281
import_edit : LocatedImport ,
282
282
) -> Option < Builder > {
283
283
let resolution = ScopeDef :: from ( import_edit. original_item ) ;
284
- let local_name = scope_def_to_name ( resolution, & ctx, & import_edit) ?;
285
- //this now just renders the alias text, but we need to find the aliases earlier and call this with the alias instead
284
+ let local_name = get_import_name ( resolution, & ctx, & import_edit) ?;
285
+ // This now just renders the alias text, but we need to find the aliases earlier and call this with the alias instead.
286
286
let doc_aliases = ctx. completion . doc_aliases_in_scope ( resolution) ;
287
287
let ctx = ctx. doc_aliases ( doc_aliases) ;
288
288
Some ( render_resolution_path ( ctx, path_ctx, local_name, Some ( import_edit) , resolution) )
@@ -294,7 +294,7 @@ pub(crate) fn render_resolution_with_import_pat(
294
294
import_edit : LocatedImport ,
295
295
) -> Option < Builder > {
296
296
let resolution = ScopeDef :: from ( import_edit. original_item ) ;
297
- let local_name = scope_def_to_name ( resolution, & ctx, & import_edit) ?;
297
+ let local_name = get_import_name ( resolution, & ctx, & import_edit) ?;
298
298
Some ( render_resolution_pat ( ctx, pattern_ctx, local_name, Some ( import_edit) , resolution) )
299
299
}
300
300
@@ -357,6 +357,24 @@ pub(crate) fn render_expr(
357
357
Some ( item)
358
358
}
359
359
360
+ fn get_import_name (
361
+ resolution : ScopeDef ,
362
+ ctx : & RenderContext < ' _ > ,
363
+ import_edit : & LocatedImport ,
364
+ ) -> Option < hir:: Name > {
365
+ // FIXME: Temporary workaround for handling aliased import.
366
+ // This should be removed after we have proper support for importing alias.
367
+ // <https://github.com/rust-lang/rust-analyzer/issues/14079>
368
+
369
+ // If `item_to_import` matches `original_item`, we are importing the item itself (not its parent module).
370
+ // In this case, we can use the last segment of `import_path`, as it accounts for the aliased name.
371
+ if import_edit. item_to_import == import_edit. original_item {
372
+ import_edit. import_path . segments ( ) . last ( ) . cloned ( )
373
+ } else {
374
+ scope_def_to_name ( resolution, ctx, import_edit)
375
+ }
376
+ }
377
+
360
378
fn scope_def_to_name (
361
379
resolution : ScopeDef ,
362
380
ctx : & RenderContext < ' _ > ,
0 commit comments