internal: Collapse lift is_infer_qualifier into Qualified variant

This commit is contained in:
Lukas Wirth 2022-06-17 17:15:29 +02:00
parent 2f2ea77d88
commit d6f161ffa9
10 changed files with 41 additions and 40 deletions

View file

@ -112,6 +112,7 @@ pub(crate) fn complete_attribute(acc: &mut Completions, ctx: &CompletionContext)
});
acc.add_nameref_keywords_with_colon(ctx);
}
Qualified::Infer => {}
}
let attributes = annotated_item_kind.and_then(|kind| {

View file

@ -101,6 +101,7 @@ pub(crate) fn complete_derive(acc: &mut Completions, ctx: &CompletionContext) {
});
acc.add_nameref_keywords_with_colon(ctx);
}
Qualified::Infer => {}
}
}

View file

@ -61,15 +61,13 @@ pub(crate) fn complete_expr_path(acc: &mut Completions, ctx: &CompletionContext)
};
match qualified {
Qualified::With(PathQualifierCtx { is_infer_qualifier, resolution, .. }) => {
if *is_infer_qualifier {
ctx.traits_in_scope()
.0
.into_iter()
.flat_map(|it| hir::Trait::from(it).items(ctx.sema.db))
.for_each(|item| add_assoc_item(acc, ctx, item));
return;
}
Qualified::Infer => ctx
.traits_in_scope()
.0
.into_iter()
.flat_map(|it| hir::Trait::from(it).items(ctx.sema.db))
.for_each(|item| add_assoc_item(acc, ctx, item)),
Qualified::With(PathQualifierCtx { resolution, .. }) => {
let resolution = match resolution {
Some(it) => it,
None => return,

View file

@ -66,7 +66,7 @@ pub(crate) fn complete_item_list(acc: &mut Completions, ctx: &CompletionContext)
});
acc.add_nameref_keywords_with_colon(ctx);
}
Qualified::No => {}
Qualified::Infer | Qualified::No => {}
}
}

View file

@ -208,5 +208,6 @@ fn pattern_path_completion(
acc.add_nameref_keywords_with_colon(ctx);
}
Qualified::Infer => {}
}
}

View file

@ -55,15 +55,13 @@ pub(crate) fn complete_type_path(acc: &mut Completions, ctx: &CompletionContext)
};
match qualified {
Qualified::With(PathQualifierCtx { is_infer_qualifier, resolution, .. }) => {
if *is_infer_qualifier {
ctx.traits_in_scope()
.0
.into_iter()
.flat_map(|it| hir::Trait::from(it).items(ctx.sema.db))
.for_each(|item| add_assoc_item(acc, item));
return;
}
Qualified::Infer => ctx
.traits_in_scope()
.0
.into_iter()
.flat_map(|it| hir::Trait::from(it).items(ctx.sema.db))
.for_each(|item| add_assoc_item(acc, item)),
Qualified::With(PathQualifierCtx { resolution, .. }) => {
let resolution = match resolution {
Some(it) => it,
None => return,

View file

@ -24,13 +24,7 @@ pub(crate) fn complete_use_tree(acc: &mut Completions, ctx: &CompletionContext)
};
match qualified {
Qualified::With(PathQualifierCtx {
path,
resolution,
is_super_chain,
use_tree_parent,
..
}) => {
Qualified::With(PathQualifierCtx { path, resolution, is_super_chain, use_tree_parent }) => {
if *is_super_chain {
acc.add_keyword(ctx, "super::");
}
@ -136,5 +130,6 @@ pub(crate) fn complete_use_tree(acc: &mut Completions, ctx: &CompletionContext)
});
acc.add_nameref_keywords_with_colon(ctx);
}
Qualified::Infer => {}
}
}

View file

@ -37,7 +37,7 @@ pub(crate) fn complete_vis_path(acc: &mut Completions, ctx: &CompletionContext)
acc.add_keyword(ctx, "super::");
}
}
Qualified::Absolute => {}
Qualified::Absolute | Qualified::Infer => {}
Qualified::No => {
if !has_in_token {
cov_mark::hit!(kw_completion_in);

View file

@ -150,6 +150,8 @@ pub(super) enum ItemListKind {
pub(super) enum Qualified {
No,
With(PathQualifierCtx),
/// <_>::
Infer,
/// Whether the path is an absolute path
Absolute,
}
@ -163,8 +165,6 @@ pub(crate) struct PathQualifierCtx {
pub(crate) is_super_chain: bool,
/// Whether the qualifier comes from a use tree parent or not
pub(crate) use_tree_parent: bool,
/// <_>
pub(crate) is_infer_qualifier: bool,
}
/// The state of the pattern we are completing.
@ -320,13 +320,16 @@ pub(crate) struct CompletionContext<'a> {
pub(super) expected_type: Option<Type>,
/// The parent function of the cursor position if it exists.
// FIXME: This probably doesn't belong here
pub(super) function_def: Option<ast::Fn>,
/// The parent impl of the cursor position if it exists.
// FIXME: This probably doesn't belong here
pub(super) impl_def: Option<ast::Impl>,
/// Are we completing inside a let statement with a missing semicolon?
// FIXME: This should be part of PathKind::Expr
pub(super) incomplete_let: bool,
// FIXME: This shouldn't exist
pub(super) previous_token: Option<SyntaxToken>,
pub(super) ident_ctx: IdentContext,
@ -354,6 +357,7 @@ impl<'a> CompletionContext<'a> {
}
}
// FIXME: This shouldn't exist
pub(crate) fn previous_token_is(&self, kind: SyntaxKind) -> bool {
self.previous_token.as_ref().map_or(false, |tok| tok.kind() == kind)
}

View file

@ -861,10 +861,6 @@ impl<'a> CompletionContext<'a> {
.and_then(|it| find_node_in_file(original_file, &it))
.map(|it| it.parent_path());
if let Some(path) = path {
let res = sema.resolve_path(&path);
let is_super_chain = iter::successors(Some(path.clone()), |p| p.qualifier())
.all(|p| p.segment().and_then(|s| s.super_token()).is_some());
// `<_>::$0`
let is_infer_qualifier = path.qualifier().is_none()
&& matches!(
@ -875,13 +871,20 @@ impl<'a> CompletionContext<'a> {
})
);
path_ctx.qualified = Qualified::With(PathQualifierCtx {
path,
resolution: res,
is_super_chain,
use_tree_parent,
is_infer_qualifier,
})
path_ctx.qualified = if is_infer_qualifier {
Qualified::Infer
} else {
let res = sema.resolve_path(&path);
let is_super_chain =
iter::successors(Some(path.clone()), |p| p.qualifier())
.all(|p| p.segment().and_then(|s| s.super_token()).is_some());
Qualified::With(PathQualifierCtx {
path,
resolution: res,
is_super_chain,
use_tree_parent,
})
}
};
}
} else if let Some(segment) = path.segment() {