Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide-completion/src/tests/special.rs')
-rw-r--r--crates/ide-completion/src/tests/special.rs73
1 files changed, 71 insertions, 2 deletions
diff --git a/crates/ide-completion/src/tests/special.rs b/crates/ide-completion/src/tests/special.rs
index e80a289049..83888e08f1 100644
--- a/crates/ide-completion/src/tests/special.rs
+++ b/crates/ide-completion/src/tests/special.rs
@@ -2,10 +2,15 @@
use expect_test::{expect, Expect};
-use crate::tests::{
- check_edit, completion_list, completion_list_no_kw, completion_list_with_trigger_character,
+use crate::{
+ tests::{
+ check_edit, completion_list, completion_list_no_kw, completion_list_with_trigger_character,
+ },
+ CompletionItemKind,
};
+use super::{do_completion_with_config, TEST_CONFIG};
+
fn check_no_kw(ra_fixture: &str, expect: Expect) {
let actual = completion_list_no_kw(ra_fixture);
expect.assert_eq(&actual)
@@ -1303,3 +1308,67 @@ struct Foo<T: PartialOrd
"#,
);
}
+
+fn check_signatures(src: &str, kind: CompletionItemKind, reduced: Expect, full: Expect) {
+ const FULL_SIGNATURES_CONFIG: crate::CompletionConfig = {
+ let mut x = TEST_CONFIG;
+ x.full_function_signatures = true;
+ x
+ };
+
+ // reduced signature
+ let completion = do_completion_with_config(TEST_CONFIG, src, kind);
+ assert!(completion[0].detail.is_some());
+ reduced.assert_eq(completion[0].detail.as_ref().unwrap());
+
+ // full signature
+ let completion = do_completion_with_config(FULL_SIGNATURES_CONFIG, src, kind);
+ assert!(completion[0].detail.is_some());
+ full.assert_eq(completion[0].detail.as_ref().unwrap());
+}
+
+#[test]
+fn respects_full_function_signatures() {
+ check_signatures(
+ r#"
+pub fn foo<'x, T>(x: &'x mut T) -> u8 where T: Clone, { 0u8 }
+fn main() { fo$0 }
+"#,
+ CompletionItemKind::SymbolKind(ide_db::SymbolKind::Function),
+ expect!("fn(&mut T) -> u8"),
+ expect!("pub fn foo<'x, T>(x: &'x mut T) -> u8 where T: Clone,"),
+ );
+
+ check_signatures(
+ r#"
+struct Foo;
+struct Bar;
+impl Bar {
+ pub const fn baz(x: Foo) -> ! { loop {} };
+}
+
+fn main() { Bar::b$0 }
+"#,
+ CompletionItemKind::SymbolKind(ide_db::SymbolKind::Function),
+ expect!("const fn(Foo) -> !"),
+ expect!("pub const fn baz(x: Foo) -> !"),
+ );
+
+ check_signatures(
+ r#"
+struct Foo;
+struct Bar;
+impl Bar {
+ pub const fn baz<'foo>(&'foo mut self, x: &'foo Foo) -> ! { loop {} };
+}
+
+fn main() {
+ let mut bar = Bar;
+ bar.b$0
+}
+"#,
+ CompletionItemKind::Method,
+ expect!("const fn(&'foo mut self, &Foo) -> !"),
+ expect!("pub const fn baz<'foo>(&'foo mut self, x: &'foo Foo) -> !"),
+ );
+}