feat: append :: after

This commit is contained in:
yue4u 2022-06-09 16:37:18 +09:00
parent 55bc693356
commit 2942863709
2 changed files with 20 additions and 14 deletions

View file

@ -1,13 +1,13 @@
//! Completion for use trees //! Completion for use trees
use hir::ScopeDef; use hir::ScopeDef;
use ide_db::FxHashSet; use ide_db::{FxHashSet, SymbolKind};
use syntax::{ast, AstNode}; use syntax::{ast, AstNode};
use crate::{ use crate::{
context::{CompletionContext, NameRefContext, PathCompletionCtx, PathKind, PathQualifierCtx}, context::{CompletionContext, NameRefContext, PathCompletionCtx, PathKind, PathQualifierCtx},
item::Builder, item::Builder,
CompletionRelevance, Completions, CompletionItem, CompletionItemKind, CompletionRelevance, Completions,
}; };
pub(crate) fn complete_use_tree(acc: &mut Completions, ctx: &CompletionContext) { 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 => { None => {
cov_mark::hit!(unqualified_path_selected_only); cov_mark::hit!(unqualified_path_selected_only);
ctx.process_all_names(&mut |name, res| { ctx.process_all_names(&mut |name, res| {
let should_add_resolution = match res { match res {
ScopeDef::ModuleDef(hir::ModuleDef::Module(_)) => true, ScopeDef::ModuleDef(hir::ModuleDef::Module(_)) => {
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);
} }
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());
}
}
_ => {}
};
}); });
acc.add_nameref_keywords_with_colon(ctx); acc.add_nameref_keywords_with_colon(ctx);
} }

View file

@ -26,7 +26,7 @@ mod foo {}
// nothing here // nothing here
"#, "#,
expect![[r#" expect![[r#"
en FooBar en FooBar::
md foo md foo
md other_crate md other_crate
kw crate:: kw crate::