mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 04:44:57 +00:00
fix: auto-complete import for aliased function and module
This commit is contained in:
parent
f9935be013
commit
c4b097719d
2 changed files with 50 additions and 2 deletions
|
@ -281,8 +281,14 @@ pub(crate) fn render_resolution_with_import(
|
||||||
import_edit: LocatedImport,
|
import_edit: LocatedImport,
|
||||||
) -> Option<Builder> {
|
) -> Option<Builder> {
|
||||||
let resolution = ScopeDef::from(import_edit.original_item);
|
let resolution = ScopeDef::from(import_edit.original_item);
|
||||||
let local_name = scope_def_to_name(resolution, &ctx, &import_edit)?;
|
// Use the last segment when `item_to_import` matches `original_item`,
|
||||||
//this now just renders the alias text, but we need to find the aliases earlier and call this with the alias instead
|
// as it will take the aliased name into account.
|
||||||
|
let local_name = if import_edit.item_to_import == import_edit.original_item {
|
||||||
|
import_edit.import_path.segments().last()?.clone()
|
||||||
|
} else {
|
||||||
|
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 doc_aliases = ctx.completion.doc_aliases_in_scope(resolution);
|
let doc_aliases = ctx.completion.doc_aliases_in_scope(resolution);
|
||||||
let ctx = ctx.doc_aliases(doc_aliases);
|
let ctx = ctx.doc_aliases(doc_aliases);
|
||||||
Some(render_resolution_path(ctx, path_ctx, local_name, Some(import_edit), resolution))
|
Some(render_resolution_path(ctx, path_ctx, local_name, Some(import_edit), resolution))
|
||||||
|
|
|
@ -1669,3 +1669,45 @@ mod module {
|
||||||
"#]],
|
"#]],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn re_export_aliased_function() {
|
||||||
|
check(
|
||||||
|
r#"
|
||||||
|
//- /lib.rs crate:bar
|
||||||
|
pub fn func(_: i32) -> i32 {}
|
||||||
|
|
||||||
|
//- /lib.rs crate:foo deps:bar
|
||||||
|
pub use bar::func as my_func;
|
||||||
|
|
||||||
|
//- /main.rs crate:main deps:foo
|
||||||
|
fn main() {
|
||||||
|
m$0
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
fn my_func(…) (use foo::my_func) fn(i32) -> i32
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn re_export_aliased_module() {
|
||||||
|
check(
|
||||||
|
r#"
|
||||||
|
//- /lib.rs crate:bar
|
||||||
|
pub mod baz {}
|
||||||
|
|
||||||
|
//- /lib.rs crate:foo deps:bar
|
||||||
|
pub use bar::baz as my_baz;
|
||||||
|
|
||||||
|
//- /main.rs crate:main deps:foo
|
||||||
|
fn main() {
|
||||||
|
m$0
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
md my_baz (use foo::my_baz)
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue