1
0
Fork 0
mirror of https://github.com/laravel-ls/protocol.git synced 2026-06-16 20:10:02 +02:00

adding LSP rcp error codes

This commit is contained in:
Henrik Hautakoski 2026-02-02 19:11:35 +01:00
parent 3ce51072ee
commit 59661d5961
2 changed files with 89 additions and 0 deletions

51
rpc.go Normal file
View file

@ -0,0 +1,51 @@
package protocol
// Range of the LSP code space
const (
LspReservedErrorRangeStart = -32899
LspReservedErrorRangeEnd = -32800
)
// LSP Specific error codes used with JSON RPC.
const (
// Error code indicating that a server received a notification or
// request before the server received the `initialize` request.
//
// For backwards compatibility these codes are not in the LSP range.
RPCServerNotInitialized int64 = -32002
RPCUnknownErrorCode int64 = -32001
// A request failed but it was syntactically correct, e.g the
// method name was known and the parameters were valid. The error
// message should contain human readable information about why
// the request failed.
//
// @since 3.17.0
RPCRequestFailed int64 = -32803
// The server detected that the content of a document got
// modified outside normal conditions. A server should
// NOT send this error code if it detects a content change
// in its unprocessed messages. The result even computed
// on an older state might still be useful for the client.
//
// If a client decides that a result is not of any use anymore
// the client should cancel the request.
RPCContentModified int64 = -32801
// The client has canceled a request and a server has detected
// the cancel.
RPCRequestCancelled int64 = -32800
)
func IsLspRPCErrorCode(code int64) bool {
if code >= LspReservedErrorRangeStart && code <= LspReservedErrorRangeEnd {
return true
}
if code == RPCServerNotInitialized || code == RPCUnknownErrorCode {
return true
}
return false
}

38
rpc_test.go Normal file
View file

@ -0,0 +1,38 @@
package protocol_test
import (
"testing"
"github.com/laravel-ls/protocol"
)
func Test_IsLspRPCErrorCode(t *testing.T) {
if protocol.IsLspRPCErrorCode(5000) {
t.Errorf("5000 is not a valid code, but function returned true")
}
if protocol.IsLspRPCErrorCode(-9000) {
t.Errorf("-9000 is not a valid code, but function returned true")
}
if protocol.IsLspRPCErrorCode(-32899) == false {
t.Errorf("-32899 is a valid code, but function returned false")
}
if protocol.IsLspRPCErrorCode(-32840) == false {
t.Errorf("-32840 is a valid code, but function returned false")
}
if protocol.IsLspRPCErrorCode(-32800) == false {
t.Errorf("-32800 is a valid code, but function returned false")
}
// Exception
if protocol.IsLspRPCErrorCode(-32001) == false {
t.Errorf("-32001 is a valid code, but function returned false")
}
if protocol.IsLspRPCErrorCode(-32002) == false {
t.Errorf("-32002 is a valid code, but function returned false")
}
}