2022-05-05 12:08:40 +02:00
|
|
|
//! Completion of paths and keywords at item list position.
|
|
|
|
|
|
|
|
use crate::{
|
|
|
|
completions::module_or_fn_macro,
|
|
|
|
context::{PathCompletionCtx, PathKind, PathQualifierCtx},
|
|
|
|
CompletionContext, Completions,
|
|
|
|
};
|
|
|
|
|
|
|
|
pub(crate) fn complete_item_list(acc: &mut Completions, ctx: &CompletionContext) {
|
2022-05-05 15:49:03 +02:00
|
|
|
let _p = profile::span("complete_item_list");
|
2022-05-05 12:08:40 +02:00
|
|
|
if ctx.is_path_disallowed() || ctx.has_unfinished_impl_or_trait_prev_sibling() {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-05-07 13:46:43 +02:00
|
|
|
let (&is_absolute_path, qualifier) = match ctx.path_context() {
|
2022-05-06 15:44:41 +02:00
|
|
|
Some(PathCompletionCtx {
|
|
|
|
kind: PathKind::Item { .. },
|
|
|
|
is_absolute_path,
|
|
|
|
qualifier,
|
|
|
|
..
|
|
|
|
}) => (is_absolute_path, qualifier),
|
2022-05-05 12:08:40 +02:00
|
|
|
_ => return,
|
|
|
|
};
|
|
|
|
|
|
|
|
match qualifier {
|
|
|
|
Some(PathQualifierCtx { resolution, is_super_chain, .. }) => {
|
|
|
|
if let Some(hir::PathResolution::Def(hir::ModuleDef::Module(module))) = resolution {
|
|
|
|
for (name, def) in module.scope(ctx.db, Some(ctx.module)) {
|
|
|
|
if let Some(def) = module_or_fn_macro(ctx.db, def) {
|
|
|
|
acc.add_resolution(ctx, name, def);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if *is_super_chain {
|
|
|
|
acc.add_keyword(ctx, "super::");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
None if is_absolute_path => {
|
|
|
|
acc.add_crate_roots(ctx);
|
|
|
|
}
|
|
|
|
None => {
|
|
|
|
ctx.process_all_names(&mut |name, def| {
|
|
|
|
if let Some(def) = module_or_fn_macro(ctx.db, def) {
|
|
|
|
acc.add_resolution(ctx, name, def);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
acc.add_nameref_keywords_with_colon(ctx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|