fix: show non-std enum in a fresh use tree completion

This commit is contained in:
yue4u 2022-06-08 20:53:42 +09:00
parent 66a842124b
commit 55bc693356
2 changed files with 20 additions and 4 deletions

View file

@ -101,11 +101,22 @@ pub(crate) fn complete_use_tree(acc: &mut Completions, ctx: &CompletionContext)
cov_mark::hit!(use_tree_crate_roots_only); cov_mark::hit!(use_tree_crate_roots_only);
acc.add_crate_roots(ctx); acc.add_crate_roots(ctx);
} }
// only show modules in a fresh UseTree // only show modules and non-std enum in a fresh UseTree
None => { None => {
cov_mark::hit!(unqualified_path_only_modules_in_import); cov_mark::hit!(unqualified_path_selected_only);
ctx.process_all_names(&mut |name, res| { 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); acc.add_resolution(ctx, name, res);
} }
}); });

View file

@ -10,18 +10,23 @@ fn check(ra_fixture: &str, expect: Expect) {
#[test] #[test]
fn use_tree_start() { fn use_tree_start() {
cov_mark::check!(unqualified_path_only_modules_in_import); cov_mark::check!(unqualified_path_selected_only);
check( check(
r#" r#"
//- /lib.rs crate:main deps:other_crate //- /lib.rs crate:main deps:other_crate
use f$0 use f$0
struct Foo; struct Foo;
enum FooBar {
Foo,
Bar
}
mod foo {} mod foo {}
//- /other_crate/lib.rs crate:other_crate //- /other_crate/lib.rs crate:other_crate
// nothing here // nothing here
"#, "#,
expect![[r#" expect![[r#"
en FooBar
md foo md foo
md other_crate md other_crate
kw crate:: kw crate::