mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-28 14:03:35 +00:00
Inline PathQualifierCtx
This commit is contained in:
parent
d6f161ffa9
commit
85b68b1f7d
10 changed files with 39 additions and 48 deletions
|
@ -18,9 +18,7 @@ use syntax::{
|
|||
|
||||
use crate::{
|
||||
completions::module_or_attr,
|
||||
context::{
|
||||
CompletionContext, IdentContext, PathCompletionCtx, PathKind, PathQualifierCtx, Qualified,
|
||||
},
|
||||
context::{CompletionContext, IdentContext, PathCompletionCtx, PathKind, Qualified},
|
||||
item::CompletionItem,
|
||||
Completions,
|
||||
};
|
||||
|
@ -84,7 +82,7 @@ pub(crate) fn complete_attribute(acc: &mut Completions, ctx: &CompletionContext)
|
|||
};
|
||||
|
||||
match qualified {
|
||||
Qualified::With(PathQualifierCtx { resolution, is_super_chain, .. }) => {
|
||||
Qualified::With { resolution, is_super_chain, .. } => {
|
||||
if *is_super_chain {
|
||||
acc.add_keyword(ctx, "super::");
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ use itertools::Itertools;
|
|||
use syntax::SmolStr;
|
||||
|
||||
use crate::{
|
||||
context::{CompletionContext, PathCompletionCtx, PathKind, PathQualifierCtx, Qualified},
|
||||
context::{CompletionContext, PathCompletionCtx, PathKind, Qualified},
|
||||
item::CompletionItem,
|
||||
Completions,
|
||||
};
|
||||
|
@ -21,7 +21,7 @@ pub(crate) fn complete_derive(acc: &mut Completions, ctx: &CompletionContext) {
|
|||
let core = ctx.famous_defs().core();
|
||||
|
||||
match qualified {
|
||||
Qualified::With(PathQualifierCtx { resolution, is_super_chain, .. }) => {
|
||||
Qualified::With { resolution, is_super_chain, .. } => {
|
||||
if *is_super_chain {
|
||||
acc.add_keyword(ctx, "super::");
|
||||
}
|
||||
|
|
|
@ -4,9 +4,7 @@ use hir::ScopeDef;
|
|||
use ide_db::FxHashSet;
|
||||
|
||||
use crate::{
|
||||
context::{
|
||||
NameRefContext, NameRefKind, PathCompletionCtx, PathKind, PathQualifierCtx, Qualified,
|
||||
},
|
||||
context::{NameRefContext, NameRefKind, PathCompletionCtx, PathKind, Qualified},
|
||||
CompletionContext, Completions,
|
||||
};
|
||||
|
||||
|
@ -67,7 +65,7 @@ pub(crate) fn complete_expr_path(acc: &mut Completions, ctx: &CompletionContext)
|
|||
.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, .. }) => {
|
||||
Qualified::With { resolution, .. } => {
|
||||
let resolution = match resolution {
|
||||
Some(it) => it,
|
||||
None => return,
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
use crate::{
|
||||
completions::module_or_fn_macro,
|
||||
context::{ItemListKind, PathCompletionCtx, PathKind, PathQualifierCtx, Qualified},
|
||||
context::{ItemListKind, PathCompletionCtx, PathKind, Qualified},
|
||||
CompletionContext, Completions,
|
||||
};
|
||||
|
||||
|
@ -44,7 +44,7 @@ pub(crate) fn complete_item_list(acc: &mut Completions, ctx: &CompletionContext)
|
|||
}
|
||||
|
||||
match qualified {
|
||||
Qualified::With(PathQualifierCtx { resolution, is_super_chain, .. }) => {
|
||||
Qualified::With { resolution, is_super_chain, .. } => {
|
||||
if let Some(hir::PathResolution::Def(hir::ModuleDef::Module(module))) = resolution {
|
||||
for (name, def) in module.scope(ctx.db, Some(ctx.module)) {
|
||||
if let Some(def) = module_or_fn_macro(ctx.db, def) {
|
||||
|
|
|
@ -5,7 +5,7 @@ use ide_db::FxHashSet;
|
|||
use syntax::ast::Pat;
|
||||
|
||||
use crate::{
|
||||
context::{PathCompletionCtx, PathQualifierCtx, PatternRefutability, Qualified},
|
||||
context::{PathCompletionCtx, PatternRefutability, Qualified},
|
||||
CompletionContext, Completions,
|
||||
};
|
||||
|
||||
|
@ -114,7 +114,7 @@ fn pattern_path_completion(
|
|||
PathCompletionCtx { qualified, .. }: &PathCompletionCtx,
|
||||
) {
|
||||
match qualified {
|
||||
Qualified::With(PathQualifierCtx { resolution, is_super_chain, .. }) => {
|
||||
Qualified::With { resolution, is_super_chain, .. } => {
|
||||
if *is_super_chain {
|
||||
acc.add_keyword(ctx, "super::");
|
||||
}
|
||||
|
|
|
@ -5,10 +5,7 @@ use ide_db::FxHashSet;
|
|||
use syntax::{ast, AstNode};
|
||||
|
||||
use crate::{
|
||||
context::{
|
||||
PathCompletionCtx, PathKind, PathQualifierCtx, Qualified, TypeAscriptionTarget,
|
||||
TypeLocation,
|
||||
},
|
||||
context::{PathCompletionCtx, PathKind, Qualified, TypeAscriptionTarget, TypeLocation},
|
||||
render::render_type_inference,
|
||||
CompletionContext, Completions,
|
||||
};
|
||||
|
@ -61,7 +58,7 @@ pub(crate) fn complete_type_path(acc: &mut Completions, ctx: &CompletionContext)
|
|||
.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, .. }) => {
|
||||
Qualified::With { resolution, .. } => {
|
||||
let resolution = match resolution {
|
||||
Some(it) => it,
|
||||
None => return,
|
||||
|
|
|
@ -6,25 +6,30 @@ use syntax::{ast, AstNode};
|
|||
|
||||
use crate::{
|
||||
context::{
|
||||
CompletionContext, NameRefContext, NameRefKind, PathCompletionCtx, PathKind,
|
||||
PathQualifierCtx, Qualified,
|
||||
CompletionContext, NameRefContext, NameRefKind, PathCompletionCtx, PathKind, Qualified,
|
||||
},
|
||||
item::Builder,
|
||||
CompletionItem, CompletionItemKind, CompletionRelevance, Completions,
|
||||
};
|
||||
|
||||
pub(crate) fn complete_use_tree(acc: &mut Completions, ctx: &CompletionContext) {
|
||||
let (qualified, name_ref) = match ctx.nameref_ctx() {
|
||||
let (qualified, name_ref, use_tree_parent) = match ctx.nameref_ctx() {
|
||||
Some(NameRefContext {
|
||||
kind: Some(NameRefKind::Path(PathCompletionCtx { kind: PathKind::Use, qualified, .. })),
|
||||
kind:
|
||||
Some(NameRefKind::Path(PathCompletionCtx {
|
||||
kind: PathKind::Use,
|
||||
qualified,
|
||||
use_tree_parent,
|
||||
..
|
||||
})),
|
||||
nameref,
|
||||
..
|
||||
}) => (qualified, nameref),
|
||||
}) => (qualified, nameref, use_tree_parent),
|
||||
_ => return,
|
||||
};
|
||||
|
||||
match qualified {
|
||||
Qualified::With(PathQualifierCtx { path, resolution, is_super_chain, use_tree_parent }) => {
|
||||
Qualified::With { path, resolution, is_super_chain } => {
|
||||
if *is_super_chain {
|
||||
acc.add_keyword(ctx, "super::");
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
use hir::ScopeDef;
|
||||
|
||||
use crate::{
|
||||
context::{CompletionContext, PathCompletionCtx, PathKind, PathQualifierCtx, Qualified},
|
||||
context::{CompletionContext, PathCompletionCtx, PathKind, Qualified},
|
||||
Completions,
|
||||
};
|
||||
|
||||
|
@ -16,7 +16,7 @@ pub(crate) fn complete_vis_path(acc: &mut Completions, ctx: &CompletionContext)
|
|||
};
|
||||
|
||||
match qualified {
|
||||
Qualified::With(PathQualifierCtx { resolution, is_super_chain, .. }) => {
|
||||
Qualified::With { resolution, is_super_chain, .. } => {
|
||||
// Try completing next child module of the path that is still a parent of the current module
|
||||
if let Some(hir::PathResolution::Def(hir::ModuleDef::Module(module))) = resolution {
|
||||
let next_towards_current = ctx
|
||||
|
|
|
@ -64,6 +64,8 @@ pub(crate) struct PathCompletionCtx {
|
|||
pub(super) kind: PathKind,
|
||||
/// Whether the path segment has type args or not.
|
||||
pub(super) has_type_args: bool,
|
||||
/// Whether the qualifier comes from a use tree parent or not
|
||||
pub(crate) use_tree_parent: bool,
|
||||
}
|
||||
|
||||
impl PathCompletionCtx {
|
||||
|
@ -149,24 +151,18 @@ pub(super) enum ItemListKind {
|
|||
#[derive(Debug)]
|
||||
pub(super) enum Qualified {
|
||||
No,
|
||||
With(PathQualifierCtx),
|
||||
With {
|
||||
path: ast::Path,
|
||||
resolution: Option<PathResolution>,
|
||||
/// Whether this path consists solely of `super` segments
|
||||
is_super_chain: bool,
|
||||
},
|
||||
/// <_>::
|
||||
Infer,
|
||||
/// Whether the path is an absolute path
|
||||
Absolute,
|
||||
}
|
||||
|
||||
/// The path qualifier state of the path we are completing.
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct PathQualifierCtx {
|
||||
pub(crate) path: ast::Path,
|
||||
pub(crate) resolution: Option<PathResolution>,
|
||||
/// Whether this path consists solely of `super` segments
|
||||
pub(crate) is_super_chain: bool,
|
||||
/// Whether the qualifier comes from a use tree parent or not
|
||||
pub(crate) use_tree_parent: bool,
|
||||
}
|
||||
|
||||
/// The state of the pattern we are completing.
|
||||
#[derive(Debug)]
|
||||
pub(super) struct PatternContext {
|
||||
|
@ -410,7 +406,7 @@ impl<'a> CompletionContext<'a> {
|
|||
|
||||
pub(crate) fn path_qual(&self) -> Option<&ast::Path> {
|
||||
self.path_context().and_then(|it| match &it.qualified {
|
||||
Qualified::With(it) => Some(&it.path),
|
||||
Qualified::With { path, .. } => Some(path),
|
||||
_ => None,
|
||||
})
|
||||
}
|
||||
|
|
|
@ -13,8 +13,8 @@ use syntax::{
|
|||
use crate::context::{
|
||||
CompletionContext, DotAccess, DotAccessKind, IdentContext, ItemListKind, LifetimeContext,
|
||||
LifetimeKind, NameContext, NameKind, NameRefContext, NameRefKind, ParamKind, PathCompletionCtx,
|
||||
PathKind, PathQualifierCtx, PatternContext, PatternRefutability, Qualified, QualifierCtx,
|
||||
TypeAscriptionTarget, TypeLocation, COMPLETION_MARKER,
|
||||
PathKind, PatternContext, PatternRefutability, Qualified, QualifierCtx, TypeAscriptionTarget,
|
||||
TypeLocation, COMPLETION_MARKER,
|
||||
};
|
||||
|
||||
impl<'a> CompletionContext<'a> {
|
||||
|
@ -589,6 +589,7 @@ impl<'a> CompletionContext<'a> {
|
|||
parent: path.parent_path(),
|
||||
kind: PathKind::Item { kind: ItemListKind::SourceFile },
|
||||
has_type_args: false,
|
||||
use_tree_parent: false,
|
||||
};
|
||||
|
||||
let is_in_block = |it: &SyntaxNode| {
|
||||
|
@ -853,6 +854,7 @@ impl<'a> CompletionContext<'a> {
|
|||
|
||||
// calculate the qualifier context
|
||||
if let Some((path, use_tree_parent)) = path_or_use_tree_qualifier(&path) {
|
||||
path_ctx.use_tree_parent = use_tree_parent;
|
||||
if !use_tree_parent && segment.coloncolon_token().is_some() {
|
||||
path_ctx.qualified = Qualified::Absolute;
|
||||
} else {
|
||||
|
@ -878,12 +880,7 @@ impl<'a> CompletionContext<'a> {
|
|||
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,
|
||||
})
|
||||
Qualified::With { path, resolution: res, is_super_chain }
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue