Unnamed repository; edit this file 'description' to name the repository.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//! 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");

    let (&is_absolute_path, path_qualifier, _kind) = match ctx.path_context() {
        Some(PathCompletionCtx {
            kind: PathKind::Item { kind },
            is_absolute_path,
            qualifier,
            ..
        }) => (is_absolute_path, qualifier, kind),
        _ => return,
    };

    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);
        }
        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);
        }
        None => {}
    }
}