Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

50 lines
1.6 KiB
Rust
Raw Normal View History

//! 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) {
let _p = profile::span("complete_item_list");
2022-05-30 16:01:17 +02:00
let (&is_absolute_path, path_qualifier, _kind) = match ctx.path_context() {
Some(PathCompletionCtx {
2022-05-30 16:01:17 +02:00
kind: PathKind::Item { kind },
is_absolute_path,
qualifier,
..
2022-05-30 16:01:17 +02:00
}) => (is_absolute_path, qualifier, kind),
_ => return,
};
2022-05-30 16:01:17 +02:00
match path_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);
}
2022-05-30 16:01:17 +02:00
None if ctx.qualifier_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);
}
2022-05-30 16:01:17 +02:00
None => {}
}
}