summaryrefslogtreecommitdiff
path: root/internal/lsp/handlers_test.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2025-08-16 23:16:54 +0300
committerPaul Buetow <paul@buetow.org>2025-08-16 23:16:54 +0300
commit765eda955eb811d08d867ff4d3914fc6d60c22dd (patch)
treefdc87da6af9d86dbda2ea9ab08244e93fd167188 /internal/lsp/handlers_test.go
parent1b01e35c34b953cbf51298f4650dc3215c382a4f (diff)
refactor(config): drop env-based config (except OPENAI_API_KEY)
- Switch to config-file-only; only OPENAI_API_KEY read from env.\n- llm: replace env autodetect with Config + NewFromConfig; add newOpenAI/newOllama.\n- lsp: NewServer now accepts injected llm.Client.\n- cli: remove env overrides; extend appConfig with provider-specific fields; build client from config + OPENAI_API_KEY.\n- docs: update README (config-only, defaults to OpenAI, minimal example); simplify flags table.\n- add config.json.example.\n- prompts: enforce ;text; (no spaces) and add ;;text; to remove entire line; tests added.
Diffstat (limited to 'internal/lsp/handlers_test.go')
-rw-r--r--internal/lsp/handlers_test.go57
1 files changed, 57 insertions, 0 deletions
diff --git a/internal/lsp/handlers_test.go b/internal/lsp/handlers_test.go
index 6ce1e5d..3ebddfb 100644
--- a/internal/lsp/handlers_test.go
+++ b/internal/lsp/handlers_test.go
@@ -147,3 +147,60 @@ no markers here`
t.Fatalf("e0 start not at ;")
}
}
+
+func TestCollectPromptRemovalEdits_SkipSpacedMarkers(t *testing.T) {
+ s := newTestServer()
+ uri := "file:///y.go"
+ // Only ;ok; should be removed; "; spaced ;" must be ignored
+ src := `prefix ;ok; middle ; spaced ; suffix`
+ s.setDocument(uri, src)
+ edits := s.collectPromptRemovalEdits(uri)
+ if len(edits) != 1 {
+ t.Fatalf("expected 1 edit (only ;ok;), got %d", len(edits))
+ }
+ // Ensure the removed region starts at the first ';' of ;ok;
+ line := s.getDocument(uri).lines[0]
+ wantStart := strings.Index(line, ";ok;")
+ if wantStart < 0 {
+ t.Fatalf("test setup: could not find ;ok; in %q", line)
+ }
+ if edits[0].Range.Start.Line != 0 || edits[0].Range.Start.Character != wantStart {
+ t.Fatalf("unexpected first edit start: got line=%d char=%d want line=0 char=%d", edits[0].Range.Start.Line, edits[0].Range.Start.Character, wantStart)
+ }
+}
+
+func TestCollectPromptRemovalEdits_DoubleSemicolonRemovesWholeLine(t *testing.T) {
+ s := newTestServer()
+ uri := "file:///z.go"
+ line0 := "keep"
+ line1 := ";;todo; remove this whole line"
+ line2 := "keep ;ok; end"
+ src := strings.Join([]string{line0, line1, line2}, "\n")
+ s.setDocument(uri, src)
+ edits := s.collectPromptRemovalEdits(uri)
+ if len(edits) != 2 {
+ t.Fatalf("expected 2 edits (whole line + ;ok;), got %d", len(edits))
+ }
+ // Find the whole-line removal for line1
+ found := false
+ for _, e := range edits {
+ if e.Range.Start.Line == 1 && e.Range.Start.Character == 0 && e.Range.End.Line == 1 && e.Range.End.Character == len(line1) {
+ found = true
+ break
+ }
+ }
+ if !found {
+ t.Fatalf("did not find whole-line removal edit for line 1")
+ }
+}
+
+func TestCollectPromptRemovalEdits_SkipSpacedDouble(t *testing.T) {
+ s := newTestServer()
+ uri := "file:///w.go"
+ src := "prefix ;; spaced ; suffix"
+ s.setDocument(uri, src)
+ edits := s.collectPromptRemovalEdits(uri)
+ if len(edits) != 0 {
+ t.Fatalf("expected 0 edits for spaced double-semicolon trigger, got %d", len(edits))
+ }
+}