|
2 | 2 |
|
3 | 3 | use expect_test::{expect, Expect};
|
4 | 4 |
|
5 |
| -use crate::tests::{ |
6 |
| - check_edit, completion_list, completion_list_no_kw, completion_list_with_trigger_character, |
| 5 | +use crate::{ |
| 6 | + tests::{ |
| 7 | + check_edit, completion_list, completion_list_no_kw, completion_list_with_trigger_character, |
| 8 | + }, |
| 9 | + CompletionItemKind, |
7 | 10 | };
|
8 | 11 |
|
| 12 | +use super::{do_completion_with_config, TEST_CONFIG}; |
| 13 | + |
9 | 14 | fn check_no_kw(ra_fixture: &str, expect: Expect) {
|
10 | 15 | let actual = completion_list_no_kw(ra_fixture);
|
11 | 16 | expect.assert_eq(&actual)
|
@@ -1303,3 +1308,67 @@ struct Foo<T: PartialOrd
|
1303 | 1308 | "#,
|
1304 | 1309 | );
|
1305 | 1310 | }
|
| 1311 | + |
| 1312 | +fn check_signatures(src: &str, kind: CompletionItemKind, reduced: Expect, full: Expect) { |
| 1313 | + const FULL_SIGNATURES_CONFIG: crate::CompletionConfig = { |
| 1314 | + let mut x = TEST_CONFIG; |
| 1315 | + x.full_function_signatures = true; |
| 1316 | + x |
| 1317 | + }; |
| 1318 | + |
| 1319 | + // reduced signature |
| 1320 | + let completion = do_completion_with_config(TEST_CONFIG, src, kind); |
| 1321 | + assert!(completion[0].detail.is_some()); |
| 1322 | + reduced.assert_eq(completion[0].detail.as_ref().unwrap()); |
| 1323 | + |
| 1324 | + // full signature |
| 1325 | + let completion = do_completion_with_config(FULL_SIGNATURES_CONFIG, src, kind); |
| 1326 | + assert!(completion[0].detail.is_some()); |
| 1327 | + full.assert_eq(completion[0].detail.as_ref().unwrap()); |
| 1328 | +} |
| 1329 | + |
| 1330 | +#[test] |
| 1331 | +fn respects_full_function_signatures() { |
| 1332 | + check_signatures( |
| 1333 | + r#" |
| 1334 | +pub fn foo<'x, T>(x: &'x mut T) -> u8 where T: Clone, { 0u8 } |
| 1335 | +fn main() { fo$0 } |
| 1336 | +"#, |
| 1337 | + CompletionItemKind::SymbolKind(ide_db::SymbolKind::Function), |
| 1338 | + expect!("fn(&mut T) -> u8"), |
| 1339 | + expect!("pub fn foo<'x, T>(x: &'x mut T) -> u8 where T: Clone,"), |
| 1340 | + ); |
| 1341 | + |
| 1342 | + check_signatures( |
| 1343 | + r#" |
| 1344 | +struct Foo; |
| 1345 | +struct Bar; |
| 1346 | +impl Bar { |
| 1347 | + pub const fn baz(x: Foo) -> ! { loop {} }; |
| 1348 | +} |
| 1349 | +
|
| 1350 | +fn main() { Bar::b$0 } |
| 1351 | +"#, |
| 1352 | + CompletionItemKind::SymbolKind(ide_db::SymbolKind::Function), |
| 1353 | + expect!("const fn(Foo) -> !"), |
| 1354 | + expect!("pub const fn baz(x: Foo) -> !"), |
| 1355 | + ); |
| 1356 | + |
| 1357 | + check_signatures( |
| 1358 | + r#" |
| 1359 | +struct Foo; |
| 1360 | +struct Bar; |
| 1361 | +impl Bar { |
| 1362 | + pub const fn baz<'foo>(&'foo mut self, x: &'foo Foo) -> ! { loop {} }; |
| 1363 | +} |
| 1364 | +
|
| 1365 | +fn main() { |
| 1366 | + let mut bar = Bar; |
| 1367 | + bar.b$0 |
| 1368 | +} |
| 1369 | +"#, |
| 1370 | + CompletionItemKind::Method, |
| 1371 | + expect!("const fn(&'foo mut self, &Foo) -> !"), |
| 1372 | + expect!("pub const fn baz<'foo>(&'foo mut self, x: &'foo Foo) -> !"), |
| 1373 | + ); |
| 1374 | +} |
0 commit comments