feat: Enable flyimport completions for attributes

This commit is contained in:
Lukas Wirth 2021-12-05 15:57:28 +01:00
parent 9b4ca77572
commit 1f254dd855
8 changed files with 217 additions and 34 deletions

View file

@ -30,10 +30,11 @@ pub(crate) enum PatternRefutability {
Irrefutable,
}
#[derive(Debug)]
#[derive(Copy, Clone, Debug)]
pub(super) enum PathKind {
Expr,
Type,
Attr,
}
#[derive(Debug)]
@ -232,8 +233,7 @@ impl<'a> CompletionContext<'a> {
}
pub(crate) fn is_path_disallowed(&self) -> bool {
self.attribute_under_caret.is_some()
|| self.previous_token_is(T![unsafe])
self.previous_token_is(T![unsafe])
|| matches!(
self.prev_sibling,
Some(ImmediatePrevSibling::Attribute | ImmediatePrevSibling::Visibility)
@ -241,8 +241,7 @@ impl<'a> CompletionContext<'a> {
|| matches!(
self.completion_location,
Some(
ImmediateLocation::Attribute(_)
| ImmediateLocation::ModDeclaration(_)
ImmediateLocation::ModDeclaration(_)
| ImmediateLocation::RecordPat(_)
| ImmediateLocation::RecordExpr(_)
| ImmediateLocation::Rename
@ -274,6 +273,10 @@ impl<'a> CompletionContext<'a> {
self.path_context.as_ref().and_then(|it| it.qualifier.as_ref())
}
pub(crate) fn path_kind(&self) -> Option<PathKind> {
self.path_context.as_ref().and_then(|it| it.kind)
}
/// Checks if an item is visible and not `doc(hidden)` at the completion site.
pub(crate) fn is_visible<I>(&self, item: &I) -> bool
where
@ -785,6 +788,7 @@ impl<'a> CompletionContext<'a> {
match parent {
ast::PathType(_it) => Some(PathKind::Type),
ast::PathExpr(_it) => Some(PathKind::Expr),
ast::Meta(_it) => Some(PathKind::Attr),
_ => None,
}
};