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

Commit 12dd810

Browse files
committed
Auto merge of rust-lang#12574 - Veykril:completion, r=Veykril
minor: Simplify
2 parents 69f3096 + 0665428 commit 12dd810

File tree

4 files changed

+47
-75
lines changed

4 files changed

+47
-75
lines changed

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

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

66
use crate::{
7-
context::{NameRefContext, NameRefKind, PathCompletionCtx, PathKind, Qualified},
7+
context::{PathCompletionCtx, PathKind, Qualified},
88
CompletionContext, Completions,
99
};
1010

1111
pub(crate) fn complete_expr_path(
1212
acc: &mut Completions,
1313
ctx: &CompletionContext,
14-
name_ref_ctx: &NameRefContext,
14+
path_ctx: &PathCompletionCtx,
1515
) {
1616
let _p = profile::span("complete_expr_path");
1717

@@ -23,22 +23,18 @@ pub(crate) fn complete_expr_path(
2323
after_if_expr,
2424
wants_mut_token,
2525
in_condition,
26-
) = match name_ref_ctx {
27-
&NameRefContext {
26+
) = match path_ctx {
27+
&PathCompletionCtx {
2828
kind:
29-
Some(NameRefKind::Path(PathCompletionCtx {
30-
kind:
31-
PathKind::Expr {
32-
in_block_expr,
33-
in_loop_body,
34-
after_if_expr,
35-
in_condition,
36-
ref ref_expr_parent,
37-
ref is_func_update,
38-
},
39-
ref qualified,
40-
..
41-
})),
29+
PathKind::Expr {
30+
in_block_expr,
31+
in_loop_body,
32+
after_if_expr,
33+
in_condition,
34+
ref ref_expr_parent,
35+
ref is_func_update,
36+
},
37+
ref qualified,
4238
..
4339
} if ctx.qualifier_ctx.none() => (
4440
qualified,

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

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,22 @@
11
//! Completion of field list position.
22
33
use crate::{
4-
context::{
5-
NameContext, NameKind, NameRefContext, NameRefKind, PathCompletionCtx, PathKind, Qualified,
6-
TypeLocation,
7-
},
4+
context::{NameContext, NameKind, PathCompletionCtx, PathKind, Qualified, TypeLocation},
85
CompletionContext, Completions,
96
};
107

118
pub(crate) fn complete_field_list_tuple_variant(
129
acc: &mut Completions,
1310
ctx: &CompletionContext,
14-
name_ref_ctx: &NameRefContext,
11+
path_ctx: &PathCompletionCtx,
1512
) {
16-
match name_ref_ctx {
17-
NameRefContext {
18-
kind:
19-
Some(NameRefKind::Path(PathCompletionCtx {
20-
has_macro_bang: false,
21-
qualified: Qualified::No,
22-
parent: None,
23-
kind: PathKind::Type { location: TypeLocation::TupleField },
24-
has_type_args: false,
25-
..
26-
})),
13+
match path_ctx {
14+
PathCompletionCtx {
15+
has_macro_bang: false,
16+
qualified: Qualified::No,
17+
parent: None,
18+
kind: PathKind::Type { location: TypeLocation::TupleField },
19+
has_type_args: false,
2720
..
2821
} => {
2922
if ctx.qualifier_ctx.vis_node.is_none() {

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

Lines changed: 15 additions & 35 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, NameRefContext, NameRefKind, PathCompletionCtx, PathKind, Qualified},
5+
context::{ItemListKind, PathCompletionCtx, PathKind, Qualified},
66
CompletionContext, Completions,
77
};
88

@@ -11,45 +11,25 @@ pub(crate) mod trait_impl;
1111
pub(crate) fn complete_item_list(
1212
acc: &mut Completions,
1313
ctx: &CompletionContext,
14-
name_ref_ctx: &NameRefContext,
14+
path_ctx: &PathCompletionCtx,
1515
) {
1616
let _p = profile::span("complete_item_list");
17-
18-
let (qualified, item_list_kind, is_trivial_path) = match name_ref_ctx {
19-
NameRefContext {
20-
kind:
21-
Some(NameRefKind::Path(
22-
ctx @ PathCompletionCtx { kind: PathKind::Item { kind }, qualified, .. },
23-
)),
24-
..
25-
} => (qualified, Some(kind), ctx.is_trivial_path()),
26-
NameRefContext {
27-
kind:
28-
Some(NameRefKind::Path(
29-
ctx @ PathCompletionCtx {
30-
kind: PathKind::Expr { in_block_expr: true, .. },
31-
qualified,
32-
..
33-
},
34-
)),
35-
..
36-
} => (qualified, None, ctx.is_trivial_path()),
17+
let qualified = match path_ctx {
18+
PathCompletionCtx { kind: PathKind::Item { kind }, qualified, .. } => {
19+
if path_ctx.is_trivial_path() {
20+
add_keywords(acc, ctx, Some(kind));
21+
}
22+
qualified
23+
}
24+
PathCompletionCtx { kind: PathKind::Expr { in_block_expr: true, .. }, .. }
25+
if path_ctx.is_trivial_path() =>
26+
{
27+
add_keywords(acc, ctx, None);
28+
return;
29+
}
3730
_ => return,
3831
};
3932

40-
if matches!(item_list_kind, Some(ItemListKind::TraitImpl)) {
41-
trait_impl::complete_trait_impl_name_ref(acc, ctx, name_ref_ctx);
42-
}
43-
44-
if is_trivial_path {
45-
add_keywords(acc, ctx, item_list_kind);
46-
}
47-
48-
if item_list_kind.is_none() {
49-
// this is already handled by expression
50-
return;
51-
}
52-
5333
match qualified {
5434
Qualified::With {
5535
resolution: Some(hir::PathResolution::Def(hir::ModuleDef::Module(module))),

crates/ide-completion/src/lib.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -171,22 +171,25 @@ pub fn completions(
171171
completions::item_list::trait_impl::complete_trait_impl_name(acc, ctx, name_ctx);
172172
completions::mod_::complete_mod(acc, ctx, name_ctx);
173173
}
174-
IdentContext::NameRef(name_ref_ctx @ NameRefContext { kind, .. }) => {
175-
completions::expr::complete_expr_path(acc, ctx, name_ref_ctx);
176-
completions::field::complete_field_list_tuple_variant(acc, ctx, name_ref_ctx);
177-
completions::item_list::complete_item_list(acc, ctx, name_ref_ctx);
178-
completions::use_::complete_use_tree(acc, ctx, name_ref_ctx);
174+
IdentContext::NameRef(name_ctx @ NameRefContext { kind, .. }) => {
175+
completions::item_list::trait_impl::complete_trait_impl_name_ref(
176+
acc, ctx, name_ctx,
177+
);
178+
completions::use_::complete_use_tree(acc, ctx, name_ctx);
179179

180180
match kind {
181181
Some(NameRefKind::Path(path_ctx)) => {
182-
completions::flyimport::import_on_the_fly_path(acc, ctx, path_ctx);
183-
completions::record::complete_record_expr_func_update(acc, ctx, path_ctx);
184182
completions::attribute::complete_attribute(acc, ctx, path_ctx);
185183
completions::attribute::complete_derive(acc, ctx, path_ctx);
186184
completions::dot::complete_undotted_self(acc, ctx, path_ctx);
185+
completions::expr::complete_expr_path(acc, ctx, path_ctx);
186+
completions::field::complete_field_list_tuple_variant(acc, ctx, path_ctx);
187+
completions::flyimport::import_on_the_fly_path(acc, ctx, path_ctx);
188+
completions::item_list::complete_item_list(acc, ctx, path_ctx);
187189
completions::pattern::pattern_path_completion(acc, ctx, path_ctx);
188190
completions::r#type::complete_inferred_type(acc, ctx, path_ctx);
189191
completions::r#type::complete_type_path(acc, ctx, path_ctx);
192+
completions::record::complete_record_expr_func_update(acc, ctx, path_ctx);
190193
completions::snippet::complete_expr_snippet(acc, ctx, path_ctx);
191194
completions::snippet::complete_item_snippet(acc, ctx, path_ctx);
192195
completions::vis::complete_vis_path(acc, ctx, path_ctx);

0 commit comments

Comments
 (0)