mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-15 06:33:58 +00:00
fix: show non-std enum in a fresh use tree completion
This commit is contained in:
parent
66a842124b
commit
55bc693356
2 changed files with 20 additions and 4 deletions
|
@ -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);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -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::
|
||||
|
|
Loading…
Reference in a new issue