]> git.lizzy.rs Git - rust.git/blob - src/tools/rust-analyzer/crates/ide-completion/src/completions/vis.rs
Rollup merge of #98111 - eggyal:issue-97982, r=GuillaumeGomez
[rust.git] / src / tools / rust-analyzer / crates / ide-completion / src / completions / vis.rs
1 //! Completion for visibility specifiers.
2
3 use crate::{
4     context::{CompletionContext, PathCompletionCtx, Qualified},
5     Completions,
6 };
7
8 pub(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             // Try completing next child module of the path that is still a parent of the current module
21             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                 if let Some(name) = next.name(ctx.db) {
25                     cov_mark::hit!(visibility_qualified);
26                     acc.add_module(ctx, path_ctx, next, name);
27                 }
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(ctx, "in");
37             }
38             acc.add_nameref_keywords(ctx);
39         }
40     }
41 }