From 55bc693356d793f3fae5cf9c7f97f8fc1cef5d2d Mon Sep 17 00:00:00 2001 From: yue4u Date: Wed, 8 Jun 2022 20:53:42 +0900 Subject: [PATCH] fix: show non-std enum in a fresh use tree completion --- crates/ide-completion/src/completions/use_.rs | 17 ++++++++++++++--- crates/ide-completion/src/tests/use_tree.rs | 7 ++++++- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/crates/ide-completion/src/completions/use_.rs b/crates/ide-completion/src/completions/use_.rs index f1beeb454c..2d86217077 100644 --- a/crates/ide-completion/src/completions/use_.rs +++ b/crates/ide-completion/src/completions/use_.rs @@ -101,11 +101,22 @@ pub(crate) fn complete_use_tree(acc: &mut Completions, ctx: &CompletionContext) cov_mark::hit!(use_tree_crate_roots_only); acc.add_crate_roots(ctx); } - // only show modules in a fresh UseTree + // only show modules and non-std enum in a fresh UseTree None => { - cov_mark::hit!(unqualified_path_only_modules_in_import); + cov_mark::hit!(unqualified_path_selected_only); ctx.process_all_names(&mut |name, res| { - if let ScopeDef::ModuleDef(hir::ModuleDef::Module(_)) = res { + let should_add_resolution = match res { + ScopeDef::ModuleDef(hir::ModuleDef::Module(_)) => true, + ScopeDef::ModuleDef(hir::ModuleDef::Adt(hir::Adt::Enum(_))) => { + match res.krate(ctx.db) { + // exclude prelude enum + Some(krate) => !krate.is_builtin(ctx.db), + _ => true, + } + } + _ => false, + }; + if should_add_resolution { acc.add_resolution(ctx, name, res); } }); diff --git a/crates/ide-completion/src/tests/use_tree.rs b/crates/ide-completion/src/tests/use_tree.rs index 70aa5e5468..db283f69ce 100644 --- a/crates/ide-completion/src/tests/use_tree.rs +++ b/crates/ide-completion/src/tests/use_tree.rs @@ -10,18 +10,23 @@ fn check(ra_fixture: &str, expect: Expect) { #[test] fn use_tree_start() { - cov_mark::check!(unqualified_path_only_modules_in_import); + cov_mark::check!(unqualified_path_selected_only); check( r#" //- /lib.rs crate:main deps:other_crate use f$0 struct Foo; +enum FooBar { + Foo, + Bar +} mod foo {} //- /other_crate/lib.rs crate:other_crate // nothing here "#, expect![[r#" + en FooBar md foo md other_crate kw crate::