Skip to content

Commit 616796a

Browse files
committed
Auto merge of rust-lang#12173 - Veykril:completion-rev, r=Veykril
internal: completion PathKind is not optional
2 parents dd3f5e0 + 57a9915 commit 616796a

File tree

12 files changed

+40
-33
lines changed

12 files changed

+40
-33
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ pub(crate) fn complete_known_attribute_input(
7171
pub(crate) fn complete_attribute(acc: &mut Completions, ctx: &CompletionContext) {
7272
let (is_absolute_path, qualifier, is_inner, annotated_item_kind) = match ctx.path_context {
7373
Some(PathCompletionCtx {
74-
kind: Some(PathKind::Attr { kind, annotated_item_kind }),
74+
kind: PathKind::Attr { kind, annotated_item_kind },
7575
is_absolute_path,
7676
ref qualifier,
7777
..

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

+1-4
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@ use crate::{
1313
pub(crate) fn complete_derive(acc: &mut Completions, ctx: &CompletionContext) {
1414
let (qualifier, is_absolute_path) = match ctx.path_context {
1515
Some(PathCompletionCtx {
16-
kind: Some(PathKind::Derive),
17-
ref qualifier,
18-
is_absolute_path,
19-
..
16+
kind: PathKind::Derive, ref qualifier, is_absolute_path, ..
2017
}) => (qualifier, is_absolute_path),
2118
_ => return,
2219
};

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

+14-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
33
use ide_db::FxHashSet;
44

5-
use crate::{context::CompletionContext, patterns::ImmediateLocation, Completions};
5+
use crate::{
6+
context::{CompletionContext, PathCompletionCtx, PathKind},
7+
patterns::ImmediateLocation,
8+
Completions,
9+
};
610

711
/// Complete dot accesses, i.e. fields or methods.
812
pub(crate) fn complete_dot(acc: &mut Completions, ctx: &CompletionContext) {
@@ -34,9 +38,16 @@ fn complete_undotted_self(acc: &mut Completions, ctx: &CompletionContext) {
3438
if !ctx.config.enable_self_on_the_fly {
3539
return;
3640
}
37-
if ctx.is_non_trivial_path() || ctx.is_path_disallowed() || !ctx.expects_expression() {
38-
return;
41+
match ctx.path_context {
42+
Some(PathCompletionCtx {
43+
is_absolute_path: false,
44+
qualifier: None,
45+
kind: PathKind::Expr,
46+
..
47+
}) if !ctx.is_path_disallowed() => {}
48+
_ => return,
3949
}
50+
4051
if let Some(func) = ctx.function_def.as_ref().and_then(|fn_| ctx.sema.to_def(fn_)) {
4152
if let Some(self_) = func.self_param(ctx.db) {
4253
let ty = self_.ty(ctx.db);

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ pub(crate) fn complete_expr_path(acc: &mut Completions, ctx: &CompletionContext)
1515
}
1616

1717
let (&is_absolute_path, qualifier) = match &ctx.path_context {
18-
Some(PathCompletionCtx {
19-
kind: Some(PathKind::Expr), is_absolute_path, qualifier, ..
20-
}) => (is_absolute_path, qualifier),
18+
Some(PathCompletionCtx { kind: PathKind::Expr, is_absolute_path, qualifier, .. }) => {
19+
(is_absolute_path, qualifier)
20+
}
2121
_ => return,
2222
};
2323

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ pub(crate) fn complete_item_list(acc: &mut Completions, ctx: &CompletionContext)
1313
}
1414

1515
let (&is_absolute_path, qualifier) = match &ctx.path_context {
16-
Some(PathCompletionCtx {
17-
kind: Some(PathKind::Item), is_absolute_path, qualifier, ..
18-
}) => (is_absolute_path, qualifier),
16+
Some(PathCompletionCtx { kind: PathKind::Item, is_absolute_path, qualifier, .. }) => {
17+
(is_absolute_path, qualifier)
18+
}
1919
_ => return,
2020
};
2121

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ pub(crate) fn complete_type_path(acc: &mut Completions, ctx: &CompletionContext)
1717
}
1818

1919
let (&is_absolute_path, qualifier) = match &ctx.path_context {
20-
Some(PathCompletionCtx {
21-
kind: Some(PathKind::Type), is_absolute_path, qualifier, ..
22-
}) => (is_absolute_path, qualifier),
20+
Some(PathCompletionCtx { kind: PathKind::Type, is_absolute_path, qualifier, .. }) => {
21+
(is_absolute_path, qualifier)
22+
}
2323
_ => return,
2424
};
2525

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ use crate::{
1212

1313
pub(crate) fn complete_use_tree(acc: &mut Completions, ctx: &CompletionContext) {
1414
let (&is_absolute_path, qualifier) = match &ctx.path_context {
15-
Some(PathCompletionCtx {
16-
kind: Some(PathKind::Use), is_absolute_path, qualifier, ..
17-
}) => (is_absolute_path, qualifier),
15+
Some(PathCompletionCtx { kind: PathKind::Use, is_absolute_path, qualifier, .. }) => {
16+
(is_absolute_path, qualifier)
17+
}
1818
_ => return,
1919
};
2020

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::{
1010
pub(crate) fn complete_vis(acc: &mut Completions, ctx: &CompletionContext) {
1111
let (&is_absolute_path, qualifier, &has_in_token) = match &ctx.path_context {
1212
Some(PathCompletionCtx {
13-
kind: Some(PathKind::Vis { has_in_token }),
13+
kind: PathKind::Vis { has_in_token },
1414
is_absolute_path,
1515
qualifier,
1616
..

crates/ide-completion/src/context.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ pub(crate) struct PathCompletionCtx {
7575
// FIXME: use this
7676
/// The parent of the path we are completing.
7777
pub(super) parent: Option<ast::Path>,
78-
// FIXME: This should be PathKind, the none case should never occur
79-
pub(super) kind: Option<PathKind>,
78+
pub(super) kind: PathKind,
8079
/// Whether the path segment has type args or not.
8180
pub(super) has_type_args: bool,
8281
/// `true` if we are a statement or a last expr in the block.
@@ -315,11 +314,11 @@ impl<'a> CompletionContext<'a> {
315314
}
316315

317316
pub(crate) fn expects_expression(&self) -> bool {
318-
matches!(self.path_context, Some(PathCompletionCtx { kind: Some(PathKind::Expr), .. }))
317+
matches!(self.path_context, Some(PathCompletionCtx { kind: PathKind::Expr, .. }))
319318
}
320319

321320
pub(crate) fn expects_type(&self) -> bool {
322-
matches!(self.path_context, Some(PathCompletionCtx { kind: Some(PathKind::Type), .. }))
321+
matches!(self.path_context, Some(PathCompletionCtx { kind: PathKind::Type, .. }))
323322
}
324323

325324
pub(crate) fn path_is_call(&self) -> bool {
@@ -341,7 +340,7 @@ impl<'a> CompletionContext<'a> {
341340
}
342341

343342
pub(crate) fn path_kind(&self) -> Option<PathKind> {
344-
self.path_context.as_ref().and_then(|it| it.kind)
343+
self.path_context.as_ref().map(|it| it.kind)
345344
}
346345

347346
pub(crate) fn is_immediately_after_macro_bang(&self) -> bool {
@@ -837,7 +836,7 @@ impl<'a> CompletionContext<'a> {
837836
Self::classify_name_ref(&self.sema, &original_file, name_ref)
838837
{
839838
self.path_context =
840-
Some(PathCompletionCtx { kind: Some(PathKind::Derive), ..path_ctx });
839+
Some(PathCompletionCtx { kind: PathKind::Derive, ..path_ctx });
841840
}
842841
}
843842
return;
@@ -969,7 +968,7 @@ impl<'a> CompletionContext<'a> {
969968
is_absolute_path: false,
970969
qualifier: None,
971970
parent: path.parent_path(),
972-
kind: None,
971+
kind: PathKind::Item,
973972
has_type_args: false,
974973
can_be_stmt: false,
975974
in_loop_body: false,
@@ -1041,7 +1040,7 @@ impl<'a> CompletionContext<'a> {
10411040
}
10421041
};
10431042
Some(kind)
1044-
}).flatten();
1043+
}).flatten()?;
10451044
path_ctx.has_type_args = segment.generic_arg_list().is_some();
10461045

10471046
if let Some((path, use_tree_parent)) = path_or_use_tree_qualifier(&path) {

crates/ide-completion/src/render.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ fn render_resolution_simple_(
273273
// Add `<>` for generic types
274274
let type_path_no_ty_args = matches!(
275275
ctx.completion.path_context,
276-
Some(PathCompletionCtx { kind: Some(PathKind::Type), has_type_args: false, .. })
276+
Some(PathCompletionCtx { kind: PathKind::Type, has_type_args: false, .. })
277277
) && ctx.completion.config.add_call_parenthesis;
278278
if type_path_no_ty_args {
279279
if let Some(cap) = ctx.snippet_cap() {

crates/ide-completion/src/render/function.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,10 @@ fn should_add_parens(ctx: &CompletionContext) -> bool {
197197
}
198198

199199
match ctx.path_context {
200-
Some(PathCompletionCtx { kind: Some(PathKind::Expr), has_call_parens: true, .. }) => {
200+
Some(PathCompletionCtx { kind: PathKind::Expr, has_call_parens: true, .. }) => {
201201
return false
202202
}
203-
Some(PathCompletionCtx { kind: Some(PathKind::Use | PathKind::Type), .. }) => {
203+
Some(PathCompletionCtx { kind: PathKind::Use | PathKind::Type, .. }) => {
204204
cov_mark::hit!(no_parens_in_use_item);
205205
return false;
206206
}

crates/ide-completion/src/render/macro_.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ fn render(
3535

3636
let needs_bang = match completion.path_context {
3737
Some(PathCompletionCtx { kind, has_macro_bang, .. }) => {
38-
is_fn_like && kind != Some(PathKind::Use) && !has_macro_bang
38+
is_fn_like && kind != PathKind::Use && !has_macro_bang
3939
}
4040
_ => is_fn_like,
4141
};

0 commit comments

Comments
 (0)