|
1 |
| -// SPDX-FileCopyrightText: 2021 The Go Language Server Authors |
| 1 | +// Copyright 2024 The Go Language Server Authors |
2 | 2 | // SPDX-License-Identifier: BSD-3-Clause
|
3 | 3 |
|
4 | 4 | package protocol
|
5 | 5 |
|
6 |
| -import ( |
7 |
| - "fmt" |
| 6 | +// ErrorCodes predefined error codes. |
| 7 | +type ErrorCodes int32 |
8 | 8 |
|
9 |
| - "github.com/segmentio/encoding/json" |
10 |
| -) |
| 9 | +const ( |
| 10 | + ParseErrorErrorCodes ErrorCodes = -32700 |
11 | 11 |
|
12 |
| -// CancelParams params of cancelRequest. |
13 |
| -type CancelParams struct { |
14 |
| - // ID is the request id to cancel. |
15 |
| - ID interface{} `json:"id"` // int32 | string |
16 |
| -} |
| 12 | + InvalidRequestErrorCodes ErrorCodes = -32600 |
17 | 13 |
|
18 |
| -// ProgressParams params of Progress netification. |
19 |
| -// |
20 |
| -// @since 3.15.0. |
21 |
| -type ProgressParams struct { |
22 |
| - // Token is the progress token provided by the client or server. |
23 |
| - Token ProgressToken `json:"token"` |
| 14 | + MethodNotFoundErrorCodes ErrorCodes = -32601 |
24 | 15 |
|
25 |
| - // Value is the progress data. |
26 |
| - Value interface{} `json:"value"` |
27 |
| -} |
| 16 | + InvalidParamsErrorCodes ErrorCodes = -32602 |
28 | 17 |
|
29 |
| -// ProgressToken is the progress token provided by the client or server. |
30 |
| -// |
31 |
| -// @since 3.15.0. |
32 |
| -type ProgressToken struct { |
33 |
| - name string |
34 |
| - number int32 |
35 |
| -} |
| 18 | + InternalErrorErrorCodes ErrorCodes = -32603 |
| 19 | + |
| 20 | + // ServerNotInitializedErrorCodes error code indicating that a server received a notification or request before the server has received the `initialize` request. |
| 21 | + ServerNotInitializedErrorCodes ErrorCodes = -32002 |
36 | 22 |
|
37 |
| -// compile time check whether the ProgressToken implements a fmt.Formatter, fmt.Stringer, json.Marshaler and json.Unmarshaler interfaces. |
38 |
| -var ( |
39 |
| - _ fmt.Formatter = (*ProgressToken)(nil) |
40 |
| - _ fmt.Stringer = (*ProgressToken)(nil) |
41 |
| - _ json.Marshaler = (*ProgressToken)(nil) |
42 |
| - _ json.Unmarshaler = (*ProgressToken)(nil) |
| 23 | + UnknownErrorCodeErrorCodes ErrorCodes = -32001 |
43 | 24 | )
|
44 | 25 |
|
45 |
| -// NewProgressToken returns a new ProgressToken. |
46 |
| -func NewProgressToken(s string) *ProgressToken { |
47 |
| - return &ProgressToken{name: s} |
48 |
| -} |
| 26 | +type LSPErrorCodes int32 |
49 | 27 |
|
50 |
| -// NewNumberProgressToken returns a new number ProgressToken. |
51 |
| -func NewNumberProgressToken(n int32) *ProgressToken { |
52 |
| - return &ProgressToken{number: n} |
53 |
| -} |
| 28 | +const ( |
| 29 | + // RequestFailedLSPErrorCodes 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. |
| 30 | + // |
| 31 | + // @since 3.17.0 |
| 32 | + RequestFailedLSPErrorCodes LSPErrorCodes = -32803 |
54 | 33 |
|
55 |
| -// Format writes the ProgressToken to the formatter. |
56 |
| -// |
57 |
| -// If the rune is q the representation is non ambiguous, |
58 |
| -// string forms are quoted. |
59 |
| -func (v ProgressToken) Format(f fmt.State, r rune) { |
60 |
| - const numF = `%d` |
61 |
| - strF := `%s` |
62 |
| - if r == 'q' { |
63 |
| - strF = `%q` |
64 |
| - } |
65 |
| - |
66 |
| - switch { |
67 |
| - case v.name != "": |
68 |
| - fmt.Fprintf(f, strF, v.name) |
69 |
| - default: |
70 |
| - fmt.Fprintf(f, numF, v.number) |
71 |
| - } |
72 |
| -} |
| 34 | + // ServerCancelledLSPErrorCodes the server cancelled the request. This error code should only be used for requests that explicitly support being server cancellable. |
| 35 | + // |
| 36 | + // @since 3.17.0 |
| 37 | + ServerCancelledLSPErrorCodes LSPErrorCodes = -32802 |
73 | 38 |
|
74 |
| -// String returns a string representation of the ProgressToken. |
75 |
| -func (v ProgressToken) String() string { |
76 |
| - return fmt.Sprint(v) //nolint:gocritic |
77 |
| -} |
| 39 | + // ContentModifiedLSPErrorCodes 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 it 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. |
| 40 | + ContentModifiedLSPErrorCodes LSPErrorCodes = -32801 |
78 | 41 |
|
79 |
| -// MarshalJSON implements json.Marshaler. |
80 |
| -func (v *ProgressToken) MarshalJSON() ([]byte, error) { |
81 |
| - if v.name != "" { |
82 |
| - return json.Marshal(v.name) |
83 |
| - } |
| 42 | + // RequestCancelledLSPErrorCodes the client has canceled a request and a server has detected the cancel. |
| 43 | + RequestCancelledLSPErrorCodes LSPErrorCodes = -32800 |
| 44 | +) |
84 | 45 |
|
85 |
| - return json.Marshal(v.number) |
| 46 | +type CancelParams struct { |
| 47 | + // ID the request id to cancel. |
| 48 | + ID CancelParamsID `json:"id"` |
86 | 49 | }
|
87 | 50 |
|
88 |
| -// UnmarshalJSON implements json.Unmarshaler. |
89 |
| -func (v *ProgressToken) UnmarshalJSON(data []byte) error { |
90 |
| - *v = ProgressToken{} |
91 |
| - if err := json.Unmarshal(data, &v.number); err == nil { |
92 |
| - return nil |
93 |
| - } |
| 51 | +type ProgressParams struct { |
| 52 | + // Token the progress token provided by the client or server. |
| 53 | + Token ProgressToken `json:"token"` |
94 | 54 |
|
95 |
| - return json.Unmarshal(data, &v.name) |
| 55 | + // Value the progress data. |
| 56 | + Value any `json:"value"` |
96 | 57 | }
|
0 commit comments