mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-15 14:43: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);
|
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);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -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::
|
||||||
|
|
Loading…
Reference in a new issue