Skip to content

Commit 6269137

Browse files
committed
Auto merge of rust-lang#12560 - Veykril:completion, r=Veykril
internal: More completions refactoring This gets rid of the remaining `ImmediateLocation` bits
2 parents 7322a98 + f201a40 commit 6269137

File tree

14 files changed

+332
-343
lines changed

14 files changed

+332
-343
lines changed

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ use ide_db::FxHashSet;
44

55
use crate::{
66
context::{
7-
CompletionContext, DotAccess, DotAccessKind, NameRefContext, PathCompletionCtx, PathKind,
7+
CompletionContext, DotAccess, DotAccessKind, NameRefContext, NameRefKind,
8+
PathCompletionCtx, PathKind,
89
},
910
CompletionItem, CompletionItemKind, Completions,
1011
};
@@ -13,7 +14,8 @@ use crate::{
1314
pub(crate) fn complete_dot(acc: &mut Completions, ctx: &CompletionContext) {
1415
let (dot_access, receiver_ty) = match ctx.nameref_ctx() {
1516
Some(NameRefContext {
16-
dot_access: Some(access @ DotAccess { receiver_ty: Some(receiver_ty), .. }),
17+
kind:
18+
Some(NameRefKind::DotAccess(access @ DotAccess { receiver_ty: Some(receiver_ty), .. })),
1719
..
1820
}) => (access, &receiver_ty.original),
1921
_ => return complete_undotted_self(acc, ctx),

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

+18-13
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use ide_db::FxHashSet;
55
use syntax::T;
66

77
use crate::{
8-
context::{NameRefContext, PathCompletionCtx, PathKind, PathQualifierCtx},
8+
context::{NameRefContext, NameRefKind, PathCompletionCtx, PathKind, PathQualifierCtx},
99
CompletionContext, Completions,
1010
};
1111

@@ -21,24 +21,29 @@ pub(crate) fn complete_expr_path(acc: &mut Completions, ctx: &CompletionContext)
2121
after_if_expr,
2222
wants_mut_token,
2323
) = match ctx.nameref_ctx() {
24-
Some(NameRefContext {
25-
path_ctx:
26-
Some(PathCompletionCtx {
24+
Some(&NameRefContext {
25+
kind:
26+
Some(NameRefKind::Path(PathCompletionCtx {
2727
kind:
28-
PathKind::Expr { in_block_expr, in_loop_body, after_if_expr, ref_expr_parent },
28+
PathKind::Expr {
29+
in_block_expr,
30+
in_loop_body,
31+
after_if_expr,
32+
ref ref_expr_parent,
33+
ref is_func_update,
34+
},
2935
is_absolute_path,
30-
qualifier,
36+
ref qualifier,
3137
..
32-
}),
33-
record_expr,
38+
})),
3439
..
3540
}) if ctx.qualifier_ctx.none() => (
36-
*is_absolute_path,
41+
is_absolute_path,
3742
qualifier,
38-
*in_block_expr,
39-
*in_loop_body,
40-
record_expr.as_ref().map_or(false, |&(_, it)| it),
41-
*after_if_expr,
43+
in_block_expr,
44+
in_loop_body,
45+
is_func_update.is_some(),
46+
after_if_expr,
4247
ref_expr_parent.as_ref().map(|it| it.mut_token().is_none()).unwrap_or(false),
4348
),
4449
_ => return,

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

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,27 @@
11
//! Completion of field list position.
22
33
use crate::{
4-
context::{IdentContext, NameContext, NameKind, NameRefContext, PathCompletionCtx, PathKind},
4+
context::{
5+
IdentContext, NameContext, NameKind, NameRefContext, NameRefKind, PathCompletionCtx,
6+
PathKind, TypeLocation,
7+
},
58
CompletionContext, Completions,
69
};
710

811
pub(crate) fn complete_field_list(acc: &mut Completions, ctx: &CompletionContext) {
912
match &ctx.ident_ctx {
1013
IdentContext::Name(NameContext { kind: NameKind::RecordField, .. })
1114
| IdentContext::NameRef(NameRefContext {
12-
path_ctx:
13-
Some(PathCompletionCtx {
15+
kind:
16+
Some(NameRefKind::Path(PathCompletionCtx {
1417
has_macro_bang: false,
1518
is_absolute_path: false,
1619
qualifier: None,
1720
parent: None,
18-
kind: PathKind::Type { in_tuple_struct: true },
21+
kind: PathKind::Type { location: TypeLocation::TupleField },
1922
has_type_args: false,
2023
..
21-
}),
24+
})),
2225
..
2326
}) => {
2427
if ctx.qualifier_ctx.vis_node.is_none() {

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

+20-17
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ use itertools::Itertools;
88
use syntax::{AstNode, SyntaxNode, T};
99

1010
use crate::{
11-
context::{CompletionContext, NameRefContext, PathCompletionCtx, PathKind, PatternContext},
12-
patterns::ImmediateLocation,
11+
context::{
12+
CompletionContext, NameRefContext, NameRefKind, PathCompletionCtx, PathKind,
13+
PatternContext, TypeLocation,
14+
},
1315
render::{render_resolution_with_import, RenderContext},
1416
};
1517

@@ -111,19 +113,20 @@ pub(crate) fn import_on_the_fly(acc: &mut Completions, ctx: &CompletionContext)
111113
return None;
112114
}
113115
let path_kind = match ctx.nameref_ctx() {
114-
Some(NameRefContext { path_ctx: Some(PathCompletionCtx { kind, .. }), .. })
115-
if matches!(
116-
kind,
117-
PathKind::Expr { .. }
118-
| PathKind::Type { .. }
119-
| PathKind::Attr { .. }
120-
| PathKind::Derive
121-
| PathKind::Pat
122-
) =>
123-
{
124-
Some(kind)
125-
}
126-
Some(NameRefContext { dot_access: Some(_), .. }) => None,
116+
Some(NameRefContext {
117+
kind:
118+
Some(NameRefKind::Path(PathCompletionCtx {
119+
kind:
120+
kind @ (PathKind::Expr { .. }
121+
| PathKind::Type { .. }
122+
| PathKind::Attr { .. }
123+
| PathKind::Derive
124+
| PathKind::Pat),
125+
..
126+
})),
127+
..
128+
}) => Some(kind),
129+
Some(NameRefContext { kind: Some(NameRefKind::DotAccess(_)), .. }) => None,
127130
None if matches!(ctx.pattern_ctx, Some(PatternContext { record_pat: None, .. })) => {
128131
Some(&PathKind::Pat)
129132
}
@@ -173,8 +176,8 @@ pub(crate) fn import_on_the_fly(acc: &mut Completions, ctx: &CompletionContext)
173176
(PathKind::Pat, ItemInNs::Types(_)) => true,
174177
(PathKind::Pat, ItemInNs::Values(def)) => matches!(def, hir::ModuleDef::Const(_)),
175178

176-
(PathKind::Type { .. }, ItemInNs::Types(ty)) => {
177-
if matches!(ctx.completion_location, Some(ImmediateLocation::TypeBound)) {
179+
(PathKind::Type { location }, ItemInNs::Types(ty)) => {
180+
if matches!(location, TypeLocation::TypeBound) {
178181
matches!(ty, ModuleDef::Trait(_))
179182
} else {
180183
true

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

+5-6
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ use text_edit::TextEdit;
4444

4545
use crate::{
4646
context::{
47-
IdentContext, ItemListKind, NameContext, NameKind, NameRefContext, PathCompletionCtx,
48-
PathKind,
47+
IdentContext, ItemListKind, NameContext, NameKind, NameRefContext, NameRefKind,
48+
PathCompletionCtx, PathKind,
4949
},
5050
CompletionContext, CompletionItem, CompletionItemKind, CompletionRelevance, Completions,
5151
};
@@ -106,14 +106,13 @@ fn completion_match(ctx: &CompletionContext) -> Option<(ImplCompletionKind, Text
106106
}
107107
IdentContext::NameRef(NameRefContext {
108108
nameref,
109-
path_ctx:
110-
Some(
109+
kind:
110+
Some(NameRefKind::Path(
111111
path_ctx @ PathCompletionCtx {
112112
kind: PathKind::Item { kind: ItemListKind::TraitImpl },
113113
..
114114
},
115-
),
116-
..
115+
)),
117116
}) if path_ctx.is_trivial_path() => Some((
118117
ImplCompletionKind::All,
119118
match nameref {

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

+5-2
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@
44
55
use syntax::ast::Item;
66

7-
use crate::{context::NameRefContext, CompletionContext, Completions};
7+
use crate::{
8+
context::{NameRefContext, NameRefKind},
9+
CompletionContext, Completions,
10+
};
811

912
pub(crate) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionContext) {
1013
let item = match ctx.nameref_ctx() {
11-
Some(NameRefContext { keyword: Some(item), record_expr: None, .. }) => item,
14+
Some(NameRefContext { kind: Some(NameRefKind::Keyword(item)), .. }) => item,
1215
_ => return,
1316
};
1417

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

+8-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use text_edit::TextEdit;
1313

1414
use crate::{
1515
completions::postfix::format_like::add_format_like_completions,
16-
context::{CompletionContext, DotAccess, DotAccessKind, NameRefContext},
16+
context::{CompletionContext, DotAccess, DotAccessKind, NameRefContext, NameRefKind},
1717
item::{Builder, CompletionRelevancePostfixMatch},
1818
CompletionItem, CompletionItemKind, CompletionRelevance, Completions, SnippetScope,
1919
};
@@ -25,7 +25,13 @@ pub(crate) fn complete_postfix(acc: &mut Completions, ctx: &CompletionContext) {
2525

2626
let (dot_receiver, receiver_ty, receiver_is_ambiguous_float_literal) = match ctx.nameref_ctx() {
2727
Some(NameRefContext {
28-
dot_access: Some(DotAccess { receiver_ty: Some(ty), receiver: Some(it), kind, .. }),
28+
kind:
29+
Some(NameRefKind::DotAccess(DotAccess {
30+
receiver_ty: Some(ty),
31+
receiver: Some(it),
32+
kind,
33+
..
34+
})),
2935
..
3036
}) => (
3137
it,

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

+14-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use ide_db::SymbolKind;
33
use syntax::{ast::Expr, T};
44

55
use crate::{
6-
context::{NameRefContext, PatternContext},
6+
context::{NameRefContext, NameRefKind, PathCompletionCtx, PathKind, PatternContext},
77
CompletionContext, CompletionItem, CompletionItemKind, CompletionRelevance,
88
CompletionRelevancePostfixMatch, Completions,
99
};
@@ -13,8 +13,18 @@ pub(crate) fn complete_record(acc: &mut Completions, ctx: &CompletionContext) ->
1313
&ctx.pattern_ctx
1414
{
1515
ctx.sema.record_pattern_missing_fields(record_pat)
16-
} else if let Some(NameRefContext { record_expr: Some((record_expr, _)), .. }) =
17-
ctx.nameref_ctx()
16+
} else if let Some(NameRefContext {
17+
kind:
18+
Some(
19+
NameRefKind::RecordExpr(record_expr)
20+
| NameRefKind::Path(PathCompletionCtx {
21+
kind: PathKind::Expr { is_func_update: Some(record_expr), .. },
22+
qualifier: None,
23+
..
24+
}),
25+
),
26+
..
27+
}) = ctx.nameref_ctx()
1828
{
1929
let ty = ctx.sema.type_of_expr(&Expr::RecordExpr(record_expr.clone()));
2030

@@ -39,7 +49,7 @@ pub(crate) fn complete_record(acc: &mut Completions, ctx: &CompletionContext) ->
3949
ty.original.impls_trait(ctx.db, default_trait, &[])
4050
});
4151

42-
if impl_default_trait && !missing_fields.is_empty() && ctx.path_qual().is_none() {
52+
if impl_default_trait && !missing_fields.is_empty() {
4353
let completion_text = "..Default::default()";
4454
let mut item =
4555
CompletionItem::new(SymbolKind::Field, ctx.source_range(), completion_text);

0 commit comments

Comments
 (0)