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);
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);
}
});

View file

@ -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::