Skip to content

Commit 85b68b1

Browse files
committed
Inline PathQualifierCtx
1 parent d6f161f commit 85b68b1

File tree

10 files changed

+39
-48
lines changed

10 files changed

+39
-48
lines changed

crates/ide-completion/src/completions/attribute.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ use syntax::{
1818

1919
use crate::{
2020
completions::module_or_attr,
21-
context::{
22-
CompletionContext, IdentContext, PathCompletionCtx, PathKind, PathQualifierCtx, Qualified,
23-
},
21+
context::{CompletionContext, IdentContext, PathCompletionCtx, PathKind, Qualified},
2422
item::CompletionItem,
2523
Completions,
2624
};
@@ -84,7 +82,7 @@ pub(crate) fn complete_attribute(acc: &mut Completions, ctx: &CompletionContext)
8482
};
8583

8684
match qualified {
87-
Qualified::With(PathQualifierCtx { resolution, is_super_chain, .. }) => {
85+
Qualified::With { resolution, is_super_chain, .. } => {
8886
if *is_super_chain {
8987
acc.add_keyword(ctx, "super::");
9088
}

crates/ide-completion/src/completions/attribute/derive.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use itertools::Itertools;
55
use syntax::SmolStr;
66

77
use crate::{
8-
context::{CompletionContext, PathCompletionCtx, PathKind, PathQualifierCtx, Qualified},
8+
context::{CompletionContext, PathCompletionCtx, PathKind, Qualified},
99
item::CompletionItem,
1010
Completions,
1111
};
@@ -21,7 +21,7 @@ pub(crate) fn complete_derive(acc: &mut Completions, ctx: &CompletionContext) {
2121
let core = ctx.famous_defs().core();
2222

2323
match qualified {
24-
Qualified::With(PathQualifierCtx { resolution, is_super_chain, .. }) => {
24+
Qualified::With { resolution, is_super_chain, .. } => {
2525
if *is_super_chain {
2626
acc.add_keyword(ctx, "super::");
2727
}

crates/ide-completion/src/completions/expr.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ use hir::ScopeDef;
44
use ide_db::FxHashSet;
55

66
use crate::{
7-
context::{
8-
NameRefContext, NameRefKind, PathCompletionCtx, PathKind, PathQualifierCtx, Qualified,
9-
},
7+
context::{NameRefContext, NameRefKind, PathCompletionCtx, PathKind, Qualified},
108
CompletionContext, Completions,
119
};
1210

@@ -67,7 +65,7 @@ pub(crate) fn complete_expr_path(acc: &mut Completions, ctx: &CompletionContext)
6765
.into_iter()
6866
.flat_map(|it| hir::Trait::from(it).items(ctx.sema.db))
6967
.for_each(|item| add_assoc_item(acc, ctx, item)),
70-
Qualified::With(PathQualifierCtx { resolution, .. }) => {
68+
Qualified::With { resolution, .. } => {
7169
let resolution = match resolution {
7270
Some(it) => it,
7371
None => return,

crates/ide-completion/src/completions/item_list.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use crate::{
44
completions::module_or_fn_macro,
5-
context::{ItemListKind, PathCompletionCtx, PathKind, PathQualifierCtx, Qualified},
5+
context::{ItemListKind, PathCompletionCtx, PathKind, Qualified},
66
CompletionContext, Completions,
77
};
88

@@ -44,7 +44,7 @@ pub(crate) fn complete_item_list(acc: &mut Completions, ctx: &CompletionContext)
4444
}
4545

4646
match qualified {
47-
Qualified::With(PathQualifierCtx { resolution, is_super_chain, .. }) => {
47+
Qualified::With { resolution, is_super_chain, .. } => {
4848
if let Some(hir::PathResolution::Def(hir::ModuleDef::Module(module))) = resolution {
4949
for (name, def) in module.scope(ctx.db, Some(ctx.module)) {
5050
if let Some(def) = module_or_fn_macro(ctx.db, def) {

crates/ide-completion/src/completions/pattern.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use ide_db::FxHashSet;
55
use syntax::ast::Pat;
66

77
use crate::{
8-
context::{PathCompletionCtx, PathQualifierCtx, PatternRefutability, Qualified},
8+
context::{PathCompletionCtx, PatternRefutability, Qualified},
99
CompletionContext, Completions,
1010
};
1111

@@ -114,7 +114,7 @@ fn pattern_path_completion(
114114
PathCompletionCtx { qualified, .. }: &PathCompletionCtx,
115115
) {
116116
match qualified {
117-
Qualified::With(PathQualifierCtx { resolution, is_super_chain, .. }) => {
117+
Qualified::With { resolution, is_super_chain, .. } => {
118118
if *is_super_chain {
119119
acc.add_keyword(ctx, "super::");
120120
}

crates/ide-completion/src/completions/type.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@ use ide_db::FxHashSet;
55
use syntax::{ast, AstNode};
66

77
use crate::{
8-
context::{
9-
PathCompletionCtx, PathKind, PathQualifierCtx, Qualified, TypeAscriptionTarget,
10-
TypeLocation,
11-
},
8+
context::{PathCompletionCtx, PathKind, Qualified, TypeAscriptionTarget, TypeLocation},
129
render::render_type_inference,
1310
CompletionContext, Completions,
1411
};
@@ -61,7 +58,7 @@ pub(crate) fn complete_type_path(acc: &mut Completions, ctx: &CompletionContext)
6158
.into_iter()
6259
.flat_map(|it| hir::Trait::from(it).items(ctx.sema.db))
6360
.for_each(|item| add_assoc_item(acc, item)),
64-
Qualified::With(PathQualifierCtx { resolution, .. }) => {
61+
Qualified::With { resolution, .. } => {
6562
let resolution = match resolution {
6663
Some(it) => it,
6764
None => return,

crates/ide-completion/src/completions/use_.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,30 @@ use syntax::{ast, AstNode};
66

77
use crate::{
88
context::{
9-
CompletionContext, NameRefContext, NameRefKind, PathCompletionCtx, PathKind,
10-
PathQualifierCtx, Qualified,
9+
CompletionContext, NameRefContext, NameRefKind, PathCompletionCtx, PathKind, Qualified,
1110
},
1211
item::Builder,
1312
CompletionItem, CompletionItemKind, CompletionRelevance, Completions,
1413
};
1514

1615
pub(crate) fn complete_use_tree(acc: &mut Completions, ctx: &CompletionContext) {
17-
let (qualified, name_ref) = match ctx.nameref_ctx() {
16+
let (qualified, name_ref, use_tree_parent) = match ctx.nameref_ctx() {
1817
Some(NameRefContext {
19-
kind: Some(NameRefKind::Path(PathCompletionCtx { kind: PathKind::Use, qualified, .. })),
18+
kind:
19+
Some(NameRefKind::Path(PathCompletionCtx {
20+
kind: PathKind::Use,
21+
qualified,
22+
use_tree_parent,
23+
..
24+
})),
2025
nameref,
2126
..
22-
}) => (qualified, nameref),
27+
}) => (qualified, nameref, use_tree_parent),
2328
_ => return,
2429
};
2530

2631
match qualified {
27-
Qualified::With(PathQualifierCtx { path, resolution, is_super_chain, use_tree_parent }) => {
32+
Qualified::With { path, resolution, is_super_chain } => {
2833
if *is_super_chain {
2934
acc.add_keyword(ctx, "super::");
3035
}

crates/ide-completion/src/completions/vis.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use hir::ScopeDef;
44

55
use crate::{
6-
context::{CompletionContext, PathCompletionCtx, PathKind, PathQualifierCtx, Qualified},
6+
context::{CompletionContext, PathCompletionCtx, PathKind, Qualified},
77
Completions,
88
};
99

@@ -16,7 +16,7 @@ pub(crate) fn complete_vis_path(acc: &mut Completions, ctx: &CompletionContext)
1616
};
1717

1818
match qualified {
19-
Qualified::With(PathQualifierCtx { resolution, is_super_chain, .. }) => {
19+
Qualified::With { resolution, is_super_chain, .. } => {
2020
// Try completing next child module of the path that is still a parent of the current module
2121
if let Some(hir::PathResolution::Def(hir::ModuleDef::Module(module))) = resolution {
2222
let next_towards_current = ctx

crates/ide-completion/src/context.rs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ pub(crate) struct PathCompletionCtx {
6464
pub(super) kind: PathKind,
6565
/// Whether the path segment has type args or not.
6666
pub(super) has_type_args: bool,
67+
/// Whether the qualifier comes from a use tree parent or not
68+
pub(crate) use_tree_parent: bool,
6769
}
6870

6971
impl PathCompletionCtx {
@@ -149,24 +151,18 @@ pub(super) enum ItemListKind {
149151
#[derive(Debug)]
150152
pub(super) enum Qualified {
151153
No,
152-
With(PathQualifierCtx),
154+
With {
155+
path: ast::Path,
156+
resolution: Option<PathResolution>,
157+
/// Whether this path consists solely of `super` segments
158+
is_super_chain: bool,
159+
},
153160
/// <_>::
154161
Infer,
155162
/// Whether the path is an absolute path
156163
Absolute,
157164
}
158165

159-
/// The path qualifier state of the path we are completing.
160-
#[derive(Debug)]
161-
pub(crate) struct PathQualifierCtx {
162-
pub(crate) path: ast::Path,
163-
pub(crate) resolution: Option<PathResolution>,
164-
/// Whether this path consists solely of `super` segments
165-
pub(crate) is_super_chain: bool,
166-
/// Whether the qualifier comes from a use tree parent or not
167-
pub(crate) use_tree_parent: bool,
168-
}
169-
170166
/// The state of the pattern we are completing.
171167
#[derive(Debug)]
172168
pub(super) struct PatternContext {
@@ -410,7 +406,7 @@ impl<'a> CompletionContext<'a> {
410406

411407
pub(crate) fn path_qual(&self) -> Option<&ast::Path> {
412408
self.path_context().and_then(|it| match &it.qualified {
413-
Qualified::With(it) => Some(&it.path),
409+
Qualified::With { path, .. } => Some(path),
414410
_ => None,
415411
})
416412
}

crates/ide-completion/src/context/analysis.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ use syntax::{
1313
use crate::context::{
1414
CompletionContext, DotAccess, DotAccessKind, IdentContext, ItemListKind, LifetimeContext,
1515
LifetimeKind, NameContext, NameKind, NameRefContext, NameRefKind, ParamKind, PathCompletionCtx,
16-
PathKind, PathQualifierCtx, PatternContext, PatternRefutability, Qualified, QualifierCtx,
17-
TypeAscriptionTarget, TypeLocation, COMPLETION_MARKER,
16+
PathKind, PatternContext, PatternRefutability, Qualified, QualifierCtx, TypeAscriptionTarget,
17+
TypeLocation, COMPLETION_MARKER,
1818
};
1919

2020
impl<'a> CompletionContext<'a> {
@@ -589,6 +589,7 @@ impl<'a> CompletionContext<'a> {
589589
parent: path.parent_path(),
590590
kind: PathKind::Item { kind: ItemListKind::SourceFile },
591591
has_type_args: false,
592+
use_tree_parent: false,
592593
};
593594

594595
let is_in_block = |it: &SyntaxNode| {
@@ -853,6 +854,7 @@ impl<'a> CompletionContext<'a> {
853854

854855
// calculate the qualifier context
855856
if let Some((path, use_tree_parent)) = path_or_use_tree_qualifier(&path) {
857+
path_ctx.use_tree_parent = use_tree_parent;
856858
if !use_tree_parent && segment.coloncolon_token().is_some() {
857859
path_ctx.qualified = Qualified::Absolute;
858860
} else {
@@ -878,12 +880,7 @@ impl<'a> CompletionContext<'a> {
878880
let is_super_chain =
879881
iter::successors(Some(path.clone()), |p| p.qualifier())
880882
.all(|p| p.segment().and_then(|s| s.super_token()).is_some());
881-
Qualified::With(PathQualifierCtx {
882-
path,
883-
resolution: res,
884-
is_super_chain,
885-
use_tree_parent,
886-
})
883+
Qualified::With { path, resolution: res, is_super_chain }
887884
}
888885
};
889886
}

0 commit comments

Comments
 (0)