-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathlsp_basic.go
295 lines (257 loc) · 8.53 KB
/
lsp_basic.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
//
// Copyright 2024 Cristian Maglie. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//
package lsp
import (
"fmt"
"go.bug.st/json"
"go.bug.st/lsp/jsonrpc"
)
type WorkDoneProgressOptions struct {
WorkDoneProgress bool `json:"workDoneProgress,omitempty"`
}
type WorkDoneProgressParams struct {
// An optional token that a server can use to report work done progress.
WorkDoneToken jsonrpc.ProgressToken `json:"workDoneToken,omitempty"`
}
type PartialResultParams struct {
// An optional token that a server can use to report partial results (e.g.
// streaming) to the client.
PartialResultToken jsonrpc.ProgressToken `json:"partialResultToken,omitempty"`
}
type WorkDoneProgressCreateParams struct {
// The token to be used to report progress.
Token json.RawMessage `json:"token,required"`
}
type WorkDoneProgressCancelParams struct {
// The token to be used to report progress.
Token json.RawMessage `json:"token,required"`
}
type ProgressParams struct {
// The progress token provided by the client or server.
Token json.RawMessage `json:"token,required"`
// The progress data.
Value json.RawMessage `json:"value,required"`
}
func (p *ProgressParams) TryToDecodeWellKnownValues() interface{} {
var begin WorkDoneProgressBegin
if err := json.Unmarshal(p.Value, &begin); err == nil {
return begin
}
var report WorkDoneProgressReport
if err := json.Unmarshal(p.Value, &report); err == nil {
return report
}
var end WorkDoneProgressEnd
if err := json.Unmarshal(p.Value, &end); err == nil {
return end
}
return nil
}
type WorkDoneProgressBegin struct {
// Kind string `json:"kind,required"` /* automatically set to 'begin' */
// Mandatory title of the progress operation. Used to briefly inform about
// the kind of operation being performed.
//
// Examples: "Indexing" or "Linking dependencies".
Title string `json:"title,required"`
// Controls if a cancel button should show to allow the user to cancel the
// long running operation. Clients that don't support cancellation are
// allowed to ignore the setting.
Cancellable bool `json:"cancellable,omitempty"`
// Optional, more detailed associated progress message. Contains
// complementary information to the `title`.
//
// Examples: "3/25 files", "project/src/module2", "node_modules/some_dep".
// If unset, the previous progress message (if any) is still valid.
Message string `json:"message,omitempty"`
// Optional progress percentage to display (value 100 is considered 100%).
// If not provided infinite progress is assumed and clients are allowed
// to ignore the `percentage` value in subsequent in report notifications.
//
// The value should be steadily rising. Clients are free to ignore values
// that are not following this rule. The value range is [0, 100]
Percentage *float64 `json:"percentage,omitempty"`
}
func (p *WorkDoneProgressBegin) UnmarshalJSON(data []byte) error {
var temp struct {
Kind string `json:"kind,required"`
}
if err := json.Unmarshal(data, &temp); err != nil {
return err
}
if temp.Kind != "begin" {
return fmt.Errorf("invalid Kind field value '%s': must be 'begin'", temp.Kind)
}
type __ WorkDoneProgressBegin
var res __
if err := json.Unmarshal(data, &res); err != nil {
return err
}
*p = WorkDoneProgressBegin(res)
return nil
}
func (p WorkDoneProgressBegin) MarshalJSON() ([]byte, error) {
var temp struct {
Kind string `json:"kind,required"`
Title string `json:"title,required"`
Cancellable bool `json:"cancellable,omitempty"`
Message string `json:"message,omitempty"`
Percentage *float64 `json:"percentage,omitempty"`
}
temp.Kind = "begin"
temp.Title = p.Title
temp.Cancellable = p.Cancellable
temp.Message = p.Message
temp.Percentage = p.Percentage
return json.Marshal(temp)
}
func (p WorkDoneProgressBegin) String() string {
res := "BEGIN"
if p.Cancellable {
res += " (cancellable)"
}
res += " " + p.Title
if p.Message != "" {
res += ", " + p.Message
}
if p.Percentage != nil {
res += fmt.Sprintf(", %1.1f%%", *p.Percentage)
}
return res
}
type WorkDoneProgressReport struct {
// Kind string `json:"kind,required"` /* automatically set to 'report' */
// Controls enablement state of a cancel button. This property is only valid
// if a cancel button got requested in the `WorkDoneProgressBegin` payload.
//
// Clients that don't support cancellation or don't support control the
// button's enablement state are allowed to ignore the setting.
Cancellable bool `json:"cancellable,omitempty"`
// Optional, more detailed associated progress message. Contains
// complementary information to the `title`.
//
// Examples: "3/25 files", "project/src/module2", "node_modules/some_dep".
// If unset, the previous progress message (if any) is still valid.
Message string `json:"message,omitempty"`
// Optional progress percentage to display (value 100 is considered 100%).
// If not provided infinite progress is assumed and clients are allowed
// to ignore the `percentage` value in subsequent in report notifications.
//
// The value should be steadily rising. Clients are free to ignore values
// that are not following this rule. The value range is [0, 100]
Percentage *float64 `json:"percentage,omitempty"`
}
func (p *WorkDoneProgressReport) UnmarshalJSON(data []byte) error {
var temp struct {
Kind string `json:"kind,required"`
}
if err := json.Unmarshal(data, &temp); err != nil {
return err
}
if temp.Kind != "report" {
return fmt.Errorf("invalid Kind field value '%s': must be 'report'", temp.Kind)
}
type __ WorkDoneProgressReport
var res __
if err := json.Unmarshal(data, &res); err != nil {
return err
}
*p = WorkDoneProgressReport(res)
return nil
}
func (p WorkDoneProgressReport) MarshalJSON() ([]byte, error) {
var temp struct {
Kind string `json:"kind,required"`
Cancellable bool `json:"cancellable,omitempty"`
Message string `json:"message,omitempty"`
Percentage *float64 `json:"percentage,omitempty"`
}
temp.Kind = "report"
temp.Cancellable = p.Cancellable
temp.Message = p.Message
temp.Percentage = p.Percentage
return json.Marshal(temp)
}
func (p WorkDoneProgressReport) String() string {
res := "REPORT"
if p.Cancellable {
res += " (cancellable)"
}
if p.Message != "" {
res += ", " + p.Message
}
if p.Percentage != nil {
res += fmt.Sprintf(", %1.1f%%", *p.Percentage)
}
return res
}
type WorkDoneProgressEnd struct {
// Kind string `json:"kind,required"` /* automatically set to 'end' */
// Optional, a final message indicating to for example indicate the outcome
// of the operation.
Message string `json:"message,omitempty"`
}
func (p *WorkDoneProgressEnd) UnmarshalJSON(data []byte) error {
var temp struct {
Kind string `json:"kind,required"`
}
if err := json.Unmarshal(data, &temp); err != nil {
return err
}
if temp.Kind != "end" {
return fmt.Errorf("invalid Kind field value '%s': must be 'end'", temp.Kind)
}
type __ WorkDoneProgressEnd
var res __
if err := json.Unmarshal(data, &res); err != nil {
return err
}
*p = WorkDoneProgressEnd(res)
return nil
}
func (p WorkDoneProgressEnd) MarshalJSON() ([]byte, error) {
var temp struct {
Kind string `json:"kind,required"`
Message string `json:"message,omitempty"`
}
temp.Kind = "end"
temp.Message = p.Message
return json.Marshal(temp)
}
func (p WorkDoneProgressEnd) String() string {
res := "END "
if p.Message != "" {
res += ", " + p.Message
}
return res
}
// Registration General parameters to register for a capability.
type Registration struct {
// The id used to register the request. The id can be used to deregister
// the request again.
ID string `json:"id,required"`
// The method / capability to register for.
Method string `json:"method,required"`
// Options necessary for the registration.
RegisterOptions json.RawMessage `json:"registerOptions,omitempty"`
}
type RegistrationParams struct {
Registrations []Registration `json:"registrations,required"`
}
// Unregistration General parameters to unregister a capability.
type Unregistration struct {
// The id used to unregister the request or notification. Usually an id
// provided during the register request.
ID string `json:"id,required"`
// The method / capability to unregister for.
Method string `json:"method,required"`
}
type UnregistrationParams struct {
// This should correctly be named `unregistrations`. However changing this
// is a breaking change and needs to wait until we deliver a 4.x version
// of the specification.
Unregisterations []Unregistration `json:"unregisterations,required"`
}