ide_completion/completions/
vis.rs1use crate::{
4 Completions,
5 context::{CompletionContext, PathCompletionCtx, Qualified},
6};
7
8pub(crate) fn complete_vis_path(
9 acc: &mut Completions,
10 ctx: &CompletionContext<'_>,
11 path_ctx @ PathCompletionCtx { qualified, .. }: &PathCompletionCtx<'_>,
12 &has_in_token: &bool,
13) {
14 match qualified {
15 Qualified::With {
16 resolution: Some(hir::PathResolution::Def(hir::ModuleDef::Module(module))),
17 super_chain_len,
18 ..
19 } => {
20 let next_towards_current =
22 ctx.module.path_to_root(ctx.db).into_iter().take_while(|it| it != module).last();
23 if let Some(next) = next_towards_current
24 && let Some(name) = next.name(ctx.db)
25 {
26 cov_mark::hit!(visibility_qualified);
27 acc.add_module(ctx, path_ctx, next, name, vec![]);
28 }
29
30 acc.add_super_keyword(ctx, *super_chain_len);
31 }
32 Qualified::Absolute | Qualified::TypeAnchor { .. } | Qualified::With { .. } => {}
33 Qualified::No => {
34 if !has_in_token {
35 cov_mark::hit!(kw_completion_in);
36 acc.add_keyword_snippet(ctx, "in", "in $0");
37 }
38 acc.add_nameref_keywords(ctx);
39 }
40 }
41}