Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit d6f161f

Browse files
committed
internal: Collapse lift is_infer_qualifier into Qualified variant
1 parent 2f2ea77 commit d6f161f

File tree

10 files changed

+41
-40
lines changed

10 files changed

+41
-40
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ pub(crate) fn complete_attribute(acc: &mut Completions, ctx: &CompletionContext)
112112
});
113113
acc.add_nameref_keywords_with_colon(ctx);
114114
}
115+
Qualified::Infer => {}
115116
}
116117

117118
let attributes = annotated_item_kind.and_then(|kind| {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ pub(crate) fn complete_derive(acc: &mut Completions, ctx: &CompletionContext) {
101101
});
102102
acc.add_nameref_keywords_with_colon(ctx);
103103
}
104+
Qualified::Infer => {}
104105
}
105106
}
106107

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,13 @@ pub(crate) fn complete_expr_path(acc: &mut Completions, ctx: &CompletionContext)
6161
};
6262

6363
match qualified {
64-
Qualified::With(PathQualifierCtx { is_infer_qualifier, resolution, .. }) => {
65-
if *is_infer_qualifier {
66-
ctx.traits_in_scope()
67-
.0
68-
.into_iter()
69-
.flat_map(|it| hir::Trait::from(it).items(ctx.sema.db))
70-
.for_each(|item| add_assoc_item(acc, ctx, item));
71-
return;
72-
}
64+
Qualified::Infer => ctx
65+
.traits_in_scope()
66+
.0
67+
.into_iter()
68+
.flat_map(|it| hir::Trait::from(it).items(ctx.sema.db))
69+
.for_each(|item| add_assoc_item(acc, ctx, item)),
70+
Qualified::With(PathQualifierCtx { resolution, .. }) => {
7371
let resolution = match resolution {
7472
Some(it) => it,
7573
None => return,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ pub(crate) fn complete_item_list(acc: &mut Completions, ctx: &CompletionContext)
6666
});
6767
acc.add_nameref_keywords_with_colon(ctx);
6868
}
69-
Qualified::No => {}
69+
Qualified::Infer | Qualified::No => {}
7070
}
7171
}
7272

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,5 +208,6 @@ fn pattern_path_completion(
208208

209209
acc.add_nameref_keywords_with_colon(ctx);
210210
}
211+
Qualified::Infer => {}
211212
}
212213
}

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,13 @@ pub(crate) fn complete_type_path(acc: &mut Completions, ctx: &CompletionContext)
5555
};
5656

5757
match qualified {
58-
Qualified::With(PathQualifierCtx { is_infer_qualifier, resolution, .. }) => {
59-
if *is_infer_qualifier {
60-
ctx.traits_in_scope()
61-
.0
62-
.into_iter()
63-
.flat_map(|it| hir::Trait::from(it).items(ctx.sema.db))
64-
.for_each(|item| add_assoc_item(acc, item));
65-
return;
66-
}
58+
Qualified::Infer => ctx
59+
.traits_in_scope()
60+
.0
61+
.into_iter()
62+
.flat_map(|it| hir::Trait::from(it).items(ctx.sema.db))
63+
.for_each(|item| add_assoc_item(acc, item)),
64+
Qualified::With(PathQualifierCtx { resolution, .. }) => {
6765
let resolution = match resolution {
6866
Some(it) => it,
6967
None => return,

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,7 @@ pub(crate) fn complete_use_tree(acc: &mut Completions, ctx: &CompletionContext)
2424
};
2525

2626
match qualified {
27-
Qualified::With(PathQualifierCtx {
28-
path,
29-
resolution,
30-
is_super_chain,
31-
use_tree_parent,
32-
..
33-
}) => {
27+
Qualified::With(PathQualifierCtx { path, resolution, is_super_chain, use_tree_parent }) => {
3428
if *is_super_chain {
3529
acc.add_keyword(ctx, "super::");
3630
}
@@ -136,5 +130,6 @@ pub(crate) fn complete_use_tree(acc: &mut Completions, ctx: &CompletionContext)
136130
});
137131
acc.add_nameref_keywords_with_colon(ctx);
138132
}
133+
Qualified::Infer => {}
139134
}
140135
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub(crate) fn complete_vis_path(acc: &mut Completions, ctx: &CompletionContext)
3737
acc.add_keyword(ctx, "super::");
3838
}
3939
}
40-
Qualified::Absolute => {}
40+
Qualified::Absolute | Qualified::Infer => {}
4141
Qualified::No => {
4242
if !has_in_token {
4343
cov_mark::hit!(kw_completion_in);

crates/ide-completion/src/context.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ pub(super) enum ItemListKind {
150150
pub(super) enum Qualified {
151151
No,
152152
With(PathQualifierCtx),
153+
/// <_>::
154+
Infer,
153155
/// Whether the path is an absolute path
154156
Absolute,
155157
}
@@ -163,8 +165,6 @@ pub(crate) struct PathQualifierCtx {
163165
pub(crate) is_super_chain: bool,
164166
/// Whether the qualifier comes from a use tree parent or not
165167
pub(crate) use_tree_parent: bool,
166-
/// <_>
167-
pub(crate) is_infer_qualifier: bool,
168168
}
169169

170170
/// The state of the pattern we are completing.
@@ -320,13 +320,16 @@ pub(crate) struct CompletionContext<'a> {
320320
pub(super) expected_type: Option<Type>,
321321

322322
/// The parent function of the cursor position if it exists.
323+
// FIXME: This probably doesn't belong here
323324
pub(super) function_def: Option<ast::Fn>,
324325
/// The parent impl of the cursor position if it exists.
326+
// FIXME: This probably doesn't belong here
325327
pub(super) impl_def: Option<ast::Impl>,
326328
/// Are we completing inside a let statement with a missing semicolon?
327329
// FIXME: This should be part of PathKind::Expr
328330
pub(super) incomplete_let: bool,
329331

332+
// FIXME: This shouldn't exist
330333
pub(super) previous_token: Option<SyntaxToken>,
331334

332335
pub(super) ident_ctx: IdentContext,
@@ -354,6 +357,7 @@ impl<'a> CompletionContext<'a> {
354357
}
355358
}
356359

360+
// FIXME: This shouldn't exist
357361
pub(crate) fn previous_token_is(&self, kind: SyntaxKind) -> bool {
358362
self.previous_token.as_ref().map_or(false, |tok| tok.kind() == kind)
359363
}

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

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -861,10 +861,6 @@ impl<'a> CompletionContext<'a> {
861861
.and_then(|it| find_node_in_file(original_file, &it))
862862
.map(|it| it.parent_path());
863863
if let Some(path) = path {
864-
let res = sema.resolve_path(&path);
865-
let is_super_chain = iter::successors(Some(path.clone()), |p| p.qualifier())
866-
.all(|p| p.segment().and_then(|s| s.super_token()).is_some());
867-
868864
// `<_>::$0`
869865
let is_infer_qualifier = path.qualifier().is_none()
870866
&& matches!(
@@ -875,13 +871,20 @@ impl<'a> CompletionContext<'a> {
875871
})
876872
);
877873

878-
path_ctx.qualified = Qualified::With(PathQualifierCtx {
879-
path,
880-
resolution: res,
881-
is_super_chain,
882-
use_tree_parent,
883-
is_infer_qualifier,
884-
})
874+
path_ctx.qualified = if is_infer_qualifier {
875+
Qualified::Infer
876+
} else {
877+
let res = sema.resolve_path(&path);
878+
let is_super_chain =
879+
iter::successors(Some(path.clone()), |p| p.qualifier())
880+
.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+
})
887+
}
885888
};
886889
}
887890
} else if let Some(segment) = path.segment() {

0 commit comments

Comments
 (0)