(fixture: &ParsedFixture)
| 403 | // ─── Feature runners ──────────────────────────────────────────────────────── |
| 404 | |
| 405 | async fn run_completion(fixture: &ParsedFixture) -> Result<(), String> { |
| 406 | let backend = create_fixture_backend(); |
| 407 | let uri = open_files(&backend, fixture).await; |
| 408 | |
| 409 | let position = Position { |
| 410 | line: fixture.cursor_line, |
| 411 | character: fixture.cursor_char, |
| 412 | }; |
| 413 | |
| 414 | let params = CompletionParams { |
| 415 | text_document_position: TextDocumentPositionParams { |
| 416 | text_document: TextDocumentIdentifier { uri }, |
| 417 | position, |
| 418 | }, |
| 419 | work_done_progress_params: WorkDoneProgressParams::default(), |
| 420 | partial_result_params: PartialResultParams::default(), |
| 421 | context: None, |
| 422 | }; |
| 423 | |
| 424 | let response = backend |
| 425 | .completion(params) |
| 426 | .await |
| 427 | .map_err(|e| format!("Completion request failed: {e}"))?; |
| 428 | |
| 429 | let items = match response { |
| 430 | Some(CompletionResponse::Array(items)) => items, |
| 431 | Some(CompletionResponse::List(list)) => list.items, |
| 432 | None => Vec::new(), |
| 433 | }; |
| 434 | |
| 435 | let labels: Vec<String> = items.iter().map(|item| item.label.clone()).collect(); |
| 436 | |
| 437 | // Check expected items are present. |
| 438 | for expected in &fixture.meta.expect { |
| 439 | let found = labels |
| 440 | .iter() |
| 441 | .any(|label| label.starts_with(expected.as_str())); |
| 442 | if !found { |
| 443 | return Err(format!( |
| 444 | "Expected completion label starting with `{expected}` not found.\nGot: {labels:?}" |
| 445 | )); |
| 446 | } |
| 447 | } |
| 448 | |
| 449 | // Check absent items are not present. |
| 450 | for absent in &fixture.meta.expect_absent { |
| 451 | let found = labels |
| 452 | .iter() |
| 453 | .any(|label| label.starts_with(absent.as_str())); |
| 454 | if found { |
| 455 | return Err(format!( |
| 456 | "Completion label starting with `{absent}` should NOT be present.\nGot: {labels:?}" |
| 457 | )); |
| 458 | } |
| 459 | } |
| 460 | |
| 461 | if fixture.meta.expect.is_empty() && fixture.meta.expect_absent.is_empty() { |
| 462 | return Err( |
no test coverage detected