From 9df848c58079a710869dcde2692466cc4b0ac78e Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Thu, 17 Jun 2021 15:10:25 +0200 Subject: Less filtering in completion tests --- crates/ide_completion/src/completions/attribute.rs | 6 +- .../src/completions/attribute/derive.rs | 7 +- .../src/completions/attribute/lint.rs | 1 - crates/ide_completion/src/completions/keyword.rs | 24 ++-- crates/ide_completion/src/completions/lifetime.rs | 14 +-- crates/ide_completion/src/completions/mod_.rs | 134 ++++++++++----------- crates/ide_completion/src/tests.rs | 8 +- 7 files changed, 96 insertions(+), 98 deletions(-) (limited to 'crates/ide_completion/src') 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 { use expect_test::{expect, Expect}; - use crate::{tests::filtered_completion_list, CompletionKind}; + use crate::tests::completion_list; #[test] fn attributes_are_sorted() { @@ -341,7 +341,7 @@ mod tests { } fn check(ra_fixture: &str, expect: Expect) { - let actual = filtered_completion_list(ra_fixture, CompletionKind::Attribute); + let actual = completion_list(ra_fixture); expect.assert_eq(&actual); } @@ -786,6 +786,7 @@ mod tests { at target_feature = "…" at test at track_caller + kw return "#]], ); } @@ -801,6 +802,7 @@ mod tests { at deny(…) at forbid(…) at warn(…) + kw return "#]], ); } 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] = &[ mod tests { use expect_test::{expect, Expect}; - use crate::{tests::filtered_completion_list, CompletionKind}; + use crate::tests::completion_list; fn check(ra_fixture: &str, expect: Expect) { let builtin_derives = r#" @@ -106,10 +106,7 @@ pub macro PartialOrd {} pub macro Ord {} "#; - let actual = filtered_completion_list( - &format!("{} {}", builtin_derives, ra_fixture), - CompletionKind::Attribute, - ); + let actual = completion_list(&format!("{} {}", builtin_derives, ra_fixture)); expect.assert_eq(&actual); } 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( #[cfg(test)] mod tests { - use crate::tests::check_edit; #[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 } }; } - - // Suggest .await syntax for types that implement Future trait - if let Some(receiver) = ctx.dot_receiver() { - if let Some(ty) = ctx.sema.type_of_expr(receiver) { - if ty.impls_future(ctx.db) { - let mut item = kw_completion("await"); - item.detail("expr.await"); - item.add_to(acc); - } - }; - } } 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 cov_mark::hit!(no_keyword_completion_in_record_lit); return; } + + // Suggest .await syntax for types that implement Future trait + if let Some(receiver) = ctx.dot_receiver() { + if let Some(ty) = ctx.sema.type_of_expr(receiver) { + if ty.impls_future(ctx.db) { + let mut item = + CompletionItem::new(CompletionKind::Keyword, ctx.source_range(), "await"); + item.kind(CompletionItemKind::Keyword).detail("expr.await"); + item.add_to(acc); + } + }; + } + let mut add_keyword = |kw, snippet| add_keyword(ctx, acc, kw, snippet); 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) { mod tests { use expect_test::{expect, Expect}; - use crate::{ - tests::{check_edit, filtered_completion_list_with_config, TEST_CONFIG}, - CompletionConfig, CompletionKind, - }; + use crate::tests::{check_edit, completion_list}; fn check(ra_fixture: &str, expect: Expect) { - check_with_config(TEST_CONFIG, ra_fixture, expect); - } - - fn check_with_config(config: CompletionConfig, ra_fixture: &str, expect: Expect) { - let actual = - filtered_completion_list_with_config(config, ra_fixture, CompletionKind::Reference); - expect.assert_eq(&actual) + let actual = completion_list(ra_fixture); + expect.assert_eq(&actual); } #[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 { fn lib_module_completion() { check( r#" - //- /lib.rs - mod $0 - //- /foo.rs - fn foo() {} - //- /foo/ignored_foo.rs - fn ignored_foo() {} - //- /bar/mod.rs - fn bar() {} - //- /bar/ignored_bar.rs - fn ignored_bar() {} - "#, +//- /lib.rs +mod $0 +//- /foo.rs +fn foo() {} +//- /foo/ignored_foo.rs +fn ignored_foo() {} +//- /bar/mod.rs +fn bar() {} +//- /bar/ignored_bar.rs +fn ignored_bar() {} +"#, expect![[r#" md foo; md bar; @@ -175,13 +175,13 @@ mod tests { fn no_module_completion_with_module_body() { check( r#" - //- /lib.rs - mod $0 { +//- /lib.rs +mod $0 { - } - //- /foo.rs - fn foo() {} - "#, +} +//- /foo.rs +fn foo() {} +"#, expect![[r#""#]], ); } @@ -190,17 +190,17 @@ mod tests { fn main_module_completion() { check( r#" - //- /main.rs - mod $0 - //- /foo.rs - fn foo() {} - //- /foo/ignored_foo.rs - fn ignored_foo() {} - //- /bar/mod.rs - fn bar() {} - //- /bar/ignored_bar.rs - fn ignored_bar() {} - "#, +//- /main.rs +mod $0 +//- /foo.rs +fn foo() {} +//- /foo/ignored_foo.rs +fn ignored_foo() {} +//- /bar/mod.rs +fn bar() {} +//- /bar/ignored_bar.rs +fn ignored_bar() {} +"#, expect![[r#" md foo; md bar; @@ -212,13 +212,13 @@ mod tests { fn main_test_module_completion() { check( r#" - //- /main.rs - mod tests { - mod $0; - } - //- /tests/foo.rs - fn foo() {} - "#, +//- /main.rs +mod tests { + mod $0; +} +//- /tests/foo.rs +fn foo() {} +"#, expect![[r#" md foo "#]], @@ -229,19 +229,19 @@ mod tests { fn directly_nested_module_completion() { check( r#" - //- /lib.rs - mod foo; - //- /foo.rs - mod $0; - //- /foo/bar.rs - fn bar() {} - //- /foo/bar/ignored_bar.rs - fn ignored_bar() {} - //- /foo/baz/mod.rs - fn baz() {} - //- /foo/moar/ignored_moar.rs - fn ignored_moar() {} - "#, +//- /lib.rs +mod foo; +//- /foo.rs +mod $0; +//- /foo/bar.rs +fn bar() {} +//- /foo/bar/ignored_bar.rs +fn ignored_bar() {} +//- /foo/baz/mod.rs +fn baz() {} +//- /foo/moar/ignored_moar.rs +fn ignored_moar() {} +"#, expect![[r#" md bar md baz @@ -253,15 +253,15 @@ mod tests { fn nested_in_source_module_completion() { check( r#" - //- /lib.rs - mod foo; - //- /foo.rs - mod bar { - mod $0 - } - //- /foo/bar/baz.rs - fn baz() {} - "#, +//- /lib.rs +mod foo; +//- /foo.rs +mod bar { + mod $0 +} +//- /foo/bar/baz.rs +fn baz() {} +"#, expect![[r#" md baz; "#]], @@ -299,16 +299,16 @@ mod tests { fn already_declared_bin_module_completion_omitted() { check( r#" - //- /src/bin.rs crate:main - fn main() {} - //- /src/bin/foo.rs - mod $0 - //- /src/bin/bar.rs - mod foo; - fn bar() {} - //- /src/bin/bar/bar_ignored.rs - fn bar_ignored() {} - "#, +//- /src/bin.rs crate:main +fn main() {} +//- /src/bin/foo.rs +mod $0 +//- /src/bin/bar.rs +mod foo; +fn bar() {} +//- /src/bin/bar/bar_ignored.rs +fn bar_ignored() {} +"#, expect![[r#""#]], ); } 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 @@ +//! Tests and test utilities for completions. +//! +//! Most tests live in this module or its submodules unless for very specific completions like +//! `attributes` or `lifetimes` where the completed concept is a distinct thing. +//! Notable examples for completions that are being tested in this module's submodule are paths. + mod item_list; mod use_tree; @@ -32,7 +38,7 @@ pub(crate) const TEST_CONFIG: CompletionConfig = CompletionConfig { }, }; -fn completion_list(code: &str) -> String { +pub(crate) fn completion_list(code: &str) -> String { completion_list_with_config(TEST_CONFIG, code) } -- cgit v1.2.3