@@ -4,18 +4,25 @@ import (
44 "bufio"
55 "context"
66 "encoding/json"
7+ "errors"
78 "fmt"
89 "io"
910 "strings"
1011
1112 "github.com/isaacphi/mcp-language-server/internal/logging"
13+ "github.com/isaacphi/mcp-language-server/internal/protocol"
1214)
1315
1416// Create component-specific loggers
1517var lspLogger = logging .NewLogger (logging .LSP )
1618var wireLogger = logging .NewLogger (logging .LSPWire )
1719var processLogger = logging .NewLogger (logging .LSPProcess )
1820
21+ var (
22+ ErrContentModified = errors .New ("content modified" )
23+ ErrServerCancelled = errors .New ("server cancelled" )
24+ )
25+
1926// WriteMessage writes an LSP message to the given writer
2027func WriteMessage (w io.Writer , msg * Message ) error {
2128 data , err := json .Marshal (msg )
@@ -230,7 +237,14 @@ func (c *Client) Call(ctx context.Context, method string, params any, result any
230237
231238 if resp .Error != nil {
232239 lspLogger .Error ("Request failed: %s (code: %d)" , resp .Error .Message , resp .Error .Code )
233- return fmt .Errorf ("request failed: %s (code: %d)" , resp .Error .Message , resp .Error .Code )
240+ switch protocol .LSPErrorCodes (resp .Error .Code ) {
241+ case protocol .ContentModified :
242+ return ErrContentModified
243+ case protocol .ServerCancelled :
244+ return ErrServerCancelled
245+ default :
246+ return fmt .Errorf ("request failed: %s (code: %d)" , resp .Error .Message , resp .Error .Code )
247+ }
234248 }
235249
236250 if result != nil {
0 commit comments