From 29428637093cce62829e863eb5c8143da9860bef Mon Sep 17 00:00:00 2001 From: yue4u Date: Thu, 9 Jun 2022 16:37:18 +0900 Subject: [PATCH] feat: append :: after --- crates/ide-completion/src/completions/use_.rs | 32 +++++++++++-------- crates/ide-completion/src/tests/use_tree.rs | 2 +- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/crates/ide-completion/src/completions/use_.rs b/crates/ide-completion/src/completions/use_.rs index 2d86217077..28e4e47751 100644 --- a/crates/ide-completion/src/completions/use_.rs +++ b/crates/ide-completion/src/completions/use_.rs @@ -1,13 +1,13 @@ //! Completion for use trees use hir::ScopeDef; -use ide_db::FxHashSet; +use ide_db::{FxHashSet, SymbolKind}; use syntax::{ast, AstNode}; use crate::{ context::{CompletionContext, NameRefContext, PathCompletionCtx, PathKind, PathQualifierCtx}, item::Builder, - CompletionRelevance, Completions, + CompletionItem, CompletionItemKind, CompletionRelevance, Completions, }; 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) None => { cov_mark::hit!(unqualified_path_selected_only); ctx.process_all_names(&mut |name, 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, + match res { + ScopeDef::ModuleDef(hir::ModuleDef::Module(_)) => { + acc.add_resolution(ctx, name, res); + } + ScopeDef::ModuleDef(hir::ModuleDef::Adt(hir::Adt::Enum(e))) => { + // exclude prelude enum + let is_builtin = + res.krate(ctx.db).map_or(false, |krate| krate.is_builtin(ctx.db)); + + if !is_builtin { + let item = CompletionItem::new( + CompletionItemKind::SymbolKind(SymbolKind::Enum), + ctx.source_range(), + format!("{}::", e.name(ctx.db)), + ); + acc.add(item.build()); } } - _ => false, + _ => {} }; - if should_add_resolution { - acc.add_resolution(ctx, name, res); - } }); acc.add_nameref_keywords_with_colon(ctx); } diff --git a/crates/ide-completion/src/tests/use_tree.rs b/crates/ide-completion/src/tests/use_tree.rs index db283f69ce..711822d731 100644 --- a/crates/ide-completion/src/tests/use_tree.rs +++ b/crates/ide-completion/src/tests/use_tree.rs @@ -26,7 +26,7 @@ mod foo {} // nothing here "#, expect![[r#" - en FooBar + en FooBar:: md foo md other_crate kw crate::