diff options
| author | Paul Buetow <paul@buetow.org> | 2025-09-03 16:41:46 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2025-09-03 16:41:46 +0300 |
| commit | 3ee19139a95441a3ce10690377de8f453c7aec3f (patch) | |
| tree | b627097b2b2863e493e9ef0f9f4a88057c96c228 /internal/lsp/handlers_document.go | |
| parent | f3a1a41d92651d6d19ee6b078c0ffdc825015bde (diff) | |
lsp: add 'Hexai: implement unit test' code action for Gov0.4.1
- Generate or append tests to _test.go
- Jump to generated test via showDocument (command + server-initiated)
- Document the feature in docs/go-unit-tests.md
- Prefix action titles with 'Hexai: '
- Bump version to 0.4.1
Diffstat (limited to 'internal/lsp/handlers_document.go')
| -rw-r--r-- | internal/lsp/handlers_document.go | 39 |
1 files changed, 33 insertions, 6 deletions
diff --git a/internal/lsp/handlers_document.go b/internal/lsp/handlers_document.go index 53c1588..5b83d78 100644 --- a/internal/lsp/handlers_document.go +++ b/internal/lsp/handlers_document.go @@ -254,12 +254,12 @@ func stripTrailingTrigger(sx string) string { // clientApplyEdit sends a workspace/applyEdit request to the client. func (s *Server) clientApplyEdit(label string, edit WorkspaceEdit) { - params := ApplyWorkspaceEditParams{Label: label, Edit: edit} - id := s.nextReqID() - req := Request{JSONRPC: "2.0", ID: id, Method: "workspace/applyEdit"} - b, _ := json.Marshal(params) - req.Params = b - s.writeMessage(req) + params := ApplyWorkspaceEditParams{Label: label, Edit: edit} + id := s.nextReqID() + req := Request{JSONRPC: "2.0", ID: id, Method: "workspace/applyEdit"} + b, _ := json.Marshal(params) + req.Params = b + s.writeMessage(req) } // nextReqID returns a unique json.RawMessage id for server-initiated requests. @@ -271,3 +271,30 @@ func (s *Server) nextReqID() json.RawMessage { b, _ := json.Marshal(idNum) return b } + +// clientShowDocument asks the client to open/focus a document and select a range. +func (s *Server) clientShowDocument(uri string, sel *Range) { + var params struct { + URI string `json:"uri"` + External bool `json:"external,omitempty"` + TakeFocus bool `json:"takeFocus,omitempty"` + Selection *Range `json:"selection,omitempty"` + } + params.URI = uri + params.TakeFocus = true + params.Selection = sel + id := s.nextReqID() + req := Request{JSONRPC: "2.0", ID: id, Method: "window/showDocument"} + b, _ := json.Marshal(params) + req.Params = b + s.writeMessage(req) +} + +// deferShowDocument schedules a showDocument after a short delay to allow the client +// time to apply any pending edits (e.g., create the file before focusing it). +func (s *Server) deferShowDocument(uri string, sel Range) { + go func() { + time.Sleep(120 * time.Millisecond) + s.clientShowDocument(uri, &sel) + }() +} |
