@@ -281,8 +281,8 @@ pub(crate) fn render_resolution_with_import(
281281 import_edit : LocatedImport ,
282282) -> Option < Builder > {
283283 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.
286286 let doc_aliases = ctx. completion . doc_aliases_in_scope ( resolution) ;
287287 let ctx = ctx. doc_aliases ( doc_aliases) ;
288288 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(
294294 import_edit : LocatedImport ,
295295) -> Option < Builder > {
296296 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) ?;
298298 Some ( render_resolution_pat ( ctx, pattern_ctx, local_name, Some ( import_edit) , resolution) )
299299}
300300
@@ -357,6 +357,24 @@ pub(crate) fn render_expr(
357357 Some ( item)
358358}
359359
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+
360378fn scope_def_to_name (
361379 resolution : ScopeDef ,
362380 ctx : & RenderContext < ' _ > ,
0 commit comments