2022-02-02 15:14:43 +01:00
|
|
|
//! Completion for visibility specifiers.
|
|
|
|
|
|
|
|
use hir::ScopeDef;
|
|
|
|
|
|
|
|
use crate::{
|
2022-02-02 16:01:46 +01:00
|
|
|
context::{CompletionContext, PathCompletionCtx, PathKind, PathQualifierCtx},
|
2022-02-02 15:14:43 +01:00
|
|
|
Completions,
|
|
|
|
};
|
|
|
|
|
|
|
|
pub(crate) fn complete_vis(acc: &mut Completions, ctx: &CompletionContext) {
|
2022-02-02 16:01:46 +01:00
|
|
|
let (is_absolute_path, qualifier, has_in_token) = match ctx.path_context {
|
|
|
|
Some(PathCompletionCtx {
|
2022-02-02 15:14:43 +01:00
|
|
|
kind: Some(PathKind::Vis { has_in_token }),
|
2022-02-02 16:01:46 +01:00
|
|
|
is_absolute_path,
|
2022-02-02 15:14:43 +01:00
|
|
|
ref qualifier,
|
|
|
|
..
|
2022-02-02 16:01:46 +01:00
|
|
|
}) => (is_absolute_path, qualifier, has_in_token),
|
2022-02-02 15:14:43 +01:00
|
|
|
_ => return,
|
|
|
|
};
|
|
|
|
|
|
|
|
match qualifier {
|
2022-02-02 16:01:46 +01:00
|
|
|
Some(PathQualifierCtx { resolution, is_super_chain, .. }) => {
|
|
|
|
if let Some(hir::PathResolution::Def(hir::ModuleDef::Module(module))) = resolution {
|
2022-02-02 15:14:43 +01:00
|
|
|
if let Some(current_module) = ctx.module {
|
|
|
|
let next_towards_current = current_module
|
|
|
|
.path_to_root(ctx.db)
|
|
|
|
.into_iter()
|
|
|
|
.take_while(|it| it != module)
|
|
|
|
.next();
|
|
|
|
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 16:01:46 +01:00
|
|
|
if *is_super_chain {
|
2022-02-02 15:14:43 +01:00
|
|
|
acc.add_keyword(ctx, "super::");
|
|
|
|
}
|
|
|
|
}
|
2022-02-02 16:01:46 +01:00
|
|
|
None if !is_absolute_path => {
|
2022-02-02 15:14:43 +01:00
|
|
|
if !has_in_token {
|
|
|
|
cov_mark::hit!(kw_completion_in);
|
|
|
|
acc.add_keyword(ctx, "in");
|
|
|
|
}
|
|
|
|
["self", "super", "crate"].into_iter().for_each(|kw| acc.add_keyword(ctx, kw));
|
|
|
|
}
|
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
}
|