Skip to content

Commit 61ebc5a

Browse files
authored
Generate LSP request IDs atomically (#1162)
1 parent b00279c commit 61ebc5a

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

internal/lsp/server.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"runtime/debug"
1212
"slices"
1313
"sync"
14+
"sync/atomic"
1415
"syscall"
1516

1617
"github.com/microsoft/typescript-go/internal/collections"
@@ -124,7 +125,7 @@ type Server struct {
124125

125126
stderr io.Writer
126127

127-
clientSeq int32
128+
clientSeq atomic.Int32
128129
requestQueue chan *lsproto.RequestMessage
129130
outgoingQueue chan *lsproto.Message
130131
pendingClientRequests map[lsproto.ID]pendingClientRequest
@@ -399,8 +400,7 @@ func (s *Server) writeLoop(ctx context.Context) error {
399400
}
400401

401402
func (s *Server) sendRequest(ctx context.Context, method lsproto.Method, params any) (any, error) {
402-
s.clientSeq++
403-
id := lsproto.NewIDString(fmt.Sprintf("ts%d", s.clientSeq))
403+
id := lsproto.NewIDString(fmt.Sprintf("ts%d", s.clientSeq.Add(1)))
404404
req := lsproto.NewRequestMessage(method, id, params)
405405

406406
responseChan := make(chan *lsproto.ResponseMessage, 1)

0 commit comments

Comments
 (0)