mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 04:44:57 +00:00
internal: Collapse lift is_infer_qualifier into Qualified
variant
This commit is contained in:
parent
2f2ea77d88
commit
d6f161ffa9
10 changed files with 41 additions and 40 deletions
|
@ -112,6 +112,7 @@ pub(crate) fn complete_attribute(acc: &mut Completions, ctx: &CompletionContext)
|
||||||
});
|
});
|
||||||
acc.add_nameref_keywords_with_colon(ctx);
|
acc.add_nameref_keywords_with_colon(ctx);
|
||||||
}
|
}
|
||||||
|
Qualified::Infer => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
let attributes = annotated_item_kind.and_then(|kind| {
|
let attributes = annotated_item_kind.and_then(|kind| {
|
||||||
|
|
|
@ -101,6 +101,7 @@ pub(crate) fn complete_derive(acc: &mut Completions, ctx: &CompletionContext) {
|
||||||
});
|
});
|
||||||
acc.add_nameref_keywords_with_colon(ctx);
|
acc.add_nameref_keywords_with_colon(ctx);
|
||||||
}
|
}
|
||||||
|
Qualified::Infer => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -61,15 +61,13 @@ pub(crate) fn complete_expr_path(acc: &mut Completions, ctx: &CompletionContext)
|
||||||
};
|
};
|
||||||
|
|
||||||
match qualified {
|
match qualified {
|
||||||
Qualified::With(PathQualifierCtx { is_infer_qualifier, resolution, .. }) => {
|
Qualified::Infer => ctx
|
||||||
if *is_infer_qualifier {
|
.traits_in_scope()
|
||||||
ctx.traits_in_scope()
|
.0
|
||||||
.0
|
.into_iter()
|
||||||
.into_iter()
|
.flat_map(|it| hir::Trait::from(it).items(ctx.sema.db))
|
||||||
.flat_map(|it| hir::Trait::from(it).items(ctx.sema.db))
|
.for_each(|item| add_assoc_item(acc, ctx, item)),
|
||||||
.for_each(|item| add_assoc_item(acc, ctx, item));
|
Qualified::With(PathQualifierCtx { resolution, .. }) => {
|
||||||
return;
|
|
||||||
}
|
|
||||||
let resolution = match resolution {
|
let resolution = match resolution {
|
||||||
Some(it) => it,
|
Some(it) => it,
|
||||||
None => return,
|
None => return,
|
||||||
|
|
|
@ -66,7 +66,7 @@ pub(crate) fn complete_item_list(acc: &mut Completions, ctx: &CompletionContext)
|
||||||
});
|
});
|
||||||
acc.add_nameref_keywords_with_colon(ctx);
|
acc.add_nameref_keywords_with_colon(ctx);
|
||||||
}
|
}
|
||||||
Qualified::No => {}
|
Qualified::Infer | Qualified::No => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -208,5 +208,6 @@ fn pattern_path_completion(
|
||||||
|
|
||||||
acc.add_nameref_keywords_with_colon(ctx);
|
acc.add_nameref_keywords_with_colon(ctx);
|
||||||
}
|
}
|
||||||
|
Qualified::Infer => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,15 +55,13 @@ pub(crate) fn complete_type_path(acc: &mut Completions, ctx: &CompletionContext)
|
||||||
};
|
};
|
||||||
|
|
||||||
match qualified {
|
match qualified {
|
||||||
Qualified::With(PathQualifierCtx { is_infer_qualifier, resolution, .. }) => {
|
Qualified::Infer => ctx
|
||||||
if *is_infer_qualifier {
|
.traits_in_scope()
|
||||||
ctx.traits_in_scope()
|
.0
|
||||||
.0
|
.into_iter()
|
||||||
.into_iter()
|
.flat_map(|it| hir::Trait::from(it).items(ctx.sema.db))
|
||||||
.flat_map(|it| hir::Trait::from(it).items(ctx.sema.db))
|
.for_each(|item| add_assoc_item(acc, item)),
|
||||||
.for_each(|item| add_assoc_item(acc, item));
|
Qualified::With(PathQualifierCtx { resolution, .. }) => {
|
||||||
return;
|
|
||||||
}
|
|
||||||
let resolution = match resolution {
|
let resolution = match resolution {
|
||||||
Some(it) => it,
|
Some(it) => it,
|
||||||
None => return,
|
None => return,
|
||||||
|
|
|
@ -24,13 +24,7 @@ pub(crate) fn complete_use_tree(acc: &mut Completions, ctx: &CompletionContext)
|
||||||
};
|
};
|
||||||
|
|
||||||
match qualified {
|
match qualified {
|
||||||
Qualified::With(PathQualifierCtx {
|
Qualified::With(PathQualifierCtx { path, resolution, is_super_chain, use_tree_parent }) => {
|
||||||
path,
|
|
||||||
resolution,
|
|
||||||
is_super_chain,
|
|
||||||
use_tree_parent,
|
|
||||||
..
|
|
||||||
}) => {
|
|
||||||
if *is_super_chain {
|
if *is_super_chain {
|
||||||
acc.add_keyword(ctx, "super::");
|
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);
|
acc.add_nameref_keywords_with_colon(ctx);
|
||||||
}
|
}
|
||||||
|
Qualified::Infer => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,7 @@ pub(crate) fn complete_vis_path(acc: &mut Completions, ctx: &CompletionContext)
|
||||||
acc.add_keyword(ctx, "super::");
|
acc.add_keyword(ctx, "super::");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Qualified::Absolute => {}
|
Qualified::Absolute | Qualified::Infer => {}
|
||||||
Qualified::No => {
|
Qualified::No => {
|
||||||
if !has_in_token {
|
if !has_in_token {
|
||||||
cov_mark::hit!(kw_completion_in);
|
cov_mark::hit!(kw_completion_in);
|
||||||
|
|
|
@ -150,6 +150,8 @@ pub(super) enum ItemListKind {
|
||||||
pub(super) enum Qualified {
|
pub(super) enum Qualified {
|
||||||
No,
|
No,
|
||||||
With(PathQualifierCtx),
|
With(PathQualifierCtx),
|
||||||
|
/// <_>::
|
||||||
|
Infer,
|
||||||
/// Whether the path is an absolute path
|
/// Whether the path is an absolute path
|
||||||
Absolute,
|
Absolute,
|
||||||
}
|
}
|
||||||
|
@ -163,8 +165,6 @@ pub(crate) struct PathQualifierCtx {
|
||||||
pub(crate) is_super_chain: bool,
|
pub(crate) is_super_chain: bool,
|
||||||
/// Whether the qualifier comes from a use tree parent or not
|
/// Whether the qualifier comes from a use tree parent or not
|
||||||
pub(crate) use_tree_parent: bool,
|
pub(crate) use_tree_parent: bool,
|
||||||
/// <_>
|
|
||||||
pub(crate) is_infer_qualifier: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The state of the pattern we are completing.
|
/// The state of the pattern we are completing.
|
||||||
|
@ -320,13 +320,16 @@ pub(crate) struct CompletionContext<'a> {
|
||||||
pub(super) expected_type: Option<Type>,
|
pub(super) expected_type: Option<Type>,
|
||||||
|
|
||||||
/// The parent function of the cursor position if it exists.
|
/// The parent function of the cursor position if it exists.
|
||||||
|
// FIXME: This probably doesn't belong here
|
||||||
pub(super) function_def: Option<ast::Fn>,
|
pub(super) function_def: Option<ast::Fn>,
|
||||||
/// The parent impl of the cursor position if it exists.
|
/// The parent impl of the cursor position if it exists.
|
||||||
|
// FIXME: This probably doesn't belong here
|
||||||
pub(super) impl_def: Option<ast::Impl>,
|
pub(super) impl_def: Option<ast::Impl>,
|
||||||
/// Are we completing inside a let statement with a missing semicolon?
|
/// Are we completing inside a let statement with a missing semicolon?
|
||||||
// FIXME: This should be part of PathKind::Expr
|
// FIXME: This should be part of PathKind::Expr
|
||||||
pub(super) incomplete_let: bool,
|
pub(super) incomplete_let: bool,
|
||||||
|
|
||||||
|
// FIXME: This shouldn't exist
|
||||||
pub(super) previous_token: Option<SyntaxToken>,
|
pub(super) previous_token: Option<SyntaxToken>,
|
||||||
|
|
||||||
pub(super) ident_ctx: IdentContext,
|
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 {
|
pub(crate) fn previous_token_is(&self, kind: SyntaxKind) -> bool {
|
||||||
self.previous_token.as_ref().map_or(false, |tok| tok.kind() == kind)
|
self.previous_token.as_ref().map_or(false, |tok| tok.kind() == kind)
|
||||||
}
|
}
|
||||||
|
|
|
@ -861,10 +861,6 @@ impl<'a> CompletionContext<'a> {
|
||||||
.and_then(|it| find_node_in_file(original_file, &it))
|
.and_then(|it| find_node_in_file(original_file, &it))
|
||||||
.map(|it| it.parent_path());
|
.map(|it| it.parent_path());
|
||||||
if let Some(path) = 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`
|
// `<_>::$0`
|
||||||
let is_infer_qualifier = path.qualifier().is_none()
|
let is_infer_qualifier = path.qualifier().is_none()
|
||||||
&& matches!(
|
&& matches!(
|
||||||
|
@ -875,13 +871,20 @@ impl<'a> CompletionContext<'a> {
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
path_ctx.qualified = Qualified::With(PathQualifierCtx {
|
path_ctx.qualified = if is_infer_qualifier {
|
||||||
path,
|
Qualified::Infer
|
||||||
resolution: res,
|
} else {
|
||||||
is_super_chain,
|
let res = sema.resolve_path(&path);
|
||||||
use_tree_parent,
|
let is_super_chain =
|
||||||
is_infer_qualifier,
|
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() {
|
} else if let Some(segment) = path.segment() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue