diff options
| author | Paul Buetow <paul@buetow.org> | 2025-09-06 10:56:27 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2025-09-06 10:56:27 +0300 |
| commit | 320de746f7a2985b60c8564a0e65bdf231e840b7 (patch) | |
| tree | e70bcf50813dba411afa2934e774383124bbc99e /internal/lsp/diagnostics_action_test.go | |
| parent | 06247527d5170f329b454b42f59a3e4434ab1f4b (diff) | |
use gofumpt
Diffstat (limited to 'internal/lsp/diagnostics_action_test.go')
| -rw-r--r-- | internal/lsp/diagnostics_action_test.go | 49 |
1 files changed, 26 insertions, 23 deletions
diff --git a/internal/lsp/diagnostics_action_test.go b/internal/lsp/diagnostics_action_test.go index 1a9201f..a607b86 100644 --- a/internal/lsp/diagnostics_action_test.go +++ b/internal/lsp/diagnostics_action_test.go @@ -1,30 +1,33 @@ package lsp import ( - "encoding/json" - "io" - "log" - "testing" + "encoding/json" + "io" + "log" + "testing" ) func TestHandleCodeAction_ListsDiagnosticsActionWhenOverlap(t *testing.T) { - s := &Server{logger: log.New(io.Discard, "", 0), docs: make(map[string]*document)} - s.llmClient = fakeLLM{resp: "fixed"} - uri := "file:///x.go" - s.setDocument(uri, "package p\nvar a=1\n") - // Selection overlaps line 1 - sel := Range{Start: Position{Line:1, Character:0}, End: Position{Line:1, Character:5}} - // Provide diagnostics in the action context with one overlapping - ctx := CodeActionContext{Diagnostics: []Diagnostic{ - {Range: Range{Start: Position{Line:1, Character:0}, End: Position{Line:1, Character:3}}, Message: "in"}, - {Range: Range{Start: Position{Line:0, Character:0}, End: Position{Line:0, Character:1}}, Message: "out"}, - }} - rawCtx, _ := json.Marshal(ctx) - p := CodeActionParams{TextDocument: TextDocumentIdentifier{URI: uri}, Range: sel, Context: json.RawMessage(rawCtx)} - ca := s.buildDiagnosticsCodeAction(p, "var a=1") - if ca == nil { t.Fatalf("expected diagnostics action") } - // Resolve should produce an edit - resolved, ok := s.resolveCodeAction(*ca) - if !ok || resolved.Edit == nil { t.Fatalf("expected resolved edit from diagnostics") } + s := &Server{logger: log.New(io.Discard, "", 0), docs: make(map[string]*document)} + s.llmClient = fakeLLM{resp: "fixed"} + uri := "file:///x.go" + s.setDocument(uri, "package p\nvar a=1\n") + // Selection overlaps line 1 + sel := Range{Start: Position{Line: 1, Character: 0}, End: Position{Line: 1, Character: 5}} + // Provide diagnostics in the action context with one overlapping + ctx := CodeActionContext{Diagnostics: []Diagnostic{ + {Range: Range{Start: Position{Line: 1, Character: 0}, End: Position{Line: 1, Character: 3}}, Message: "in"}, + {Range: Range{Start: Position{Line: 0, Character: 0}, End: Position{Line: 0, Character: 1}}, Message: "out"}, + }} + rawCtx, _ := json.Marshal(ctx) + p := CodeActionParams{TextDocument: TextDocumentIdentifier{URI: uri}, Range: sel, Context: json.RawMessage(rawCtx)} + ca := s.buildDiagnosticsCodeAction(p, "var a=1") + if ca == nil { + t.Fatalf("expected diagnostics action") + } + // Resolve should produce an edit + resolved, ok := s.resolveCodeAction(*ca) + if !ok || resolved.Edit == nil { + t.Fatalf("expected resolved edit from diagnostics") + } } - |
