mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 05:15:04 +00:00
Merge pull request #18382 from dqkqd/issue-17042
fix: auto-complete import for aliased function and module
This commit is contained in:
commit
223979bf97
2 changed files with 72 additions and 3 deletions
|
@ -281,8 +281,8 @@ pub(crate) fn render_resolution_with_import(
|
|||
import_edit: LocatedImport,
|
||||
) -> Option<Builder> {
|
||||
let resolution = ScopeDef::from(import_edit.original_item);
|
||||
let local_name = scope_def_to_name(resolution, &ctx, &import_edit)?;
|
||||
//this now just renders the alias text, but we need to find the aliases earlier and call this with the alias instead
|
||||
let local_name = get_import_name(resolution, &ctx, &import_edit)?;
|
||||
// This now just renders the alias text, but we need to find the aliases earlier and call this with the alias instead.
|
||||
let doc_aliases = ctx.completion.doc_aliases_in_scope(resolution);
|
||||
let ctx = ctx.doc_aliases(doc_aliases);
|
||||
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(
|
|||
import_edit: LocatedImport,
|
||||
) -> Option<Builder> {
|
||||
let resolution = ScopeDef::from(import_edit.original_item);
|
||||
let local_name = scope_def_to_name(resolution, &ctx, &import_edit)?;
|
||||
let local_name = get_import_name(resolution, &ctx, &import_edit)?;
|
||||
Some(render_resolution_pat(ctx, pattern_ctx, local_name, Some(import_edit), resolution))
|
||||
}
|
||||
|
||||
|
@ -357,6 +357,24 @@ pub(crate) fn render_expr(
|
|||
Some(item)
|
||||
}
|
||||
|
||||
fn get_import_name(
|
||||
resolution: ScopeDef,
|
||||
ctx: &RenderContext<'_>,
|
||||
import_edit: &LocatedImport,
|
||||
) -> Option<hir::Name> {
|
||||
// FIXME: Temporary workaround for handling aliased import.
|
||||
// This should be removed after we have proper support for importing alias.
|
||||
// <https://github.com/rust-lang/rust-analyzer/issues/14079>
|
||||
|
||||
// If `item_to_import` matches `original_item`, we are importing the item itself (not its parent module).
|
||||
// In this case, we can use the last segment of `import_path`, as it accounts for the aliased name.
|
||||
if import_edit.item_to_import == import_edit.original_item {
|
||||
import_edit.import_path.segments().last().cloned()
|
||||
} else {
|
||||
scope_def_to_name(resolution, ctx, import_edit)
|
||||
}
|
||||
}
|
||||
|
||||
fn scope_def_to_name(
|
||||
resolution: ScopeDef,
|
||||
ctx: &RenderContext<'_>,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue