Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 55bc693

Browse files
committed
fix: show non-std enum in a fresh use tree completion
1 parent 66a8421 commit 55bc693

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

crates/ide-completion/src/completions/use_.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,22 @@ pub(crate) fn complete_use_tree(acc: &mut Completions, ctx: &CompletionContext)
101101
cov_mark::hit!(use_tree_crate_roots_only);
102102
acc.add_crate_roots(ctx);
103103
}
104-
// only show modules in a fresh UseTree
104+
// only show modules and non-std enum in a fresh UseTree
105105
None => {
106-
cov_mark::hit!(unqualified_path_only_modules_in_import);
106+
cov_mark::hit!(unqualified_path_selected_only);
107107
ctx.process_all_names(&mut |name, res| {
108-
if let ScopeDef::ModuleDef(hir::ModuleDef::Module(_)) = res {
108+
let should_add_resolution = match res {
109+
ScopeDef::ModuleDef(hir::ModuleDef::Module(_)) => true,
110+
ScopeDef::ModuleDef(hir::ModuleDef::Adt(hir::Adt::Enum(_))) => {
111+
match res.krate(ctx.db) {
112+
// exclude prelude enum
113+
Some(krate) => !krate.is_builtin(ctx.db),
114+
_ => true,
115+
}
116+
}
117+
_ => false,
118+
};
119+
if should_add_resolution {
109120
acc.add_resolution(ctx, name, res);
110121
}
111122
});

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,23 @@ fn check(ra_fixture: &str, expect: Expect) {
1010

1111
#[test]
1212
fn use_tree_start() {
13-
cov_mark::check!(unqualified_path_only_modules_in_import);
13+
cov_mark::check!(unqualified_path_selected_only);
1414
check(
1515
r#"
1616
//- /lib.rs crate:main deps:other_crate
1717
use f$0
1818
1919
struct Foo;
20+
enum FooBar {
21+
Foo,
22+
Bar
23+
}
2024
mod foo {}
2125
//- /other_crate/lib.rs crate:other_crate
2226
// nothing here
2327
"#,
2428
expect![[r#"
29+
en FooBar
2530
md foo
2631
md other_crate
2732
kw crate::

0 commit comments

Comments
 (0)