diff options
Diffstat (limited to 'crates/ide_completion/src/completions')
9 files changed, 103 insertions, 170 deletions
diff --git a/crates/ide_completion/src/completions/attribute.rs b/crates/ide_completion/src/completions/attribute.rs index 3866c5917..f3b11e72d 100644 --- a/crates/ide_completion/src/completions/attribute.rs +++ b/crates/ide_completion/src/completions/attribute.rs | |||
@@ -322,7 +322,7 @@ mod tests { | |||
322 | 322 | ||
323 | use expect_test::{expect, Expect}; | 323 | use expect_test::{expect, Expect}; |
324 | 324 | ||
325 | use crate::{tests::filtered_completion_list, CompletionKind}; | 325 | use crate::tests::completion_list; |
326 | 326 | ||
327 | #[test] | 327 | #[test] |
328 | fn attributes_are_sorted() { | 328 | fn attributes_are_sorted() { |
@@ -341,7 +341,7 @@ mod tests { | |||
341 | } | 341 | } |
342 | 342 | ||
343 | fn check(ra_fixture: &str, expect: Expect) { | 343 | fn check(ra_fixture: &str, expect: Expect) { |
344 | let actual = filtered_completion_list(ra_fixture, CompletionKind::Attribute); | 344 | let actual = completion_list(ra_fixture); |
345 | expect.assert_eq(&actual); | 345 | expect.assert_eq(&actual); |
346 | } | 346 | } |
347 | 347 | ||
@@ -786,6 +786,7 @@ mod tests { | |||
786 | at target_feature = "…" | 786 | at target_feature = "…" |
787 | at test | 787 | at test |
788 | at track_caller | 788 | at track_caller |
789 | kw return | ||
789 | "#]], | 790 | "#]], |
790 | ); | 791 | ); |
791 | } | 792 | } |
@@ -801,6 +802,7 @@ mod tests { | |||
801 | at deny(…) | 802 | at deny(…) |
802 | at forbid(…) | 803 | at forbid(…) |
803 | at warn(…) | 804 | at warn(…) |
805 | kw return | ||
804 | "#]], | 806 | "#]], |
805 | ); | 807 | ); |
806 | } | 808 | } |
diff --git a/crates/ide_completion/src/completions/attribute/derive.rs b/crates/ide_completion/src/completions/attribute/derive.rs index 5201095e8..6fe41e0d6 100644 --- a/crates/ide_completion/src/completions/attribute/derive.rs +++ b/crates/ide_completion/src/completions/attribute/derive.rs | |||
@@ -82,7 +82,7 @@ const DEFAULT_DERIVE_COMPLETIONS: &[DeriveDependencies] = &[ | |||
82 | mod tests { | 82 | mod tests { |
83 | use expect_test::{expect, Expect}; | 83 | use expect_test::{expect, Expect}; |
84 | 84 | ||
85 | use crate::{tests::filtered_completion_list, CompletionKind}; | 85 | use crate::tests::completion_list; |
86 | 86 | ||
87 | fn check(ra_fixture: &str, expect: Expect) { | 87 | fn check(ra_fixture: &str, expect: Expect) { |
88 | let builtin_derives = r#" | 88 | let builtin_derives = r#" |
@@ -106,10 +106,7 @@ pub macro PartialOrd {} | |||
106 | pub macro Ord {} | 106 | pub macro Ord {} |
107 | 107 | ||
108 | "#; | 108 | "#; |
109 | let actual = filtered_completion_list( | 109 | let actual = completion_list(&format!("{} {}", builtin_derives, ra_fixture)); |
110 | &format!("{} {}", builtin_derives, ra_fixture), | ||
111 | CompletionKind::Attribute, | ||
112 | ); | ||
113 | expect.assert_eq(&actual); | 110 | expect.assert_eq(&actual); |
114 | } | 111 | } |
115 | 112 | ||
diff --git a/crates/ide_completion/src/completions/attribute/lint.rs b/crates/ide_completion/src/completions/attribute/lint.rs index 4812b075c..1ddc38986 100644 --- a/crates/ide_completion/src/completions/attribute/lint.rs +++ b/crates/ide_completion/src/completions/attribute/lint.rs | |||
@@ -33,7 +33,6 @@ pub(super) fn complete_lint( | |||
33 | 33 | ||
34 | #[cfg(test)] | 34 | #[cfg(test)] |
35 | mod tests { | 35 | mod tests { |
36 | |||
37 | use crate::tests::check_edit; | 36 | use crate::tests::check_edit; |
38 | 37 | ||
39 | #[test] | 38 | #[test] |
diff --git a/crates/ide_completion/src/completions/keyword.rs b/crates/ide_completion/src/completions/keyword.rs index 9754122a0..c99fdef05 100644 --- a/crates/ide_completion/src/completions/keyword.rs +++ b/crates/ide_completion/src/completions/keyword.rs | |||
@@ -37,17 +37,6 @@ pub(crate) fn complete_use_tree_keyword(acc: &mut Completions, ctx: &CompletionC | |||
37 | } | 37 | } |
38 | }; | 38 | }; |
39 | } | 39 | } |
40 | |||
41 | // Suggest .await syntax for types that implement Future trait | ||
42 | if let Some(receiver) = ctx.dot_receiver() { | ||
43 | if let Some(ty) = ctx.sema.type_of_expr(receiver) { | ||
44 | if ty.impls_future(ctx.db) { | ||
45 | let mut item = kw_completion("await"); | ||
46 | item.detail("expr.await"); | ||
47 | item.add_to(acc); | ||
48 | } | ||
49 | }; | ||
50 | } | ||
51 | } | 40 | } |
52 | 41 | ||
53 | pub(crate) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionContext) { | 42 | pub(crate) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionContext) { |
@@ -59,6 +48,19 @@ pub(crate) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionConte | |||
59 | cov_mark::hit!(no_keyword_completion_in_record_lit); | 48 | cov_mark::hit!(no_keyword_completion_in_record_lit); |
60 | return; | 49 | return; |
61 | } | 50 | } |
51 | |||
52 | // Suggest .await syntax for types that implement Future trait | ||
53 | if let Some(receiver) = ctx.dot_receiver() { | ||
54 | if let Some(ty) = ctx.sema.type_of_expr(receiver) { | ||
55 | if ty.impls_future(ctx.db) { | ||
56 | let mut item = | ||
57 | CompletionItem::new(CompletionKind::Keyword, ctx.source_range(), "await"); | ||
58 | item.kind(CompletionItemKind::Keyword).detail("expr.await"); | ||
59 | item.add_to(acc); | ||
60 | } | ||
61 | }; | ||
62 | } | ||
63 | |||
62 | let mut add_keyword = |kw, snippet| add_keyword(ctx, acc, kw, snippet); | 64 | let mut add_keyword = |kw, snippet| add_keyword(ctx, acc, kw, snippet); |
63 | 65 | ||
64 | let expects_assoc_item = ctx.expects_assoc_item(); | 66 | let expects_assoc_item = ctx.expects_assoc_item(); |
@@ -67,6 +69,9 @@ pub(crate) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionConte | |||
67 | 69 | ||
68 | if ctx.has_impl_or_trait_prev_sibling() { | 70 | if ctx.has_impl_or_trait_prev_sibling() { |
69 | add_keyword("where", "where "); | 71 | add_keyword("where", "where "); |
72 | if ctx.has_impl_prev_sibling() { | ||
73 | add_keyword("for", "for "); | ||
74 | } | ||
70 | return; | 75 | return; |
71 | } | 76 | } |
72 | if ctx.previous_token_is(T![unsafe]) { | 77 | if ctx.previous_token_is(T![unsafe]) { |
@@ -386,22 +391,6 @@ fn quux() -> i32 { | |||
386 | } | 391 | } |
387 | 392 | ||
388 | #[test] | 393 | #[test] |
389 | fn test_where_keyword() { | ||
390 | check( | ||
391 | r"trait A $0", | ||
392 | expect![[r#" | ||
393 | kw where | ||
394 | "#]], | ||
395 | ); | ||
396 | check( | ||
397 | r"impl A $0", | ||
398 | expect![[r#" | ||
399 | kw where | ||
400 | "#]], | ||
401 | ); | ||
402 | } | ||
403 | |||
404 | #[test] | ||
405 | fn no_keyword_completion_in_comments() { | 394 | fn no_keyword_completion_in_comments() { |
406 | cov_mark::check!(no_keyword_completion_in_comments); | 395 | cov_mark::check!(no_keyword_completion_in_comments); |
407 | check( | 396 | check( |
@@ -478,22 +467,6 @@ fn foo() { | |||
478 | } | 467 | } |
479 | 468 | ||
480 | #[test] | 469 | #[test] |
481 | fn before_field() { | ||
482 | check( | ||
483 | r#" | ||
484 | struct Foo { | ||
485 | $0 | ||
486 | pub f: i32, | ||
487 | } | ||
488 | "#, | ||
489 | expect![[r#" | ||
490 | kw pub(crate) | ||
491 | kw pub | ||
492 | "#]], | ||
493 | ) | ||
494 | } | ||
495 | |||
496 | #[test] | ||
497 | fn skip_struct_initializer() { | 470 | fn skip_struct_initializer() { |
498 | cov_mark::check!(no_keyword_completion_in_record_lit); | 471 | cov_mark::check!(no_keyword_completion_in_record_lit); |
499 | check( | 472 | check( |
diff --git a/crates/ide_completion/src/completions/lifetime.rs b/crates/ide_completion/src/completions/lifetime.rs index 36f595164..abf6935c9 100644 --- a/crates/ide_completion/src/completions/lifetime.rs +++ b/crates/ide_completion/src/completions/lifetime.rs | |||
@@ -49,19 +49,11 @@ pub(crate) fn complete_label(acc: &mut Completions, ctx: &CompletionContext) { | |||
49 | mod tests { | 49 | mod tests { |
50 | use expect_test::{expect, Expect}; | 50 | use expect_test::{expect, Expect}; |
51 | 51 | ||
52 | use crate::{ | 52 | use crate::tests::{check_edit, completion_list}; |
53 | tests::{check_edit, filtered_completion_list_with_config, TEST_CONFIG}, | ||
54 | CompletionConfig, CompletionKind, | ||
55 | }; | ||
56 | 53 | ||
57 | fn check(ra_fixture: &str, expect: Expect) { | 54 | fn check(ra_fixture: &str, expect: Expect) { |
58 | check_with_config(TEST_CONFIG, ra_fixture, expect); | 55 | let actual = completion_list(ra_fixture); |
59 | } | 56 | expect.assert_eq(&actual); |
60 | |||
61 | fn check_with_config(config: CompletionConfig, ra_fixture: &str, expect: Expect) { | ||
62 | let actual = | ||
63 | filtered_completion_list_with_config(config, ra_fixture, CompletionKind::Reference); | ||
64 | expect.assert_eq(&actual) | ||
65 | } | 57 | } |
66 | 58 | ||
67 | #[test] | 59 | #[test] |
diff --git a/crates/ide_completion/src/completions/mod_.rs b/crates/ide_completion/src/completions/mod_.rs index 5def0d06a..1c864c0e7 100644 --- a/crates/ide_completion/src/completions/mod_.rs +++ b/crates/ide_completion/src/completions/mod_.rs | |||
@@ -141,11 +141,11 @@ fn module_chain_to_containing_module_file( | |||
141 | 141 | ||
142 | #[cfg(test)] | 142 | #[cfg(test)] |
143 | mod tests { | 143 | mod tests { |
144 | use crate::{tests::filtered_completion_list, CompletionKind}; | 144 | use crate::tests::completion_list; |
145 | use expect_test::{expect, Expect}; | 145 | use expect_test::{expect, Expect}; |
146 | 146 | ||
147 | fn check(ra_fixture: &str, expect: Expect) { | 147 | fn check(ra_fixture: &str, expect: Expect) { |
148 | let actual = filtered_completion_list(ra_fixture, CompletionKind::Magic); | 148 | let actual = completion_list(ra_fixture); |
149 | expect.assert_eq(&actual); | 149 | expect.assert_eq(&actual); |
150 | } | 150 | } |
151 | 151 | ||
@@ -153,17 +153,17 @@ mod tests { | |||
153 | fn lib_module_completion() { | 153 | fn lib_module_completion() { |
154 | check( | 154 | check( |
155 | r#" | 155 | r#" |
156 | //- /lib.rs | 156 | //- /lib.rs |
157 | mod $0 | 157 | mod $0 |
158 | //- /foo.rs | 158 | //- /foo.rs |
159 | fn foo() {} | 159 | fn foo() {} |
160 | //- /foo/ignored_foo.rs | 160 | //- /foo/ignored_foo.rs |
161 | fn ignored_foo() {} | 161 | fn ignored_foo() {} |
162 | //- /bar/mod.rs | 162 | //- /bar/mod.rs |
163 | fn bar() {} | 163 | fn bar() {} |
164 | //- /bar/ignored_bar.rs | 164 | //- /bar/ignored_bar.rs |
165 | fn ignored_bar() {} | 165 | fn ignored_bar() {} |
166 | "#, | 166 | "#, |
167 | expect![[r#" | 167 | expect![[r#" |
168 | md foo; | 168 | md foo; |
169 | md bar; | 169 | md bar; |
@@ -175,13 +175,13 @@ mod tests { | |||
175 | fn no_module_completion_with_module_body() { | 175 | fn no_module_completion_with_module_body() { |
176 | check( | 176 | check( |
177 | r#" | 177 | r#" |
178 | //- /lib.rs | 178 | //- /lib.rs |
179 | mod $0 { | 179 | mod $0 { |
180 | 180 | ||
181 | } | 181 | } |
182 | //- /foo.rs | 182 | //- /foo.rs |
183 | fn foo() {} | 183 | fn foo() {} |
184 | "#, | 184 | "#, |
185 | expect![[r#""#]], | 185 | expect![[r#""#]], |
186 | ); | 186 | ); |
187 | } | 187 | } |
@@ -190,17 +190,17 @@ mod tests { | |||
190 | fn main_module_completion() { | 190 | fn main_module_completion() { |
191 | check( | 191 | check( |
192 | r#" | 192 | r#" |
193 | //- /main.rs | 193 | //- /main.rs |
194 | mod $0 | 194 | mod $0 |
195 | //- /foo.rs | 195 | //- /foo.rs |
196 | fn foo() {} | 196 | fn foo() {} |
197 | //- /foo/ignored_foo.rs | 197 | //- /foo/ignored_foo.rs |
198 | fn ignored_foo() {} | 198 | fn ignored_foo() {} |
199 | //- /bar/mod.rs | 199 | //- /bar/mod.rs |
200 | fn bar() {} | 200 | fn bar() {} |
201 | //- /bar/ignored_bar.rs | 201 | //- /bar/ignored_bar.rs |
202 | fn ignored_bar() {} | 202 | fn ignored_bar() {} |
203 | "#, | 203 | "#, |
204 | expect![[r#" | 204 | expect![[r#" |
205 | md foo; | 205 | md foo; |
206 | md bar; | 206 | md bar; |
@@ -212,13 +212,13 @@ mod tests { | |||
212 | fn main_test_module_completion() { | 212 | fn main_test_module_completion() { |
213 | check( | 213 | check( |
214 | r#" | 214 | r#" |
215 | //- /main.rs | 215 | //- /main.rs |
216 | mod tests { | 216 | mod tests { |
217 | mod $0; | 217 | mod $0; |
218 | } | 218 | } |
219 | //- /tests/foo.rs | 219 | //- /tests/foo.rs |
220 | fn foo() {} | 220 | fn foo() {} |
221 | "#, | 221 | "#, |
222 | expect![[r#" | 222 | expect![[r#" |
223 | md foo | 223 | md foo |
224 | "#]], | 224 | "#]], |
@@ -229,19 +229,19 @@ mod tests { | |||
229 | fn directly_nested_module_completion() { | 229 | fn directly_nested_module_completion() { |
230 | check( | 230 | check( |
231 | r#" | 231 | r#" |
232 | //- /lib.rs | 232 | //- /lib.rs |
233 | mod foo; | 233 | mod foo; |
234 | //- /foo.rs | 234 | //- /foo.rs |
235 | mod $0; | 235 | mod $0; |
236 | //- /foo/bar.rs | 236 | //- /foo/bar.rs |
237 | fn bar() {} | 237 | fn bar() {} |
238 | //- /foo/bar/ignored_bar.rs | 238 | //- /foo/bar/ignored_bar.rs |
239 | fn ignored_bar() {} | 239 | fn ignored_bar() {} |
240 | //- /foo/baz/mod.rs | 240 | //- /foo/baz/mod.rs |
241 | fn baz() {} | 241 | fn baz() {} |
242 | //- /foo/moar/ignored_moar.rs | 242 | //- /foo/moar/ignored_moar.rs |
243 | fn ignored_moar() {} | 243 | fn ignored_moar() {} |
244 | "#, | 244 | "#, |
245 | expect![[r#" | 245 | expect![[r#" |
246 | md bar | 246 | md bar |
247 | md baz | 247 | md baz |
@@ -253,15 +253,15 @@ mod tests { | |||
253 | fn nested_in_source_module_completion() { | 253 | fn nested_in_source_module_completion() { |
254 | check( | 254 | check( |
255 | r#" | 255 | r#" |
256 | //- /lib.rs | 256 | //- /lib.rs |
257 | mod foo; | 257 | mod foo; |
258 | //- /foo.rs | 258 | //- /foo.rs |
259 | mod bar { | 259 | mod bar { |
260 | mod $0 | 260 | mod $0 |
261 | } | 261 | } |
262 | //- /foo/bar/baz.rs | 262 | //- /foo/bar/baz.rs |
263 | fn baz() {} | 263 | fn baz() {} |
264 | "#, | 264 | "#, |
265 | expect![[r#" | 265 | expect![[r#" |
266 | md baz; | 266 | md baz; |
267 | "#]], | 267 | "#]], |
@@ -299,16 +299,16 @@ mod tests { | |||
299 | fn already_declared_bin_module_completion_omitted() { | 299 | fn already_declared_bin_module_completion_omitted() { |
300 | check( | 300 | check( |
301 | r#" | 301 | r#" |
302 | //- /src/bin.rs crate:main | 302 | //- /src/bin.rs crate:main |
303 | fn main() {} | 303 | fn main() {} |
304 | //- /src/bin/foo.rs | 304 | //- /src/bin/foo.rs |
305 | mod $0 | 305 | mod $0 |
306 | //- /src/bin/bar.rs | 306 | //- /src/bin/bar.rs |
307 | mod foo; | 307 | mod foo; |
308 | fn bar() {} | 308 | fn bar() {} |
309 | //- /src/bin/bar/bar_ignored.rs | 309 | //- /src/bin/bar/bar_ignored.rs |
310 | fn bar_ignored() {} | 310 | fn bar_ignored() {} |
311 | "#, | 311 | "#, |
312 | expect![[r#""#]], | 312 | expect![[r#""#]], |
313 | ); | 313 | ); |
314 | } | 314 | } |
diff --git a/crates/ide_completion/src/completions/qualified_path.rs b/crates/ide_completion/src/completions/qualified_path.rs index 0597879ac..88f4d940d 100644 --- a/crates/ide_completion/src/completions/qualified_path.rs +++ b/crates/ide_completion/src/completions/qualified_path.rs | |||
@@ -556,26 +556,6 @@ fn f() {m::$0} | |||
556 | } | 556 | } |
557 | 557 | ||
558 | #[test] | 558 | #[test] |
559 | fn completes_in_assoc_item_list() { | ||
560 | check( | ||
561 | r#" | ||
562 | #[macro_export] | ||
563 | macro_rules! foo { () => {} } | ||
564 | mod bar {} | ||
565 | |||
566 | struct MyStruct {} | ||
567 | impl MyStruct { | ||
568 | crate::$0 | ||
569 | } | ||
570 | "#, | ||
571 | expect![[r##" | ||
572 | md bar | ||
573 | ma foo!(…) #[macro_export] macro_rules! foo | ||
574 | "##]], | ||
575 | ); | ||
576 | } | ||
577 | |||
578 | #[test] | ||
579 | fn completes_reexported_items_under_correct_name() { | 559 | fn completes_reexported_items_under_correct_name() { |
580 | check( | 560 | check( |
581 | r#" | 561 | r#" |
diff --git a/crates/ide_completion/src/completions/snippet.rs b/crates/ide_completion/src/completions/snippet.rs index 81ddfa34f..cbc20cc2c 100644 --- a/crates/ide_completion/src/completions/snippet.rs +++ b/crates/ide_completion/src/completions/snippet.rs | |||
@@ -36,7 +36,11 @@ pub(crate) fn complete_expr_snippet(acc: &mut Completions, ctx: &CompletionConte | |||
36 | } | 36 | } |
37 | 37 | ||
38 | pub(crate) fn complete_item_snippet(acc: &mut Completions, ctx: &CompletionContext) { | 38 | pub(crate) fn complete_item_snippet(acc: &mut Completions, ctx: &CompletionContext) { |
39 | if !ctx.expects_item() || ctx.previous_token_is(T![unsafe]) || ctx.path_qual().is_some() { | 39 | if !ctx.expects_item() |
40 | || ctx.previous_token_is(T![unsafe]) | ||
41 | || ctx.path_qual().is_some() | ||
42 | || ctx.has_impl_or_trait_prev_sibling() | ||
43 | { | ||
40 | return; | 44 | return; |
41 | } | 45 | } |
42 | if ctx.has_visibility_prev_sibling() { | 46 | if ctx.has_visibility_prev_sibling() { |
diff --git a/crates/ide_completion/src/completions/unqualified_path.rs b/crates/ide_completion/src/completions/unqualified_path.rs index 6f96eceb9..8ea5a2d5b 100644 --- a/crates/ide_completion/src/completions/unqualified_path.rs +++ b/crates/ide_completion/src/completions/unqualified_path.rs | |||
@@ -6,7 +6,7 @@ use syntax::{ast, AstNode}; | |||
6 | use crate::{patterns::ImmediateLocation, CompletionContext, Completions}; | 6 | use crate::{patterns::ImmediateLocation, CompletionContext, Completions}; |
7 | 7 | ||
8 | pub(crate) fn complete_unqualified_path(acc: &mut Completions, ctx: &CompletionContext) { | 8 | pub(crate) fn complete_unqualified_path(acc: &mut Completions, ctx: &CompletionContext) { |
9 | if ctx.is_path_disallowed() || !ctx.is_trivial_path() { | 9 | if ctx.is_path_disallowed() || !ctx.is_trivial_path() || ctx.has_impl_or_trait_prev_sibling() { |
10 | return; | 10 | return; |
11 | } | 11 | } |
12 | 12 | ||
@@ -68,6 +68,9 @@ pub(crate) fn complete_unqualified_path(acc: &mut Completions, ctx: &CompletionC | |||
68 | return; | 68 | return; |
69 | } | 69 | } |
70 | let add_resolution = match res { | 70 | let add_resolution = match res { |
71 | ScopeDef::ImplSelfType(_) => { | ||
72 | !ctx.previous_token_is(syntax::T![impl]) && !ctx.previous_token_is(syntax::T![for]) | ||
73 | } | ||
71 | // Don't suggest attribute macros and derives. | 74 | // Don't suggest attribute macros and derives. |
72 | ScopeDef::MacroDef(mac) => mac.is_fn_like(), | 75 | ScopeDef::MacroDef(mac) => mac.is_fn_like(), |
73 | // no values in type places | 76 | // no values in type places |
@@ -713,23 +716,6 @@ fn f() {} | |||
713 | } | 716 | } |
714 | 717 | ||
715 | #[test] | 718 | #[test] |
716 | fn completes_target_type_or_trait_in_impl_block() { | ||
717 | check( | ||
718 | r#" | ||
719 | trait MyTrait {} | ||
720 | struct MyStruct {} | ||
721 | |||
722 | impl My$0 | ||
723 | "#, | ||
724 | expect![[r#" | ||
725 | sp Self | ||
726 | tt MyTrait | ||
727 | st MyStruct | ||
728 | "#]], | ||
729 | ) | ||
730 | } | ||
731 | |||
732 | #[test] | ||
733 | fn completes_types_and_const_in_arg_list() { | 719 | fn completes_types_and_const_in_arg_list() { |
734 | check( | 720 | check( |
735 | r#" | 721 | r#" |