aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_completion
diff options
context:
space:
mode:
authorLukas Wirth <[email protected]>2021-06-17 14:10:25 +0100
committerLukas Wirth <[email protected]>2021-06-17 14:10:25 +0100
commit9df848c58079a710869dcde2692466cc4b0ac78e (patch)
tree7e2e2318fa0635d619ae310cb78bb220d9aaaad5 /crates/ide_completion
parentc82a9141abe6b6cbf5b55710dc8a315a3839081b (diff)
Less filtering in completion tests
Diffstat (limited to 'crates/ide_completion')
-rw-r--r--crates/ide_completion/src/completions/attribute.rs6
-rw-r--r--crates/ide_completion/src/completions/attribute/derive.rs7
-rw-r--r--crates/ide_completion/src/completions/attribute/lint.rs1
-rw-r--r--crates/ide_completion/src/completions/keyword.rs24
-rw-r--r--crates/ide_completion/src/completions/lifetime.rs14
-rw-r--r--crates/ide_completion/src/completions/mod_.rs134
-rw-r--r--crates/ide_completion/src/tests.rs8
7 files changed, 96 insertions, 98 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] = &[
82mod tests { 82mod 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 {}
106pub macro Ord {} 106pub 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)]
35mod tests { 35mod 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..af67f9315 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
53pub(crate) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionContext) { 42pub(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();
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) {
49mod tests { 49mod 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..dee3ec88d 100644
--- a/crates/ide_completion/src/completions/mod_.rs
+++ b/crates/ide_completion/src/completions/mod_.rs
@@ -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 157mod $0
158 //- /foo.rs 158//- /foo.rs
159 fn foo() {} 159fn foo() {}
160 //- /foo/ignored_foo.rs 160//- /foo/ignored_foo.rs
161 fn ignored_foo() {} 161fn ignored_foo() {}
162 //- /bar/mod.rs 162//- /bar/mod.rs
163 fn bar() {} 163fn bar() {}
164 //- /bar/ignored_bar.rs 164//- /bar/ignored_bar.rs
165 fn ignored_bar() {} 165fn 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 { 179mod $0 {
180 180
181 } 181}
182 //- /foo.rs 182//- /foo.rs
183 fn foo() {} 183fn 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 194mod $0
195 //- /foo.rs 195//- /foo.rs
196 fn foo() {} 196fn foo() {}
197 //- /foo/ignored_foo.rs 197//- /foo/ignored_foo.rs
198 fn ignored_foo() {} 198fn ignored_foo() {}
199 //- /bar/mod.rs 199//- /bar/mod.rs
200 fn bar() {} 200fn bar() {}
201 //- /bar/ignored_bar.rs 201//- /bar/ignored_bar.rs
202 fn ignored_bar() {} 202fn 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 { 216mod tests {
217 mod $0; 217 mod $0;
218 } 218}
219 //- /tests/foo.rs 219//- /tests/foo.rs
220 fn foo() {} 220fn 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; 233mod foo;
234 //- /foo.rs 234//- /foo.rs
235 mod $0; 235mod $0;
236 //- /foo/bar.rs 236//- /foo/bar.rs
237 fn bar() {} 237fn bar() {}
238 //- /foo/bar/ignored_bar.rs 238//- /foo/bar/ignored_bar.rs
239 fn ignored_bar() {} 239fn ignored_bar() {}
240 //- /foo/baz/mod.rs 240//- /foo/baz/mod.rs
241 fn baz() {} 241fn baz() {}
242 //- /foo/moar/ignored_moar.rs 242//- /foo/moar/ignored_moar.rs
243 fn ignored_moar() {} 243fn 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; 257mod foo;
258 //- /foo.rs 258//- /foo.rs
259 mod bar { 259mod bar {
260 mod $0 260 mod $0
261 } 261}
262 //- /foo/bar/baz.rs 262//- /foo/bar/baz.rs
263 fn baz() {} 263fn 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() {} 303fn main() {}
304 //- /src/bin/foo.rs 304//- /src/bin/foo.rs
305 mod $0 305mod $0
306 //- /src/bin/bar.rs 306//- /src/bin/bar.rs
307 mod foo; 307mod foo;
308 fn bar() {} 308fn bar() {}
309 //- /src/bin/bar/bar_ignored.rs 309//- /src/bin/bar/bar_ignored.rs
310 fn bar_ignored() {} 310fn bar_ignored() {}
311 "#, 311"#,
312 expect![[r#""#]], 312 expect![[r#""#]],
313 ); 313 );
314 } 314 }
diff --git a/crates/ide_completion/src/tests.rs b/crates/ide_completion/src/tests.rs
index 89c7fb524..4b7e19cc0 100644
--- a/crates/ide_completion/src/tests.rs
+++ b/crates/ide_completion/src/tests.rs
@@ -1,3 +1,9 @@
1//! Tests and test utilities for completions.
2//!
3//! Most tests live in this module or its submodules unless for very specific completions like
4//! `attributes` or `lifetimes` where the completed concept is a distinct thing.
5//! Notable examples for completions that are being tested in this module's submodule are paths.
6
1mod item_list; 7mod item_list;
2mod use_tree; 8mod use_tree;
3 9
@@ -32,7 +38,7 @@ pub(crate) const TEST_CONFIG: CompletionConfig = CompletionConfig {
32 }, 38 },
33}; 39};
34 40
35fn completion_list(code: &str) -> String { 41pub(crate) fn completion_list(code: &str) -> String {
36 completion_list_with_config(TEST_CONFIG, code) 42 completion_list_with_config(TEST_CONFIG, code)
37} 43}
38 44