Unnamed repository; edit this file 'description' to name the repository.
fix: handle aliased pattern and simplify testcase
Khanh Duong Quoc 2024-10-24
parent cf5f1e8 · commit 962d340
-rw-r--r--crates/ide-completion/src/render.rs2
-rw-r--r--crates/ide-completion/src/tests/flyimport.rs53
2 files changed, 32 insertions, 23 deletions
diff --git a/crates/ide-completion/src/render.rs b/crates/ide-completion/src/render.rs
index 08a3450fda..d146990c5a 100644
--- a/crates/ide-completion/src/render.rs
+++ b/crates/ide-completion/src/render.rs
@@ -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))
}
diff --git a/crates/ide-completion/src/tests/flyimport.rs b/crates/ide-completion/src/tests/flyimport.rs
index 1ca0116c79..4b949e0d65 100644
--- a/crates/ide-completion/src/tests/flyimport.rs
+++ b/crates/ide-completion/src/tests/flyimport.rs
@@ -1671,43 +1671,52 @@ mod module {
}
#[test]
-fn re_export_aliased_function() {
+fn re_export_aliased() {
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
+mod outer {
+ mod inner {
+ pub struct BarStruct;
+ pub fn bar_fun() {}
+ pub mod bar {}
+ }
+ pub use inner::bar as foo;
+ pub use inner::bar_fun as foo_fun;
+ pub use inner::BarStruct as FooStruct;
+}
+fn function() {
+ foo$0
}
"#,
expect![[r#"
- fn my_func(…) (use foo::my_func) fn(i32) -> i32
+ st FooStruct (use outer::FooStruct) BarStruct
+ md foo (use outer::foo)
+ fn foo_fun() (use outer::foo_fun) fn()
"#]],
);
}
#[test]
-fn re_export_aliased_module() {
+fn re_export_aliased_pattern() {
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
+mod outer {
+ mod inner {
+ pub struct BarStruct;
+ pub fn bar_fun() {}
+ pub mod bar {}
+ }
+ pub use inner::bar as foo;
+ pub use inner::bar_fun as foo_fun;
+ pub use inner::BarStruct as FooStruct;
+}
+fn function() {
+ let foo$0
}
"#,
expect![[r#"
- md my_baz (use foo::my_baz)
+ st FooStruct (use outer::FooStruct)
+ md foo (use outer::foo)
"#]],
);
}