Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions internal/lsp/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ import (
)

type Client struct {
Cmd *exec.Cmd
stdin io.WriteCloser
stdout *bufio.Reader
stderr io.ReadCloser
Cmd *exec.Cmd
stdin io.WriteCloser
stdinMu sync.Mutex
stdout *bufio.Reader
stderr io.ReadCloser

// Request ID counter
nextID atomic.Int32
Expand Down
15 changes: 12 additions & 3 deletions internal/lsp/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,10 @@ func (c *Client) handleMessages() {
}

// Send response back to server
if err := WriteMessage(c.stdin, response); err != nil {
c.stdinMu.Lock()
err := WriteMessage(c.stdin, response)
c.stdinMu.Unlock()
if err != nil {
lspLogger.Error("Error sending response to server: %v", err)
}

Expand Down Expand Up @@ -217,7 +220,10 @@ func (c *Client) Call(ctx context.Context, method string, params any, result any
}()

// Send request
if err := WriteMessage(c.stdin, msg); err != nil {
c.stdinMu.Lock()
err = WriteMessage(c.stdin, msg)
c.stdinMu.Unlock()
if err != nil {
return fmt.Errorf("failed to send request: %w", err)
}

Expand Down Expand Up @@ -258,7 +264,10 @@ func (c *Client) Notify(ctx context.Context, method string, params any) error {
return fmt.Errorf("failed to create notification: %w", err)
}

if err := WriteMessage(c.stdin, msg); err != nil {
c.stdinMu.Lock()
err = WriteMessage(c.stdin, msg)
c.stdinMu.Unlock()
if err != nil {
return fmt.Errorf("failed to send notification: %w", err)
}

Expand Down