Skip to content

Commit 2942863

Browse files
committed
feat: append :: after
1 parent 55bc693 commit 2942863

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

crates/ide-completion/src/completions/use_.rs

+19-13
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
//! Completion for use trees
22
33
use hir::ScopeDef;
4-
use ide_db::FxHashSet;
4+
use ide_db::{FxHashSet, SymbolKind};
55
use syntax::{ast, AstNode};
66

77
use crate::{
88
context::{CompletionContext, NameRefContext, PathCompletionCtx, PathKind, PathQualifierCtx},
99
item::Builder,
10-
CompletionRelevance, Completions,
10+
CompletionItem, CompletionItemKind, CompletionRelevance, Completions,
1111
};
1212

1313
pub(crate) fn complete_use_tree(acc: &mut Completions, ctx: &CompletionContext) {
@@ -105,20 +105,26 @@ pub(crate) fn complete_use_tree(acc: &mut Completions, ctx: &CompletionContext)
105105
None => {
106106
cov_mark::hit!(unqualified_path_selected_only);
107107
ctx.process_all_names(&mut |name, res| {
108-
let should_add_resolution = match res {
109-
ScopeDef::ModuleDef(hir::ModuleDef::Module(_)) => true,
110-
ScopeDef::ModuleDef(hir::ModuleDef::Adt(hir::Adt::Enum(_))) => {
111-
match res.krate(ctx.db) {
112-
// exclude prelude enum
113-
Some(krate) => !krate.is_builtin(ctx.db),
114-
_ => true,
108+
match res {
109+
ScopeDef::ModuleDef(hir::ModuleDef::Module(_)) => {
110+
acc.add_resolution(ctx, name, res);
111+
}
112+
ScopeDef::ModuleDef(hir::ModuleDef::Adt(hir::Adt::Enum(e))) => {
113+
// exclude prelude enum
114+
let is_builtin =
115+
res.krate(ctx.db).map_or(false, |krate| krate.is_builtin(ctx.db));
116+
117+
if !is_builtin {
118+
let item = CompletionItem::new(
119+
CompletionItemKind::SymbolKind(SymbolKind::Enum),
120+
ctx.source_range(),
121+
format!("{}::", e.name(ctx.db)),
122+
);
123+
acc.add(item.build());
115124
}
116125
}
117-
_ => false,
126+
_ => {}
118127
};
119-
if should_add_resolution {
120-
acc.add_resolution(ctx, name, res);
121-
}
122128
});
123129
acc.add_nameref_keywords_with_colon(ctx);
124130
}

crates/ide-completion/src/tests/use_tree.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ mod foo {}
2626
// nothing here
2727
"#,
2828
expect![[r#"
29-
en FooBar
29+
en FooBar::
3030
md foo
3131
md other_crate
3232
kw crate::

0 commit comments

Comments
 (0)