Skip to content

Commit 962d340

Browse files
committed
fix: handle aliased pattern and simplify testcase
1 parent cf5f1e8 commit 962d340

File tree

2 files changed

+32
-23
lines changed

2 files changed

+32
-23
lines changed

crates/ide-completion/src/render.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -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

crates/ide-completion/src/tests/flyimport.rs

+31-22
Original file line numberDiff line numberDiff line change
@@ -1671,43 +1671,52 @@ mod module {
16711671
}
16721672

16731673
#[test]
1674-
fn re_export_aliased_function() {
1674+
fn re_export_aliased() {
16751675
check(
16761676
r#"
1677-
//- /lib.rs crate:bar
1678-
pub fn func(_: i32) -> i32 {}
1679-
1680-
//- /lib.rs crate:foo deps:bar
1681-
pub use bar::func as my_func;
1682-
1683-
//- /main.rs crate:main deps:foo
1684-
fn main() {
1685-
m$0
1677+
mod outer {
1678+
mod inner {
1679+
pub struct BarStruct;
1680+
pub fn bar_fun() {}
1681+
pub mod bar {}
1682+
}
1683+
pub use inner::bar as foo;
1684+
pub use inner::bar_fun as foo_fun;
1685+
pub use inner::BarStruct as FooStruct;
1686+
}
1687+
fn function() {
1688+
foo$0
16861689
}
16871690
"#,
16881691
expect![[r#"
1689-
fn my_func(…) (use foo::my_func) fn(i32) -> i32
1692+
st FooStruct (use outer::FooStruct) BarStruct
1693+
md foo (use outer::foo)
1694+
fn foo_fun() (use outer::foo_fun) fn()
16901695
"#]],
16911696
);
16921697
}
16931698

16941699
#[test]
1695-
fn re_export_aliased_module() {
1700+
fn re_export_aliased_pattern() {
16961701
check(
16971702
r#"
1698-
//- /lib.rs crate:bar
1699-
pub mod baz {}
1700-
1701-
//- /lib.rs crate:foo deps:bar
1702-
pub use bar::baz as my_baz;
1703-
1704-
//- /main.rs crate:main deps:foo
1705-
fn main() {
1706-
m$0
1703+
mod outer {
1704+
mod inner {
1705+
pub struct BarStruct;
1706+
pub fn bar_fun() {}
1707+
pub mod bar {}
1708+
}
1709+
pub use inner::bar as foo;
1710+
pub use inner::bar_fun as foo_fun;
1711+
pub use inner::BarStruct as FooStruct;
1712+
}
1713+
fn function() {
1714+
let foo$0
17071715
}
17081716
"#,
17091717
expect![[r#"
1710-
md my_baz (use foo::my_baz)
1718+
st FooStruct (use outer::FooStruct)
1719+
md foo (use outer::foo)
17111720
"#]],
17121721
);
17131722
}

0 commit comments

Comments
 (0)