diff options
| author | Paul Buetow <paul@buetow.org> | 2025-08-19 23:00:05 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2025-08-19 23:00:05 +0300 |
| commit | 7abb7c9177d34f3b2a1773624f0da7daa8c8e2de (patch) | |
| tree | e37c22be0cddb6eabb07efc9b0a582cab79e5898 /internal/lsp/codeaction_test.go | |
| parent | 904988e3a417b2d3adb88c749429e8685bb346d0 (diff) | |
lsp/codeactions: make actions lazy and resolve on selection\n\n- Advertise CodeAction resolveProvider and implement codeAction/resolve\n- Return lightweight actions with data; no LLM call during listing\n- On resolve, perform LLM and populate WorkspaceEdit\n- Update tests to cover lazy+resolve flow
Diffstat (limited to 'internal/lsp/codeaction_test.go')
| -rw-r--r-- | internal/lsp/codeaction_test.go | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/internal/lsp/codeaction_test.go b/internal/lsp/codeaction_test.go index e9abbb8..59b16d8 100644 --- a/internal/lsp/codeaction_test.go +++ b/internal/lsp/codeaction_test.go @@ -15,15 +15,20 @@ func (f fakeLLM) Chat(_ context.Context, _ []llm.Message, _ ...llm.RequestOption func (f fakeLLM) Name() string { return "fake" } func (f fakeLLM) DefaultModel() string { return "fake-model" } -func TestBuildRewriteCodeAction_ReturnsEdit(t *testing.T) { +func TestBuildRewriteCodeAction_LazyAndResolves(t *testing.T) { s := newTestServer() s.llmClient = fakeLLM{resp: "REWRITTEN"} p := CodeActionParams{TextDocument: TextDocumentIdentifier{URI: "file:///t.go"}, Range: Range{Start: Position{Line: 1, Character: 2}, End: Position{Line: 3, Character: 4}}} sel := ";rewrite;\nold code" ca := s.buildRewriteCodeAction(p, sel) if ca == nil { t.Fatalf("expected code action") } - if ca.Edit == nil || len(ca.Edit.Changes) == 0 { t.Fatalf("expected workspace edit with changes") } - edits := ca.Edit.Changes[p.TextDocument.URI] + // Should be lazy (no edit yet) + if ca.Edit != nil { t.Fatalf("expected nil Edit before resolve") } + if len(ca.Data) == 0 { t.Fatalf("expected data payload for lazy resolve") } + // Resolve now + resolved, ok := s.resolveCodeAction(*ca) + if !ok || resolved.Edit == nil { t.Fatalf("expected resolve to produce edit") } + edits := resolved.Edit.Changes[p.TextDocument.URI] if len(edits) != 1 { t.Fatalf("expected 1 edit, got %d", len(edits)) } if edits[0].Range != p.Range { t.Fatalf("edit range mismatch: got %+v want %+v", edits[0].Range, p.Range) } if edits[0].NewText == "" { t.Fatalf("expected non-empty replacement text") } @@ -37,7 +42,7 @@ func TestBuildRewriteCodeAction_NoInstruction(t *testing.T) { if ca := s.buildRewriteCodeAction(p, sel); ca != nil { t.Fatalf("expected nil action when no instruction present") } } -func TestBuildDiagnosticsCodeAction_ReturnsEdit(t *testing.T) { +func TestBuildDiagnosticsCodeAction_LazyAndResolves(t *testing.T) { s := newTestServer() s.llmClient = fakeLLM{resp: "FIXED"} p := CodeActionParams{TextDocument: TextDocumentIdentifier{URI: "file:///t.go"}, Range: Range{Start: Position{Line: 10}, End: Position{Line: 12, Character: 5}}} @@ -50,7 +55,10 @@ func TestBuildDiagnosticsCodeAction_ReturnsEdit(t *testing.T) { sel := "some selected code" ca := s.buildDiagnosticsCodeAction(p, sel) if ca == nil { t.Fatalf("expected diagnostics code action") } - if ca.Edit == nil || len(ca.Edit.Changes) == 0 { t.Fatalf("expected workspace edit") } + if ca.Edit != nil { t.Fatalf("expected lazy action without edit") } + if len(ca.Data) == 0 { t.Fatalf("expected data payload for lazy diagnostics action") } + resolved, ok := s.resolveCodeAction(*ca) + if !ok || resolved.Edit == nil { t.Fatalf("expected resolve to produce edit") } } func TestBuildDiagnosticsCodeAction_NoDiagnostics(t *testing.T) { |
