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

Commit 309ecdd

Browse files
committed
internal: NameRefKind classification is not optional
1 parent 12dd810 commit 309ecdd

File tree

13 files changed

+144
-143
lines changed

13 files changed

+144
-143
lines changed

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ pub(crate) fn import_on_the_fly_path(
123123
| PathKind::Type { .. }
124124
| PathKind::Attr { .. }
125125
| PathKind::Derive { .. }
126-
| PathKind::Pat),
126+
| PathKind::Pat { .. }),
127127
qualified,
128128
..
129129
} => (Some(kind), qualified),
@@ -183,7 +183,7 @@ pub(crate) fn import_on_the_fly_pat(
183183
return None;
184184
}
185185
let kind = match pat_ctx {
186-
PatternContext { record_pat: None, .. } => PathKind::Pat,
186+
PatternContext { record_pat: None, .. } => PathKind::Pat { pat_ctx: pat_ctx.clone() },
187187
_ => return None,
188188
};
189189

@@ -229,15 +229,17 @@ fn import_on_the_fly(
229229
PathKind::Expr { .. }
230230
| PathKind::Type { .. }
231231
| PathKind::Item { .. }
232-
| PathKind::Pat,
232+
| PathKind::Pat { .. },
233233
ItemInNs::Macros(mac),
234234
) => mac.is_fn_like(ctx.db),
235235
(PathKind::Item { .. }, _) => true,
236236

237237
(PathKind::Expr { .. }, ItemInNs::Types(_) | ItemInNs::Values(_)) => true,
238238

239-
(PathKind::Pat, ItemInNs::Types(_)) => true,
240-
(PathKind::Pat, ItemInNs::Values(def)) => matches!(def, hir::ModuleDef::Const(_)),
239+
(PathKind::Pat { .. }, ItemInNs::Types(_)) => true,
240+
(PathKind::Pat { .. }, ItemInNs::Values(def)) => {
241+
matches!(def, hir::ModuleDef::Const(_))
242+
}
241243

242244
(PathKind::Type { location }, ItemInNs::Types(ty)) => {
243245
if matches!(location, TypeLocation::TypeBound) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,12 @@ pub(crate) fn complete_trait_impl_name_ref(
9595
NameRefContext {
9696
nameref,
9797
kind:
98-
Some(NameRefKind::Path(
98+
NameRefKind::Path(
9999
path_ctx @ PathCompletionCtx {
100100
kind: PathKind::Item { kind: ItemListKind::TraitImpl },
101101
..
102102
},
103-
)),
103+
),
104104
} if path_ctx.is_trivial_path() => complete_trait_impl(
105105
acc,
106106
ctx,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ pub(crate) fn pattern_path_completion(
107107
ctx: &CompletionContext,
108108
PathCompletionCtx { qualified, kind, .. }: &PathCompletionCtx,
109109
) {
110-
if !matches!(kind, PathKind::Pat) {
110+
if !matches!(kind, PathKind::Pat { .. }) {
111111
return;
112112
}
113113
match qualified {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ pub(crate) fn complete_use_tree(
2020
let (qualified, name_ref, use_tree_parent) = match name_ref_ctx {
2121
NameRefContext {
2222
kind:
23-
Some(NameRefKind::Path(PathCompletionCtx {
23+
NameRefKind::Path(PathCompletionCtx {
2424
kind: PathKind::Use,
2525
qualified,
2626
use_tree_parent,
2727
..
28-
})),
28+
}),
2929
nameref,
3030
..
3131
} => (qualified, nameref, use_tree_parent),

crates/ide-completion/src/context.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ impl PathCompletionCtx {
8585
}
8686

8787
/// The kind of path we are completing right now.
88-
#[derive(Clone, Debug, PartialEq, Eq)]
88+
#[derive(Debug, PartialEq, Eq)]
8989
pub(super) enum PathKind {
9090
Expr {
9191
in_block_expr: bool,
@@ -110,7 +110,9 @@ pub(super) enum PathKind {
110110
Item {
111111
kind: ItemListKind,
112112
},
113-
Pat,
113+
Pat {
114+
pat_ctx: PatternContext,
115+
},
114116
Vis {
115117
has_in_token: bool,
116118
},
@@ -164,7 +166,7 @@ pub(super) enum Qualified {
164166
}
165167

166168
/// The state of the pattern we are completing.
167-
#[derive(Debug)]
169+
#[derive(Debug, Clone, PartialEq, Eq)]
168170
pub(super) struct PatternContext {
169171
pub(super) refutability: PatternRefutability,
170172
pub(super) param_ctx: Option<(ast::ParamList, ast::Param, ParamKind)>,
@@ -208,7 +210,7 @@ pub(super) enum NameKind {
208210
ConstParam,
209211
Enum,
210212
Function,
211-
IdentPat,
213+
IdentPat(PatternContext),
212214
MacroDef,
213215
MacroRules,
214216
/// Fake node
@@ -230,8 +232,7 @@ pub(super) enum NameKind {
230232
pub(super) struct NameRefContext {
231233
/// NameRef syntax in the original file
232234
pub(super) nameref: Option<ast::NameRef>,
233-
// FIXME: This shouldn't be an Option
234-
pub(super) kind: Option<NameRefKind>,
235+
pub(super) kind: NameRefKind,
235236
}
236237

237238
/// The kind of the NameRef we are completing.
@@ -243,6 +244,7 @@ pub(super) enum NameRefKind {
243244
Keyword(ast::Item),
244245
/// The record expression this nameref is a field of
245246
RecordExpr(ast::RecordExpr),
247+
Pattern(PatternContext),
246248
}
247249

248250
/// The identifier we are currently completing.
@@ -330,7 +332,6 @@ pub(crate) struct CompletionContext<'a> {
330332

331333
// We might wanna split these out of CompletionContext
332334
pub(super) ident_ctx: IdentContext,
333-
pub(super) pattern_ctx: Option<PatternContext>,
334335
pub(super) qualifier_ctx: QualifierCtx,
335336

336337
pub(super) locals: FxHashMap<Name, Local>,
@@ -505,7 +506,6 @@ impl<'a> CompletionContext<'a> {
505506
previous_token: None,
506507
// dummy value, will be overwritten
507508
ident_ctx: IdentContext::UnexpandedAttrTT { fake_attribute_under_caret: None },
508-
pattern_ctx: None,
509509
qualifier_ctx: Default::default(),
510510
locals,
511511
};

0 commit comments

Comments
 (0)