Skip to content

Commit 9287284

Browse files
authored
Support lsp 3.16 (#17)
* codes: move to codes.go and romeve not JSON-RPC 2 specific codes * all: change int64 type to int32 for correspond to lsp 3.16
1 parent 4ffaa77 commit 9287284

File tree

4 files changed

+91
-79
lines changed

4 files changed

+91
-79
lines changed

codes.go

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
// SPDX-FileCopyrightText: Copyright 2021 The Go Language Server Authors
2+
// SPDX-License-Identifier: BSD-3-Clause
3+
4+
package jsonrpc2
5+
6+
// Code is an error code as defined in the JSON-RPC spec.
7+
type Code int32
8+
9+
// list of JSON-RPC error codes.
10+
const (
11+
// ParseError is the invalid JSON was received by the server.
12+
// An error occurred on the server while parsing the JSON text.
13+
ParseError Code = -32700
14+
15+
// InvalidRequest is the JSON sent is not a valid Request object.
16+
InvalidRequest Code = -32600
17+
18+
// MethodNotFound is the method does not exist / is not available.
19+
MethodNotFound Code = -32601
20+
21+
// InvalidParams is the invalid method parameter(s).
22+
InvalidParams Code = -32602
23+
24+
// InternalError is the internal JSON-RPC error.
25+
InternalError Code = -32603
26+
27+
// JSONRPCReservedErrorRangeStart is the start range of JSON RPC reserved error codes.
28+
//
29+
// It doesn't denote a real error code. No LSP error codes should
30+
// be defined between the start and end range. For backwards
31+
// compatibility the "ServerNotInitialized" and the "UnknownErrorCode"
32+
// are left in the range.
33+
//
34+
// @since 3.16.0.
35+
JSONRPCReservedErrorRangeStart Code = -32099
36+
37+
// CodeServerErrorStart reserved for implementation-defined server-errors.
38+
//
39+
// Deprecated: Use JSONRPCReservedErrorRangeStart instead.
40+
CodeServerErrorStart = JSONRPCReservedErrorRangeStart
41+
42+
// ServerNotInitialized is the error of server not initialized.
43+
ServerNotInitialized Code = -32002
44+
45+
// UnknownError should be used for all non coded errors.
46+
UnknownError Code = -32001
47+
48+
// JSONRPCReservedErrorRangeEnd is the start range of JSON RPC reserved error codes.
49+
//
50+
// It doesn't denote a real error code.
51+
//
52+
// @since 3.16.0.
53+
JSONRPCReservedErrorRangeEnd Code = -32000
54+
55+
// CodeServerErrorEnd reserved for implementation-defined server-errors.
56+
//
57+
// Deprecated: Use JSONRPCReservedErrorRangeEnd instead.
58+
CodeServerErrorEnd = JSONRPCReservedErrorRangeEnd
59+
)
60+
61+
// This file contains the Go forms of the wire specification.
62+
//
63+
// See http://www.jsonrpc.org/specification for details.
64+
//
65+
// list of JSON-RPC errors.
66+
var (
67+
// ErrUnknown should be used for all non coded errors.
68+
ErrUnknown = NewError(UnknownError, "JSON-RPC unknown error")
69+
70+
// ErrParse is used when invalid JSON was received by the server.
71+
ErrParse = NewError(ParseError, "JSON-RPC parse error")
72+
73+
// ErrInvalidRequest is used when the JSON sent is not a valid Request object.
74+
ErrInvalidRequest = NewError(InvalidRequest, "JSON-RPC invalid request")
75+
76+
// ErrMethodNotFound should be returned by the handler when the method does
77+
// not exist / is not available.
78+
ErrMethodNotFound = NewError(MethodNotFound, "JSON-RPC method not found")
79+
80+
// ErrInvalidParams should be returned by the handler when method
81+
// parameter(s) were invalid.
82+
ErrInvalidParams = NewError(InvalidParams, "JSON-RPC invalid params")
83+
84+
// ErrInternal is not currently returned but defined for completeness.
85+
ErrInternal = NewError(InternalError, "JSON-RPC internal error")
86+
)

conn.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ type Conn interface {
6565
}
6666

6767
type conn struct {
68-
seq int64 // access atomically
68+
seq int32 // access atomically
6969
writeMu sync.Mutex // protects writes to the stream
7070
stream Stream // supplied stream
7171
pendingMu sync.Mutex // protects the pending map
@@ -88,7 +88,7 @@ func NewConn(s Stream) Conn {
8888
// Call implements Conn.
8989
func (c *conn) Call(ctx context.Context, method string, params, result interface{}) (id ID, err error) {
9090
// generate a new request identifier
91-
id = NewNumberID(atomic.AddInt64(&c.seq, 1))
91+
id = NewNumberID(atomic.AddInt32(&c.seq, 1))
9292
call, err := NewCall(id, method, params)
9393
if err != nil {
9494
return id, fmt.Errorf("marshaling call parameters: %w", err)

errors.go

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -64,36 +64,7 @@ var _ error = (*constErr)(nil)
6464
// Error implements error.Error.
6565
func (e constErr) Error() string { return string(e) }
6666

67-
// This file contains the Go forms of the wire specification.
68-
//
69-
// See http://www.jsonrpc.org/specification for details.
70-
//
71-
// list of JSON-RPC errors.
72-
var (
73-
// ErrUnknown should be used for all non coded errors.
74-
ErrUnknown = NewError(UnknownError, "JSON-RPC unknown error")
75-
76-
// ErrParse is used when invalid JSON was received by the server.
77-
ErrParse = NewError(ParseError, "JSON-RPC parse error")
78-
79-
// ErrInvalidRequest is used when the JSON sent is not a valid Request object.
80-
ErrInvalidRequest = NewError(InvalidRequest, "JSON-RPC invalid request")
81-
82-
// ErrMethodNotFound should be returned by the handler when the method does
83-
// not exist / is not available.
84-
ErrMethodNotFound = NewError(MethodNotFound, "JSON-RPC method not found")
85-
86-
// ErrInvalidParams should be returned by the handler when method
87-
// parameter(s) were invalid.
88-
ErrInvalidParams = NewError(InvalidParams, "JSON-RPC invalid params")
89-
90-
// ErrInternal is not currently returned but defined for completeness.
91-
ErrInternal = NewError(InternalError, "JSON-RPC internal error")
92-
93-
// ErrServerOverloaded is returned when a message was refused due to a
94-
// server being temporarily unable to accept any new messages.
95-
ErrServerOverloaded = NewError(ServerOverloaded, "JSON-RPC overloaded")
96-
67+
const (
9768
// ErrIdleTimeout is returned when serving timed out waiting for new connections.
9869
ErrIdleTimeout = constErr("timed out waiting for new connections")
9970
)

wire.go

Lines changed: 2 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -9,51 +9,6 @@ import (
99
"github.com/segmentio/encoding/json"
1010
)
1111

12-
// Code is an int64 error code as defined in the JSON-RPC spec.
13-
type Code int64
14-
15-
// list of JSON-RPC error codes.
16-
const (
17-
// ParseError is the invalid JSON was received by the server.
18-
// An error occurred on the server while parsing the JSON text.
19-
ParseError Code = -32700
20-
21-
// InvalidRequest is the JSON sent is not a valid Request object.
22-
InvalidRequest Code = -32600
23-
24-
// MethodNotFound is the method does not exist / is not available.
25-
MethodNotFound Code = -32601
26-
27-
// InvalidParams is the invalid method parameter(s).
28-
InvalidParams Code = -32602
29-
30-
// InternalError is the internal JSON-RPC error.
31-
InternalError Code = -32603
32-
33-
// ServerNotInitialized is the error of server not initialized.
34-
ServerNotInitialized Code = -32002
35-
36-
// UnknownError should be used for all non coded errors.
37-
UnknownError Code = -32001
38-
39-
// RequestCancelled is the cancellation error.
40-
//
41-
// Defined by the Language Server Protocol.
42-
RequestCancelled Code = -32800
43-
44-
// ContentModified is the state change that invalidates the result of a request in execution.
45-
//
46-
// Defined by the Language Server Protocol.
47-
ContentModified Code = -32801
48-
49-
// ServerOverloaded is returned when a message was refused due to a
50-
// server being temporarily unable to accept any new messages.
51-
ServerOverloaded Code = -32000
52-
53-
codeServerErrorStart Code = -32099
54-
codeServerErrorEnd Code = -32000
55-
)
56-
5712
// Version represents a JSON-RPC version.
5813
const Version = "2.0"
5914

@@ -91,7 +46,7 @@ func (version) UnmarshalJSON(data []byte) error {
9146
// number form if the Name is the empty string.
9247
type ID struct {
9348
name string
94-
number int64
49+
number int32
9550
}
9651

9752
// compile time check whether the ID implements a fmt.Formatter, json.Marshaler and json.Unmarshaler interfaces.
@@ -102,7 +57,7 @@ var (
10257
)
10358

10459
// NewNumberID returns a new number request ID.
105-
func NewNumberID(v int64) ID { return ID{number: v} }
60+
func NewNumberID(v int32) ID { return ID{number: v} }
10661

10762
// NewStringID returns a new string request ID.
10863
func NewStringID(v string) ID { return ID{name: v} }

0 commit comments

Comments
 (0)