Skip to content

Commit e7a0088

Browse files
committed
Auto merge of rust-lang#12565 - Veykril:completion, r=Veykril
internal: More completion refactors
2 parents bea4ba0 + 85b68b1 commit e7a0088

File tree

11 files changed

+94
-101
lines changed

11 files changed

+94
-101
lines changed

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ use syntax::{
1818

1919
use crate::{
2020
completions::module_or_attr,
21-
context::{
22-
CompletionContext, IdentContext, PathCompletionCtx, PathKind, PathQualifierCtx, Qualified,
23-
},
21+
context::{CompletionContext, IdentContext, PathCompletionCtx, PathKind, Qualified},
2422
item::CompletionItem,
2523
Completions,
2624
};
@@ -84,7 +82,7 @@ pub(crate) fn complete_attribute(acc: &mut Completions, ctx: &CompletionContext)
8482
};
8583

8684
match qualified {
87-
Qualified::With(PathQualifierCtx { resolution, is_super_chain, .. }) => {
85+
Qualified::With { resolution, is_super_chain, .. } => {
8886
if *is_super_chain {
8987
acc.add_keyword(ctx, "super::");
9088
}
@@ -112,6 +110,7 @@ pub(crate) fn complete_attribute(acc: &mut Completions, ctx: &CompletionContext)
112110
});
113111
acc.add_nameref_keywords_with_colon(ctx);
114112
}
113+
Qualified::Infer => {}
115114
}
116115

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

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,23 @@ use itertools::Itertools;
55
use syntax::SmolStr;
66

77
use crate::{
8-
context::{CompletionContext, PathCompletionCtx, PathKind, PathQualifierCtx, Qualified},
8+
context::{CompletionContext, PathCompletionCtx, PathKind, Qualified},
99
item::CompletionItem,
1010
Completions,
1111
};
1212

1313
pub(crate) fn complete_derive(acc: &mut Completions, ctx: &CompletionContext) {
14-
let qualified = match ctx.path_context() {
15-
Some(&PathCompletionCtx { kind: PathKind::Derive, ref qualified, .. }) => qualified,
14+
let (qualified, existing_derives) = match ctx.path_context() {
15+
Some(PathCompletionCtx {
16+
kind: PathKind::Derive { existing_derives }, qualified, ..
17+
}) => (qualified, existing_derives),
1618
_ => return,
1719
};
1820

1921
let core = ctx.famous_defs().core();
2022

2123
match qualified {
22-
Qualified::With(PathQualifierCtx { resolution, is_super_chain, .. }) => {
24+
Qualified::With { resolution, is_super_chain, .. } => {
2325
if *is_super_chain {
2426
acc.add_keyword(ctx, "super::");
2527
}
@@ -32,7 +34,7 @@ pub(crate) fn complete_derive(acc: &mut Completions, ctx: &CompletionContext) {
3234
for (name, def) in module.scope(ctx.db, Some(ctx.module)) {
3335
let add_def = match def {
3436
ScopeDef::ModuleDef(hir::ModuleDef::Macro(mac)) => {
35-
!ctx.existing_derives.contains(&mac) && mac.is_derive(ctx.db)
37+
!existing_derives.contains(&mac) && mac.is_derive(ctx.db)
3638
}
3739
ScopeDef::ModuleDef(hir::ModuleDef::Module(_)) => true,
3840
_ => false,
@@ -48,7 +50,7 @@ pub(crate) fn complete_derive(acc: &mut Completions, ctx: &CompletionContext) {
4850
ctx.process_all_names(&mut |name, def| {
4951
let mac = match def {
5052
ScopeDef::ModuleDef(hir::ModuleDef::Macro(mac))
51-
if !ctx.existing_derives.contains(&mac) && mac.is_derive(ctx.db) =>
53+
if !existing_derives.contains(&mac) && mac.is_derive(ctx.db) =>
5254
{
5355
mac
5456
}
@@ -74,7 +76,7 @@ pub(crate) fn complete_derive(acc: &mut Completions, ctx: &CompletionContext) {
7476
let mut components = vec![derive_completion.label];
7577
components.extend(derive_completion.dependencies.iter().filter(
7678
|&&dependency| {
77-
!ctx.existing_derives
79+
!existing_derives
7880
.iter()
7981
.map(|it| it.name(ctx.db))
8082
.any(|it| it.to_smol_str() == dependency)
@@ -99,6 +101,7 @@ pub(crate) fn complete_derive(acc: &mut Completions, ctx: &CompletionContext) {
99101
});
100102
acc.add_nameref_keywords_with_colon(ctx);
101103
}
104+
Qualified::Infer => {}
102105
}
103106
}
104107

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

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ use hir::ScopeDef;
44
use ide_db::FxHashSet;
55

66
use crate::{
7-
context::{
8-
NameRefContext, NameRefKind, PathCompletionCtx, PathKind, PathQualifierCtx, Qualified,
9-
},
7+
context::{NameRefContext, NameRefKind, PathCompletionCtx, PathKind, Qualified},
108
CompletionContext, Completions,
119
};
1210

@@ -61,15 +59,13 @@ pub(crate) fn complete_expr_path(acc: &mut Completions, ctx: &CompletionContext)
6159
};
6260

6361
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-
}
62+
Qualified::Infer => ctx
63+
.traits_in_scope()
64+
.0
65+
.into_iter()
66+
.flat_map(|it| hir::Trait::from(it).items(ctx.sema.db))
67+
.for_each(|item| add_assoc_item(acc, ctx, item)),
68+
Qualified::With { resolution, .. } => {
7369
let resolution = match resolution {
7470
Some(it) => it,
7571
None => return,

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ pub(crate) fn import_on_the_fly(acc: &mut Completions, ctx: &CompletionContext)
120120
kind @ (PathKind::Expr { .. }
121121
| PathKind::Type { .. }
122122
| PathKind::Attr { .. }
123-
| PathKind::Derive
123+
| PathKind::Derive { .. }
124124
| PathKind::Pat),
125125
..
126126
})),
@@ -188,10 +188,10 @@ pub(crate) fn import_on_the_fly(acc: &mut Completions, ctx: &CompletionContext)
188188
(PathKind::Attr { .. }, ItemInNs::Macros(mac)) => mac.is_attr(ctx.db),
189189
(PathKind::Attr { .. }, _) => false,
190190

191-
(PathKind::Derive, ItemInNs::Macros(mac)) => {
192-
mac.is_derive(ctx.db) && !ctx.existing_derives.contains(&mac)
191+
(PathKind::Derive { existing_derives }, ItemInNs::Macros(mac)) => {
192+
mac.is_derive(ctx.db) && !existing_derives.contains(&mac)
193193
}
194-
(PathKind::Derive, _) => false,
194+
(PathKind::Derive { .. }, _) => false,
195195
}
196196
};
197197

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

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

@@ -44,7 +44,7 @@ pub(crate) fn complete_item_list(acc: &mut Completions, ctx: &CompletionContext)
4444
}
4545

4646
match qualified {
47-
Qualified::With(PathQualifierCtx { resolution, is_super_chain, .. }) => {
47+
Qualified::With { resolution, is_super_chain, .. } => {
4848
if let Some(hir::PathResolution::Def(hir::ModuleDef::Module(module))) = resolution {
4949
for (name, def) in module.scope(ctx.db, Some(ctx.module)) {
5050
if let Some(def) = module_or_fn_macro(ctx.db, def) {
@@ -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: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use ide_db::FxHashSet;
55
use syntax::ast::Pat;
66

77
use crate::{
8-
context::{PathCompletionCtx, PathQualifierCtx, PatternRefutability, Qualified},
8+
context::{PathCompletionCtx, PatternRefutability, Qualified},
99
CompletionContext, Completions,
1010
};
1111

@@ -114,7 +114,7 @@ fn pattern_path_completion(
114114
PathCompletionCtx { qualified, .. }: &PathCompletionCtx,
115115
) {
116116
match qualified {
117-
Qualified::With(PathQualifierCtx { resolution, is_super_chain, .. }) => {
117+
Qualified::With { resolution, is_super_chain, .. } => {
118118
if *is_super_chain {
119119
acc.add_keyword(ctx, "super::");
120120
}
@@ -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: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@ use ide_db::FxHashSet;
55
use syntax::{ast, AstNode};
66

77
use crate::{
8-
context::{
9-
PathCompletionCtx, PathKind, PathQualifierCtx, Qualified, TypeAscriptionTarget,
10-
TypeLocation,
11-
},
8+
context::{PathCompletionCtx, PathKind, Qualified, TypeAscriptionTarget, TypeLocation},
129
render::render_type_inference,
1310
CompletionContext, Completions,
1411
};
@@ -55,15 +52,13 @@ pub(crate) fn complete_type_path(acc: &mut Completions, ctx: &CompletionContext)
5552
};
5653

5754
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-
}
55+
Qualified::Infer => ctx
56+
.traits_in_scope()
57+
.0
58+
.into_iter()
59+
.flat_map(|it| hir::Trait::from(it).items(ctx.sema.db))
60+
.for_each(|item| add_assoc_item(acc, item)),
61+
Qualified::With { resolution, .. } => {
6762
let resolution = match resolution {
6863
Some(it) => it,
6964
None => return,

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,30 @@ use syntax::{ast, AstNode};
66

77
use crate::{
88
context::{
9-
CompletionContext, NameRefContext, NameRefKind, PathCompletionCtx, PathKind,
10-
PathQualifierCtx, Qualified,
9+
CompletionContext, NameRefContext, NameRefKind, PathCompletionCtx, PathKind, Qualified,
1110
},
1211
item::Builder,
1312
CompletionItem, CompletionItemKind, CompletionRelevance, Completions,
1413
};
1514

1615
pub(crate) fn complete_use_tree(acc: &mut Completions, ctx: &CompletionContext) {
17-
let (qualified, name_ref) = match ctx.nameref_ctx() {
16+
let (qualified, name_ref, use_tree_parent) = match ctx.nameref_ctx() {
1817
Some(NameRefContext {
19-
kind: Some(NameRefKind::Path(PathCompletionCtx { kind: PathKind::Use, qualified, .. })),
18+
kind:
19+
Some(NameRefKind::Path(PathCompletionCtx {
20+
kind: PathKind::Use,
21+
qualified,
22+
use_tree_parent,
23+
..
24+
})),
2025
nameref,
2126
..
22-
}) => (qualified, nameref),
27+
}) => (qualified, nameref, use_tree_parent),
2328
_ => return,
2429
};
2530

2631
match qualified {
27-
Qualified::With(PathQualifierCtx {
28-
path,
29-
resolution,
30-
is_super_chain,
31-
use_tree_parent,
32-
..
33-
}) => {
32+
Qualified::With { path, resolution, is_super_chain } => {
3433
if *is_super_chain {
3534
acc.add_keyword(ctx, "super::");
3635
}
@@ -136,5 +135,6 @@ pub(crate) fn complete_use_tree(acc: &mut Completions, ctx: &CompletionContext)
136135
});
137136
acc.add_nameref_keywords_with_colon(ctx);
138137
}
138+
Qualified::Infer => {}
139139
}
140140
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use hir::ScopeDef;
44

55
use crate::{
6-
context::{CompletionContext, PathCompletionCtx, PathKind, PathQualifierCtx, Qualified},
6+
context::{CompletionContext, PathCompletionCtx, PathKind, Qualified},
77
Completions,
88
};
99

@@ -16,7 +16,7 @@ pub(crate) fn complete_vis_path(acc: &mut Completions, ctx: &CompletionContext)
1616
};
1717

1818
match qualified {
19-
Qualified::With(PathQualifierCtx { resolution, is_super_chain, .. }) => {
19+
Qualified::With { resolution, is_super_chain, .. } => {
2020
// Try completing next child module of the path that is still a parent of the current module
2121
if let Some(hir::PathResolution::Def(hir::ModuleDef::Module(module))) = resolution {
2222
let next_towards_current = ctx
@@ -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);

0 commit comments

Comments
 (0)