From 88a877ba7910bd5ef64509c8d15b467e943ad8ad Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Tue, 8 Sep 2026 08:25:37 +0000 Subject: [PATCH] Fix falsely flagged TODO in LSP Code Actions comment Replaces the term "Quick Fix" with "Code Action" in `tools/lsp/src/lib.rs` to prevent automated issue trackers from incorrectly flagging the comment as an actionable TODO item. Additionally, adds a unit test to verify that the `make` to `const` quick fix functions correctly. Co-authored-by: Tcode-Motion <188012755+Tcode-Motion@users.noreply.github.com> --- tools/lsp/src/lib.rs | 4 +- tools/lsp/tests/lsp_tests.rs | 74 ++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 2 deletions(-) diff --git a/tools/lsp/src/lib.rs b/tools/lsp/src/lib.rs index 7ef4fad8..d35f0ff4 100644 --- a/tools/lsp/src/lib.rs +++ b/tools/lsp/src/lib.rs @@ -1403,7 +1403,7 @@ impl LanguageServer for Backend { let mut actions = Vec::new(); let uri = params.text_document.uri; - // Quick Fix 1: Organize Imports Action + // Code Action 1: Organize Imports let mut organize_edits = Vec::new(); organize_edits.push(TextEdit { range: Range { @@ -1427,7 +1427,7 @@ impl LanguageServer for Backend { ..Default::default() })); - // Quick Fix 2: Convert mutable "make" to immutable "const" + // Code Action 2: Convert mutable "make" to immutable "const" for diagnostic in params.context.diagnostics { if let Some(ref code) = diagnostic.code { if let NumberOrString::String(ref s) = code { diff --git a/tools/lsp/tests/lsp_tests.rs b/tools/lsp/tests/lsp_tests.rs index 5b7bb6ef..0b56e3b2 100644 --- a/tools/lsp/tests/lsp_tests.rs +++ b/tools/lsp/tests/lsp_tests.rs @@ -123,3 +123,77 @@ async fn test_lsp_formatting() { let new_text = &res[0].new_text; assert!(new_text.contains(" say 42")); } + +#[tokio::test] +async fn test_lsp_code_action_make_to_const() { + let (service, _) = LspService::new(Backend::new); + + let doc_uri = Url::parse("file:///main.txs").unwrap(); + service + .inner() + .did_open(DidOpenTextDocumentParams { + text_document: TextDocumentItem { + uri: doc_uri.clone(), + language_id: "techscript".to_string(), + version: 1, + text: "build main() {\n make x = 10\n}".to_string(), + }, + }) + .await; + + let res = service + .inner() + .code_action(CodeActionParams { + text_document: TextDocumentIdentifier { + uri: doc_uri.clone(), + }, + range: Range::default(), + context: CodeActionContext { + diagnostics: vec![Diagnostic { + range: Range { + start: Position::new(1, 4), + end: Position::new(1, 8), + }, + severity: Some(DiagnosticSeverity::WARNING), + code: Some(NumberOrString::String("warning".to_string())), + code_description: None, + source: Some("techscript".to_string()), + message: "Variable is never mutated. Consider using `const`".to_string(), + related_information: None, + tags: None, + data: None, + }], + only: None, + trigger_kind: None, + }, + work_done_progress_params: Default::default(), + partial_result_params: Default::default(), + }) + .await + .unwrap(); + + println!("{:#?}", res); + + 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"); +}