summaryrefslogtreecommitdiff
path: root/internal/lsp/handlers_test.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2025-08-16 23:29:37 +0300
committerPaul Buetow <paul@buetow.org>2025-08-16 23:29:37 +0300
commit4974b40bd5126cb4215580c0d066057a973f50d1 (patch)
tree0c0febd66e4a59ae713d927474b46fdc4f0592b7 /internal/lsp/handlers_test.go
parent765eda955eb811d08d867ff4d3914fc6d60c22dd (diff)
feat(lsp): code action to rewrite selection with instruction detection
- Adds textDocument/codeAction handler that rewrites the selected range.\n- Instruction preference: strict ;text; marker first, then //, #, -- line comments, then single-line block comments (/* */ and <!-- -->). Earliest in the selection wins.\n- Removes the matched instruction from the selection before sending to LLM.\n- README: document code action workflow and instruction formats.
Diffstat (limited to 'internal/lsp/handlers_test.go')
-rw-r--r--internal/lsp/handlers_test.go34
1 files changed, 34 insertions, 0 deletions
diff --git a/internal/lsp/handlers_test.go b/internal/lsp/handlers_test.go
index 3ebddfb..0b12611 100644
--- a/internal/lsp/handlers_test.go
+++ b/internal/lsp/handlers_test.go
@@ -204,3 +204,37 @@ func TestCollectPromptRemovalEdits_SkipSpacedDouble(t *testing.T) {
t.Fatalf("expected 0 edits for spaced double-semicolon trigger, got %d", len(edits))
}
}
+
+func TestInstructionFromSelection_OrderPreference(t *testing.T) {
+ // Earliest wins within a line
+ line := "code /*block first*/ // later ;tag;"
+ instr, cleaned := instructionFromSelection(line)
+ if instr != "block first" {
+ t.Fatalf("want block comment instr, got %q", instr)
+ }
+ if strings.Contains(cleaned, "block first") {
+ t.Fatalf("cleaned should not contain the block comment")
+ }
+}
+
+func TestInstructionFromSelection_SemicolonBeatsCommentIfEarlier(t *testing.T) {
+ line := ";do this;// later"
+ instr, cleaned := instructionFromSelection(line)
+ if instr != "do this" {
+ t.Fatalf("want semicolon instr, got %q", instr)
+ }
+ if strings.Contains(cleaned, ";do this;") {
+ t.Fatalf("cleaned should have semicolon tag removed")
+ }
+}
+
+func TestInstructionFromSelection_HTMLAndLineComments(t *testing.T) {
+ line := "prefix <!-- html note --> suffix"
+ instr, cleaned := instructionFromSelection(line)
+ if instr != "html note" {
+ t.Fatalf("want html note, got %q", instr)
+ }
+ if strings.Contains(cleaned, "<!--") || strings.Contains(cleaned, "-->") {
+ t.Fatalf("cleaned should remove html comment markers")
+ }
+}