Less filtering in completion tests

This commit is contained in:
Lukas Wirth 2021-06-17 15:10:25 +02:00
parent c82a9141ab
commit 9df848c580
7 changed files with 96 additions and 98 deletions

View file

@ -322,7 +322,7 @@ mod tests {
use expect_test::{expect, Expect}; use expect_test::{expect, Expect};
use crate::{tests::filtered_completion_list, CompletionKind}; use crate::tests::completion_list;
#[test] #[test]
fn attributes_are_sorted() { fn attributes_are_sorted() {
@ -341,7 +341,7 @@ mod tests {
} }
fn check(ra_fixture: &str, expect: Expect) { 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); expect.assert_eq(&actual);
} }
@ -786,6 +786,7 @@ mod tests {
at target_feature = "" at target_feature = ""
at test at test
at track_caller at track_caller
kw return
"#]], "#]],
); );
} }
@ -801,6 +802,7 @@ mod tests {
at deny() at deny()
at forbid() at forbid()
at warn() at warn()
kw return
"#]], "#]],
); );
} }

View file

@ -82,7 +82,7 @@ const DEFAULT_DERIVE_COMPLETIONS: &[DeriveDependencies] = &[
mod tests { mod tests {
use expect_test::{expect, Expect}; use expect_test::{expect, Expect};
use crate::{tests::filtered_completion_list, CompletionKind}; use crate::tests::completion_list;
fn check(ra_fixture: &str, expect: Expect) { fn check(ra_fixture: &str, expect: Expect) {
let builtin_derives = r#" let builtin_derives = r#"
@ -106,10 +106,7 @@ pub macro PartialOrd {}
pub macro Ord {} pub macro Ord {}
"#; "#;
let actual = filtered_completion_list( let actual = completion_list(&format!("{} {}", builtin_derives, ra_fixture));
&format!("{} {}", builtin_derives, ra_fixture),
CompletionKind::Attribute,
);
expect.assert_eq(&actual); expect.assert_eq(&actual);
} }

View file

@ -33,7 +33,6 @@ pub(super) fn complete_lint(
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use crate::tests::check_edit; use crate::tests::check_edit;
#[test] #[test]

View file

@ -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) { 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); cov_mark::hit!(no_keyword_completion_in_record_lit);
return; 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 mut add_keyword = |kw, snippet| add_keyword(ctx, acc, kw, snippet);
let expects_assoc_item = ctx.expects_assoc_item(); let expects_assoc_item = ctx.expects_assoc_item();

View file

@ -49,19 +49,11 @@ pub(crate) fn complete_label(acc: &mut Completions, ctx: &CompletionContext) {
mod tests { mod tests {
use expect_test::{expect, Expect}; use expect_test::{expect, Expect};
use crate::{ use crate::tests::{check_edit, completion_list};
tests::{check_edit, filtered_completion_list_with_config, TEST_CONFIG},
CompletionConfig, CompletionKind,
};
fn check(ra_fixture: &str, expect: Expect) { fn check(ra_fixture: &str, expect: Expect) {
check_with_config(TEST_CONFIG, ra_fixture, expect); let actual = completion_list(ra_fixture);
} expect.assert_eq(&actual);
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)
} }
#[test] #[test]

View file

@ -153,17 +153,17 @@ mod tests {
fn lib_module_completion() { fn lib_module_completion() {
check( check(
r#" r#"
//- /lib.rs //- /lib.rs
mod $0 mod $0
//- /foo.rs //- /foo.rs
fn foo() {} fn foo() {}
//- /foo/ignored_foo.rs //- /foo/ignored_foo.rs
fn ignored_foo() {} fn ignored_foo() {}
//- /bar/mod.rs //- /bar/mod.rs
fn bar() {} fn bar() {}
//- /bar/ignored_bar.rs //- /bar/ignored_bar.rs
fn ignored_bar() {} fn ignored_bar() {}
"#, "#,
expect![[r#" expect![[r#"
md foo; md foo;
md bar; md bar;
@ -175,13 +175,13 @@ mod tests {
fn no_module_completion_with_module_body() { fn no_module_completion_with_module_body() {
check( check(
r#" r#"
//- /lib.rs //- /lib.rs
mod $0 { mod $0 {
} }
//- /foo.rs //- /foo.rs
fn foo() {} fn foo() {}
"#, "#,
expect![[r#""#]], expect![[r#""#]],
); );
} }
@ -190,17 +190,17 @@ mod tests {
fn main_module_completion() { fn main_module_completion() {
check( check(
r#" r#"
//- /main.rs //- /main.rs
mod $0 mod $0
//- /foo.rs //- /foo.rs
fn foo() {} fn foo() {}
//- /foo/ignored_foo.rs //- /foo/ignored_foo.rs
fn ignored_foo() {} fn ignored_foo() {}
//- /bar/mod.rs //- /bar/mod.rs
fn bar() {} fn bar() {}
//- /bar/ignored_bar.rs //- /bar/ignored_bar.rs
fn ignored_bar() {} fn ignored_bar() {}
"#, "#,
expect![[r#" expect![[r#"
md foo; md foo;
md bar; md bar;
@ -212,13 +212,13 @@ mod tests {
fn main_test_module_completion() { fn main_test_module_completion() {
check( check(
r#" r#"
//- /main.rs //- /main.rs
mod tests { mod tests {
mod $0; mod $0;
} }
//- /tests/foo.rs //- /tests/foo.rs
fn foo() {} fn foo() {}
"#, "#,
expect![[r#" expect![[r#"
md foo md foo
"#]], "#]],
@ -229,19 +229,19 @@ mod tests {
fn directly_nested_module_completion() { fn directly_nested_module_completion() {
check( check(
r#" r#"
//- /lib.rs //- /lib.rs
mod foo; mod foo;
//- /foo.rs //- /foo.rs
mod $0; mod $0;
//- /foo/bar.rs //- /foo/bar.rs
fn bar() {} fn bar() {}
//- /foo/bar/ignored_bar.rs //- /foo/bar/ignored_bar.rs
fn ignored_bar() {} fn ignored_bar() {}
//- /foo/baz/mod.rs //- /foo/baz/mod.rs
fn baz() {} fn baz() {}
//- /foo/moar/ignored_moar.rs //- /foo/moar/ignored_moar.rs
fn ignored_moar() {} fn ignored_moar() {}
"#, "#,
expect![[r#" expect![[r#"
md bar md bar
md baz md baz
@ -253,15 +253,15 @@ mod tests {
fn nested_in_source_module_completion() { fn nested_in_source_module_completion() {
check( check(
r#" r#"
//- /lib.rs //- /lib.rs
mod foo; mod foo;
//- /foo.rs //- /foo.rs
mod bar { mod bar {
mod $0 mod $0
} }
//- /foo/bar/baz.rs //- /foo/bar/baz.rs
fn baz() {} fn baz() {}
"#, "#,
expect![[r#" expect![[r#"
md baz; md baz;
"#]], "#]],
@ -299,16 +299,16 @@ mod tests {
fn already_declared_bin_module_completion_omitted() { fn already_declared_bin_module_completion_omitted() {
check( check(
r#" r#"
//- /src/bin.rs crate:main //- /src/bin.rs crate:main
fn main() {} fn main() {}
//- /src/bin/foo.rs //- /src/bin/foo.rs
mod $0 mod $0
//- /src/bin/bar.rs //- /src/bin/bar.rs
mod foo; mod foo;
fn bar() {} fn bar() {}
//- /src/bin/bar/bar_ignored.rs //- /src/bin/bar/bar_ignored.rs
fn bar_ignored() {} fn bar_ignored() {}
"#, "#,
expect![[r#""#]], expect![[r#""#]],
); );
} }

View file

@ -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 item_list;
mod use_tree; 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) completion_list_with_config(TEST_CONFIG, code)
} }