From 3fc8eb7406774be6d60ec3fd8b290d4aa5dd3ade Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Tue, 27 Oct 2026 18:11:02 +0000 Subject: [PATCH] test(lsp): refactor quick fix code action lookup in LSP tests Co-authored-by: Tcode-Motion <188012755+Tcode-Motion@users.noreply.github.com> --- tools/lsp/tests/lsp_tests.rs | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/tools/lsp/tests/lsp_tests.rs b/tools/lsp/tests/lsp_tests.rs index 0b56e3b2..97d61492 100644 --- a/tools/lsp/tests/lsp_tests.rs +++ b/tools/lsp/tests/lsp_tests.rs @@ -177,23 +177,20 @@ async fn test_lsp_code_action_make_to_const() { let actions = res.unwrap(); // Find the quick fix action - let mut found = false; - for action in actions { - if let CodeActionOrCommand::CodeAction(a) = action { - if a.title.contains("immutable 'const'") { - found = true; - - let edits = a.edit.unwrap().changes.unwrap(); - let edits_for_uri = edits.get(&doc_uri).unwrap(); - - assert_eq!(edits_for_uri.len(), 1); - assert_eq!(edits_for_uri[0].new_text, "const "); - assert_eq!(edits_for_uri[0].range.start.line, 1); - assert_eq!(edits_for_uri[0].range.start.character, 4); - assert_eq!(edits_for_uri[0].range.end.character, 8); - } - } - } - - assert!(found, "Did not find the 'Change to const' quick fix"); + let action = actions + .into_iter() + .find_map(|action| match action { + CodeActionOrCommand::CodeAction(a) if a.title.contains("immutable 'const'") => Some(a), + _ => None, + }) + .expect("Did not find the 'Change to const' quick fix"); + + let edits = action.edit.unwrap().changes.unwrap(); + let edits_for_uri = edits.get(&doc_uri).unwrap(); + + assert_eq!(edits_for_uri.len(), 1); + assert_eq!(edits_for_uri[0].new_text, "const "); + assert_eq!(edits_for_uri[0].range.start.line, 1); + assert_eq!(edits_for_uri[0].range.start.character, 4); + assert_eq!(edits_for_uri[0].range.end.character, 8); }