Skip to content

Commit 1b94579

Browse files
Merge pull request rust-lang#20571 from A4-Tacks/type-kw-comp
Add type keywords completions
2 parents cef7df3 + 70e3d8c commit 1b94579

File tree

6 files changed

+215
-0
lines changed

6 files changed

+215
-0
lines changed

src/tools/rust-analyzer/crates/ide-completion/src/completions.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,13 @@ impl Completions {
111111
}
112112
}
113113

114+
pub(crate) fn add_type_keywords(&mut self, ctx: &CompletionContext<'_>) {
115+
self.add_keyword_snippet(ctx, "fn", "fn($1)");
116+
self.add_keyword_snippet(ctx, "dyn", "dyn $0");
117+
self.add_keyword_snippet(ctx, "impl", "impl $0");
118+
self.add_keyword_snippet(ctx, "for", "for<$1>");
119+
}
120+
114121
pub(crate) fn add_super_keyword(
115122
&mut self,
116123
ctx: &CompletionContext<'_>,

src/tools/rust-analyzer/crates/ide-completion/src/completions/type.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ pub(crate) fn complete_type_path(
205205
};
206206

207207
acc.add_nameref_keywords_with_colon(ctx);
208+
acc.add_type_keywords(ctx);
208209
ctx.process_all_names(&mut |name, def, doc_aliases| {
209210
if scope_def_applicable(def) {
210211
acc.add_path_resolution(ctx, path_ctx, name, def, doc_aliases);

src/tools/rust-analyzer/crates/ide-completion/src/tests/item.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ impl Tra$0
2323
un Union Union
2424
bt u32 u32
2525
kw crate::
26+
kw dyn
27+
kw fn
28+
kw for
29+
kw impl
2630
kw self::
2731
"#]],
2832
)
@@ -45,6 +49,10 @@ impl Trait for Str$0
4549
un Union Union
4650
bt u32 u32
4751
kw crate::
52+
kw dyn
53+
kw fn
54+
kw for
55+
kw impl
4856
kw self::
4957
"#]],
5058
)

src/tools/rust-analyzer/crates/ide-completion/src/tests/predicate.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ struct Foo<'lt, T, const C: usize> where $0 {}
2222
un Union Union
2323
bt u32 u32
2424
kw crate::
25+
kw dyn
26+
kw fn
27+
kw for
28+
kw impl
2529
kw self::
2630
"#]],
2731
);
@@ -95,6 +99,10 @@ struct Foo<'lt, T, const C: usize> where for<'a> $0 {}
9599
un Union Union
96100
bt u32 u32
97101
kw crate::
102+
kw dyn
103+
kw fn
104+
kw for
105+
kw impl
98106
kw self::
99107
"#]],
100108
);
@@ -120,6 +128,10 @@ impl Record {
120128
un Union Union
121129
bt u32 u32
122130
kw crate::
131+
kw dyn
132+
kw fn
133+
kw for
134+
kw impl
123135
kw self::
124136
"#]],
125137
);

src/tools/rust-analyzer/crates/ide-completion/src/tests/special.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1492,6 +1492,10 @@ fn foo(_: a_$0) { }
14921492
expect![[r#"
14931493
bt u32 u32
14941494
kw crate::
1495+
kw dyn
1496+
kw fn
1497+
kw for
1498+
kw impl
14951499
kw self::
14961500
"#]],
14971501
);
@@ -1506,6 +1510,10 @@ fn foo<T>() {
15061510
tp T
15071511
bt u32 u32
15081512
kw crate::
1513+
kw dyn
1514+
kw fn
1515+
kw for
1516+
kw impl
15091517
kw self::
15101518
"#]],
15111519
);
@@ -1531,6 +1539,10 @@ fn foo<const N: $0>() {}
15311539
expect![[r#"
15321540
bt u32 u32
15331541
kw crate::
1542+
kw dyn
1543+
kw fn
1544+
kw for
1545+
kw impl
15341546
kw self::
15351547
"#]],
15361548
);

0 commit comments

Comments
 (0)