2022-02-02 15:14:43 +01:00
|
|
|
//! Completion for visibility specifiers.
|
|
|
|
|
|
|
|
use hir::ScopeDef;
|
|
|
|
|
|
|
|
use crate::{
|
2022-06-17 16:36:22 +02:00
|
|
|
context::{CompletionContext, PathCompletionCtx, PathKind, PathQualifierCtx, Qualified},
|
2022-02-02 15:14:43 +01:00
|
|
|
Completions,
|
|
|
|
};
|
|
|
|
|
2022-05-10 15:00:58 +02:00
|
|
|
pub(crate) fn complete_vis_path(acc: &mut Completions, ctx: &CompletionContext) {
|
2022-06-17 16:36:22 +02:00
|
|
|
let (qualified, &has_in_token) = match ctx.path_context() {
|
|
|
|
Some(PathCompletionCtx { kind: PathKind::Vis { has_in_token }, qualified, .. }) => {
|
|
|
|
(qualified, has_in_token)
|
|
|
|
}
|
2022-02-02 15:14:43 +01:00
|
|
|
_ => return,
|
|
|
|
};
|
|
|
|
|
2022-06-17 16:36:22 +02:00
|
|
|
match qualified {
|
|
|
|
Qualified::With(PathQualifierCtx { resolution, is_super_chain, .. }) => {
|
2022-02-03 17:02:12 +01:00
|
|
|
// Try completing next child module of the path that is still a parent of the current module
|
2022-02-02 16:01:46 +01:00
|
|
|
if let Some(hir::PathResolution::Def(hir::ModuleDef::Module(module))) = resolution {
|
2022-03-31 11:12:08 +02:00
|
|
|
let next_towards_current = ctx
|
|
|
|
.module
|
|
|
|
.path_to_root(ctx.db)
|
|
|
|
.into_iter()
|
|
|
|
.take_while(|it| it != module)
|
|
|
|
.last();
|
|
|
|
if let Some(next) = next_towards_current {
|
|
|
|
if let Some(name) = next.name(ctx.db) {
|
|
|
|
cov_mark::hit!(visibility_qualified);
|
|
|
|
acc.add_resolution(ctx, name, ScopeDef::ModuleDef(next.into()));
|
2022-02-02 15:14:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-02 16:01:46 +01:00
|
|
|
if *is_super_chain {
|
2022-02-02 15:14:43 +01:00
|
|
|
acc.add_keyword(ctx, "super::");
|
|
|
|
}
|
|
|
|
}
|
2022-06-17 17:15:29 +02:00
|
|
|
Qualified::Absolute | Qualified::Infer => {}
|
2022-06-17 16:36:22 +02:00
|
|
|
Qualified::No => {
|
2022-02-02 15:14:43 +01:00
|
|
|
if !has_in_token {
|
|
|
|
cov_mark::hit!(kw_completion_in);
|
|
|
|
acc.add_keyword(ctx, "in");
|
|
|
|
}
|
2022-04-17 21:53:58 +02:00
|
|
|
acc.add_nameref_keywords(ctx);
|
2022-02-02 15:14:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|