-
Notifications
You must be signed in to change notification settings - Fork 10
/
client.go
824 lines (747 loc) · 30.3 KB
/
client.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
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
//
// 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 (
"context"
"io"
"go.bug.st/json"
"go.bug.st/lsp/jsonrpc"
)
// ServerMessagesHandler interface has all the methods that an LSP Client should
// implement to correctly parse incoming messages
type ServerMessagesHandler interface {
// Response <- Request
WindowShowMessageRequest(context.Context, jsonrpc.FunctionLogger, *ShowMessageRequestParams) (*MessageActionItem, *jsonrpc.ResponseError)
WindowShowDocument(context.Context, jsonrpc.FunctionLogger, *ShowDocumentParams) (*ShowDocumentResult, *jsonrpc.ResponseError)
WindowWorkDoneProgressCreate(context.Context, jsonrpc.FunctionLogger, *WorkDoneProgressCreateParams) *jsonrpc.ResponseError
ClientRegisterCapability(context.Context, jsonrpc.FunctionLogger, *RegistrationParams) *jsonrpc.ResponseError
ClientUnregisterCapability(context.Context, jsonrpc.FunctionLogger, *UnregistrationParams) *jsonrpc.ResponseError
WorkspaceWorkspaceFolders(context.Context, jsonrpc.FunctionLogger) ([]WorkspaceFolder, *jsonrpc.ResponseError)
WorkspaceConfiguration(context.Context, jsonrpc.FunctionLogger, *ConfigurationParams) ([]json.RawMessage, *jsonrpc.ResponseError)
WorkspaceApplyEdit(context.Context, jsonrpc.FunctionLogger, *ApplyWorkspaceEditParams) (*ApplyWorkspaceEditResult, *jsonrpc.ResponseError)
WorkspaceCodeLensRefresh(context.Context, jsonrpc.FunctionLogger) *jsonrpc.ResponseError
// Notifications <-
Progress(jsonrpc.FunctionLogger, *ProgressParams)
LogTrace(jsonrpc.FunctionLogger, *LogTraceParams)
WindowShowMessage(jsonrpc.FunctionLogger, *ShowMessageParams)
WindowLogMessage(jsonrpc.FunctionLogger, *LogMessageParams)
TelemetryEvent(jsonrpc.FunctionLogger, json.RawMessage)
TextDocumentPublishDiagnostics(jsonrpc.FunctionLogger, *PublishDiagnosticsParams)
}
// Client is an LSP Client
type Client struct {
conn *jsonrpc.Connection
handler ServerMessagesHandler
customNotification map[string]CustomNotification
customRequest map[string]CustomRequest
errorHandler func(e error)
}
func NewClient(in io.Reader, out io.Writer, handler ServerMessagesHandler) *Client {
client := &Client{
errorHandler: func(e error) {},
customNotification: map[string]CustomNotification{},
customRequest: map[string]CustomRequest{},
}
client.handler = handler
client.conn = jsonrpc.NewConnection(
in, out,
client.requestDispatcher,
client.notificationDispatcher,
client.errorHandler)
return client
}
func (client *Client) SetLogger(l jsonrpc.Logger) {
client.conn.SetLogger(l)
}
func (client *Client) SetErrorHandler(handler func(e error)) {
client.errorHandler = handler
}
func (client *Client) RegisterCustomNotification(method string, callback CustomNotification) {
client.customNotification[method] = callback
}
func (client *Client) RegisterCustomRequest(method string, callback CustomRequest) {
client.customRequest[method] = callback
}
func (client *Client) Run() {
client.conn.Run()
}
func (client *Client) notificationDispatcher(logger jsonrpc.FunctionLogger, method string, req json.RawMessage) {
switch method {
case "$/progress":
var param ProgressParams
if err := json.Unmarshal(req, ¶m); err != nil {
client.errorHandler(err)
return
}
client.handler.Progress(logger, ¶m)
case "$/cancelRequrest":
panic("should not reach here")
case "$/logTrace":
var param LogTraceParams
if err := json.Unmarshal(req, ¶m); err != nil {
client.errorHandler(err)
return
}
client.handler.LogTrace(logger, ¶m)
case "window/showMessage":
var param ShowMessageParams
if err := json.Unmarshal(req, ¶m); err != nil {
client.errorHandler(err)
return
}
client.handler.WindowShowMessage(logger, ¶m)
case "window/logMessage":
var param LogMessageParams
if err := json.Unmarshal(req, ¶m); err != nil {
client.errorHandler(err)
return
}
client.handler.WindowLogMessage(logger, ¶m)
case "telemetry/event":
// params: ‘object’ | ‘number’ | ‘boolean’ | ‘string’;
client.handler.TelemetryEvent(logger, req) // passthrough
case "textDocument/publishDiagnostics":
var param PublishDiagnosticsParams
if err := json.Unmarshal(req, ¶m); err != nil {
client.errorHandler(err)
return
}
client.handler.TextDocumentPublishDiagnostics(logger, ¶m)
default:
if handler, ok := client.customNotification[method]; ok {
handler(logger, req)
} else {
panic("unimplemented notification: " + method)
}
}
}
func (client *Client) requestDispatcher(ctx context.Context, logger jsonrpc.FunctionLogger, method string, req json.RawMessage, respCallback func(json.RawMessage, *jsonrpc.ResponseError)) {
resp := func(res interface{}, err *jsonrpc.ResponseError) {
respCallback(EncodeMessage(res), err)
}
switch method {
case "window/showMessageRequest":
var param ShowMessageRequestParams
if err := json.Unmarshal(req, ¶m); err != nil {
client.errorHandler(err)
return
}
resp(client.handler.WindowShowMessageRequest(ctx, logger, ¶m))
case "window/showDocument":
var param ShowDocumentParams
if err := json.Unmarshal(req, ¶m); err != nil {
client.errorHandler(err)
return
}
resp(client.handler.WindowShowDocument(ctx, logger, ¶m))
case "window/workDoneProgress/create":
var param WorkDoneProgressCreateParams
if err := json.Unmarshal(req, ¶m); err != nil {
client.errorHandler(err)
return
}
resp(nil, client.handler.WindowWorkDoneProgressCreate(ctx, logger, ¶m))
case "client/registerCapability":
var param RegistrationParams
if err := json.Unmarshal(req, ¶m); err != nil {
client.errorHandler(err)
return
}
resp(nil, client.handler.ClientRegisterCapability(ctx, logger, ¶m))
case "client/unregisterCapability":
var param UnregistrationParams
if err := json.Unmarshal(req, ¶m); err != nil {
client.errorHandler(err)
return
}
resp(nil, client.handler.ClientUnregisterCapability(ctx, logger, ¶m))
case "workspace/workspaceFolders":
resp(client.handler.WorkspaceWorkspaceFolders(ctx, logger))
case "workspace/configuration":
var param ConfigurationParams
if err := json.Unmarshal(req, ¶m); err != nil {
client.errorHandler(err)
return
}
resp(client.handler.WorkspaceConfiguration(ctx, logger, ¶m))
case "workspace/applyEdit":
var param ApplyWorkspaceEditParams
if err := json.Unmarshal(req, ¶m); err != nil {
client.errorHandler(err)
return
}
resp(client.handler.WorkspaceApplyEdit(ctx, logger, ¶m))
case "workspace/codeLens/refresh":
resp(nil, client.handler.WorkspaceCodeLensRefresh(ctx, logger))
default:
if handler, ok := client.customRequest[method]; ok {
resp(handler(ctx, logger, req))
} else {
panic("unimplemented request: " + method)
}
}
}
// Requests to Server
func (client *Client) Initialize(ctx context.Context, param *InitializeParams) (*InitializeResult, *jsonrpc.ResponseError, error) {
resp, respErr, err := client.conn.SendRequest(ctx, "initialize", EncodeMessage(param))
if err != nil || respErr != nil {
return nil, respErr, err
}
var res InitializeResult
return &res, nil, json.Unmarshal(resp, &res)
}
func (client *Client) Shutdown(ctx context.Context) (*jsonrpc.ResponseError, error) {
_, respErr, err := client.conn.SendRequest(ctx, "shutdown", EncodeMessage(jsonrpc.NullResult))
return respErr, err
}
func (client *Client) WorkspaceSymbol(ctx context.Context, param *WorkspaceSymbolParams) ([]SymbolInformation, *jsonrpc.ResponseError, error) {
resp, respErr, err := client.conn.SendRequest(ctx, "workspace/symbol", EncodeMessage(param))
if err != nil || respErr != nil {
return nil, respErr, err
}
// result: SymbolInformation[] | null
if string(resp) == "null" {
return nil, nil, nil
}
var res []SymbolInformation
return res, nil, json.Unmarshal(resp, &res)
}
func (client *Client) WorkspaceExecuteCommand(ctx context.Context, param *ExecuteCommandParams) (json.RawMessage, *jsonrpc.ResponseError, error) {
return client.conn.SendRequest(ctx, "workspace/executeCommand", EncodeMessage(param))
}
func (client *Client) WorkspaceWillCreateFiles(ctx context.Context, param *CreateFilesParams) (*WorkspaceEdit, *jsonrpc.ResponseError, error) {
resp, respErr, err := client.conn.SendRequest(ctx, "workspace/willCreateFiles", EncodeMessage(param))
if err != nil || respErr != nil {
return nil, respErr, err
}
// result: WorkspaceEdit | null
if string(resp) == "null" {
return nil, nil, nil
}
var res WorkspaceEdit
return &res, nil, json.Unmarshal(resp, &res)
}
func (client *Client) WorkspaceWillRenameFiles(ctx context.Context, param *RenameFilesParams) (*WorkspaceEdit, *jsonrpc.ResponseError, error) {
resp, respErr, err := client.conn.SendRequest(ctx, "workspace/willRenameFiles", EncodeMessage(param))
if err != nil || respErr != nil {
return nil, respErr, err
}
// result: WorkspaceEdit | null
if string(resp) == "null" {
return nil, nil, nil
}
var res WorkspaceEdit
return &res, nil, json.Unmarshal(resp, &res)
}
func (client *Client) WorkspaceWillDeleteFiles(ctx context.Context, param *DeleteFilesParams) (*WorkspaceEdit, *jsonrpc.ResponseError, error) {
resp, respErr, err := client.conn.SendRequest(ctx, "workspace/willDeleteFiles", EncodeMessage(param))
if err != nil || respErr != nil {
return nil, respErr, err
}
// result: WorkspaceEdit | null
if string(resp) == "null" {
return nil, nil, nil
}
var res WorkspaceEdit
return &res, nil, json.Unmarshal(resp, &res)
}
func (client *Client) TextDocumentWillSaveWaitUntil(ctx context.Context, param *WillSaveTextDocumentParams) ([]TextEdit, *jsonrpc.ResponseError, error) {
resp, respErr, err := client.conn.SendRequest(ctx, "textDocument/willSaveWaitUntil", EncodeMessage(param))
if err != nil || respErr != nil {
return nil, respErr, err
}
// result: TextEdit[] | null
if string(resp) == "null" {
return nil, nil, nil
}
var res []TextEdit
return res, nil, json.Unmarshal(resp, &res)
}
func (client *Client) TextDocumentCompletion(ctx context.Context, param *CompletionParams) (*CompletionList, *jsonrpc.ResponseError, error) {
resp, respErr, err := client.conn.SendRequest(ctx, "textDocument/completion", EncodeMessage(param))
if err != nil || respErr != nil {
return nil, respErr, err
}
// result: CompletionItem[] | CompletionList | null.
// If a CompletionItem[] is provided it is interpreted to be complete. So it is the same as { isIncomplete: false, items }
var completionItems []CompletionItem
if err := json.Unmarshal(resp, &completionItems); err == nil {
return &CompletionList{
IsIncomplete: false,
Items: completionItems,
}, nil, nil
}
if string(resp) == "null" {
return &CompletionList{
IsIncomplete: false,
Items: []CompletionItem{},
}, nil, nil
}
var res CompletionList
return &res, nil, json.Unmarshal(resp, &res)
}
func (client *Client) CompletionItemResolve(ctx context.Context, param *CompletionItem) (*CompletionItem, *jsonrpc.ResponseError, error) {
resp, respErr, err := client.conn.SendRequest(ctx, "completionItem/resolve", EncodeMessage(param))
if err != nil || respErr != nil {
return nil, respErr, err
}
var res CompletionItem
return &res, nil, json.Unmarshal(resp, &res)
}
func (client *Client) TextDocumentHover(ctx context.Context, param *HoverParams) (*Hover, *jsonrpc.ResponseError, error) {
resp, respErr, err := client.conn.SendRequest(ctx, "textDocument/hover", EncodeMessage(param))
if err != nil || respErr != nil {
return nil, respErr, err
}
// result: Hover | null
if string(resp) == "null" {
return nil, nil, nil
}
var res Hover
return &res, nil, json.Unmarshal(resp, &res)
}
func (client *Client) TextDocumentSignatureHelp(ctx context.Context, param *SignatureHelpParams) (*SignatureHelp, *jsonrpc.ResponseError, error) {
resp, respErr, err := client.conn.SendRequest(ctx, "textDocument/signatureHelp", EncodeMessage(param))
if err != nil || respErr != nil {
return nil, respErr, err
}
// result: SignatureHelp | null
if string(resp) == "null" {
return nil, nil, nil
}
var res SignatureHelp
return &res, nil, json.Unmarshal(resp, &res)
}
func (client *Client) TextDocumentDeclaration(ctx context.Context, param *DeclarationParams) ([]Location, []LocationLink, *jsonrpc.ResponseError, error) {
resp, respErr, err := client.conn.SendRequest(ctx, "textDocument/declaration", EncodeMessage(param))
if err != nil || respErr != nil {
return nil, nil, respErr, err
}
// result: Location | Location[] | LocationLink[] |null
if string(resp) == "null" {
return nil, nil, respErr, nil
}
var location Location
if err := json.Unmarshal(resp, &location); err == nil {
return []Location{location}, nil, nil, nil
}
var locations []Location
if err := json.Unmarshal(resp, &locations); err == nil {
return locations, nil, nil, nil
}
var locationLinks []LocationLink
return nil, locationLinks, nil, json.Unmarshal(resp, &locationLinks)
}
func (client *Client) TextDocumentDefinition(ctx context.Context, param *DefinitionParams) ([]Location, []LocationLink, *jsonrpc.ResponseError, error) {
resp, respErr, err := client.conn.SendRequest(ctx, "textDocument/definition", EncodeMessage(param))
if err != nil || respErr != nil {
return nil, nil, respErr, err
}
// result: Location | Location[] | LocationLink[] |null
if string(resp) == "null" {
return nil, nil, nil, nil
}
var location Location
if err := json.Unmarshal(resp, &location); err == nil {
return []Location{location}, nil, nil, nil
}
var locations []Location
if err := json.Unmarshal(resp, &locations); err == nil {
return locations, nil, nil, nil
}
var locationLinks []LocationLink
return nil, locationLinks, nil, json.Unmarshal(resp, &locationLinks)
}
func (client *Client) TextDocumentTypeDefinition(ctx context.Context, param *TypeDefinitionParams) ([]Location, []LocationLink, *jsonrpc.ResponseError, error) {
resp, respErr, err := client.conn.SendRequest(ctx, "textDocument/typeDefinition", EncodeMessage(param))
if err != nil || respErr != nil {
return nil, nil, respErr, err
}
// result: Location | Location[] | LocationLink[] |null
if string(resp) == "null" {
return nil, nil, nil, nil
}
var location Location
if err := json.Unmarshal(resp, &location); err == nil {
return []Location{location}, nil, nil, nil
}
var locations []Location
if err := json.Unmarshal(resp, &locations); err == nil {
return locations, nil, nil, nil
}
var locationLinks []LocationLink
return nil, locationLinks, nil, json.Unmarshal(resp, &locationLinks)
}
func (client *Client) TextDocumentImplementation(ctx context.Context, param *ImplementationParams) ([]Location, []LocationLink, *jsonrpc.ResponseError, error) {
resp, respErr, err := client.conn.SendRequest(ctx, "textDocument/implementation", EncodeMessage(param))
if err != nil || respErr != nil {
return nil, nil, respErr, err
}
// result: Location | Location[] | LocationLink[] |null
if string(resp) == "null" {
return nil, nil, nil, nil
}
var location Location
if err := json.Unmarshal(resp, &location); err == nil {
return []Location{location}, nil, nil, nil
}
var locations []Location
if err := json.Unmarshal(resp, &locations); err == nil {
return locations, nil, nil, nil
}
var locationLinks []LocationLink
return nil, locationLinks, nil, json.Unmarshal(resp, &locationLinks)
}
func (client *Client) TextDocumentReferences(ctx context.Context, param *ReferenceParams) ([]Location, *jsonrpc.ResponseError, error) {
resp, respErr, err := client.conn.SendRequest(ctx, "textDocument/references", EncodeMessage(param))
if err != nil || respErr != nil {
return nil, respErr, err
}
// result: Location[] | null
if string(resp) == "null" {
return nil, nil, nil
}
var res []Location
return res, nil, json.Unmarshal(resp, &res)
}
func (client *Client) TextDocumentDocumentHighlight(ctx context.Context, param *DocumentHighlightParams) ([]DocumentHighlight, *jsonrpc.ResponseError, error) {
resp, respErr, err := client.conn.SendRequest(ctx, "textDocument/documentHighlight", EncodeMessage(param))
if err != nil || respErr != nil {
return nil, respErr, err
}
// result: DocumentHighlight[] | null
if string(resp) == "null" {
return nil, nil, nil
}
var res []DocumentHighlight
return res, nil, json.Unmarshal(resp, &res)
}
func (client *Client) TextDocumentDocumentSymbol(ctx context.Context, param *DocumentSymbolParams) ([]DocumentSymbol, []SymbolInformation, *jsonrpc.ResponseError, error) {
resp, respErr, err := client.conn.SendRequest(ctx, "textDocument/documentSymbol", EncodeMessage(param))
if err != nil || respErr != nil {
return nil, nil, respErr, err
}
// result: DocumentSymbol[] | SymbolInformation[] | null
if string(resp) == "null" {
return nil, nil, nil, nil
}
var documentSymbols []DocumentSymbol
if err := json.Unmarshal(resp, &documentSymbols); err == nil {
return documentSymbols, nil, nil, nil
}
var symbolInfomation []SymbolInformation
return nil, symbolInfomation, nil, json.Unmarshal(resp, &symbolInfomation)
}
func (client *Client) TextDocumentCodeAction(ctx context.Context, param *CodeActionParams) ([]CommandOrCodeAction, *jsonrpc.ResponseError, error) {
resp, respErr, err := client.conn.SendRequest(ctx, "textDocument/codeAction", EncodeMessage(param))
if err != nil || respErr != nil {
return nil, respErr, err
}
// result: (Command | CodeAction)[] | null
if string(resp) == "null" {
return nil, nil, nil
}
var res []CommandOrCodeAction
return res, nil, json.Unmarshal(resp, &res)
}
func (client *Client) CodeActionResolve(ctx context.Context, param *CodeAction) (*CodeAction, *jsonrpc.ResponseError, error) {
resp, respErr, err := client.conn.SendRequest(ctx, "codeAction/resolve", EncodeMessage(param))
if err != nil || respErr != nil {
return nil, respErr, err
}
var res CodeAction
return &res, nil, json.Unmarshal(resp, &res)
}
func (client *Client) TextDocumentCodeLens(ctx context.Context, param *CodeLensParams) ([]CodeLens, *jsonrpc.ResponseError, error) {
resp, respErr, err := client.conn.SendRequest(ctx, "textDocument/codeLens", EncodeMessage(param))
if err != nil || respErr != nil {
return nil, respErr, err
}
// result: CodeLens[] | null
if string(resp) == "null" {
return nil, nil, nil
}
var res []CodeLens
return res, nil, json.Unmarshal(resp, &res)
}
func (client *Client) CodeLensResolve(ctx context.Context, param *CodeLens) (*CodeLens, *jsonrpc.ResponseError, error) {
resp, respErr, err := client.conn.SendRequest(ctx, "codeLens/resolve", EncodeMessage(param))
if err != nil || respErr != nil {
return nil, respErr, err
}
var res CodeLens
return &res, nil, json.Unmarshal(resp, &res)
}
func (client *Client) TextDocumentDocumentLink(ctx context.Context, param *DocumentLinkParams) ([]DocumentLink, *jsonrpc.ResponseError, error) {
resp, respErr, err := client.conn.SendRequest(ctx, "textDocument/documentLink", EncodeMessage(param))
if err != nil || respErr != nil {
return nil, respErr, err
}
// result: DocumentLink[] | null
if string(resp) == "null" {
return nil, nil, nil
}
var res []DocumentLink
return res, nil, json.Unmarshal(resp, &res)
}
func (client *Client) DocumentLinkResolve(ctx context.Context, param *DocumentLink) (*DocumentLink, *jsonrpc.ResponseError, error) {
resp, respErr, err := client.conn.SendRequest(ctx, "documentLink/resolve", EncodeMessage(param))
if err != nil || respErr != nil {
return nil, respErr, err
}
var res DocumentLink
return &res, nil, json.Unmarshal(resp, &res)
}
func (client *Client) TextDocumentDocumentColor(ctx context.Context, param *DocumentColorParams) ([]ColorInformation, *jsonrpc.ResponseError, error) {
resp, respErr, err := client.conn.SendRequest(ctx, "textDocument/documentColor", EncodeMessage(param))
if err != nil || respErr != nil {
return nil, respErr, err
}
var res []ColorInformation
return res, nil, json.Unmarshal(resp, &res)
}
func (client *Client) TextDocumentColorPresentation(ctx context.Context, param *ColorPresentationParams) ([]ColorPresentation, *jsonrpc.ResponseError, error) {
resp, respErr, err := client.conn.SendRequest(ctx, "textDocument/colorPresentation", EncodeMessage(param))
if err != nil || respErr != nil {
return nil, respErr, err
}
var res []ColorPresentation
return res, nil, json.Unmarshal(resp, &res)
}
func (client *Client) TextDocumentFormatting(ctx context.Context, param *DocumentFormattingParams) ([]TextEdit, *jsonrpc.ResponseError, error) {
resp, respErr, err := client.conn.SendRequest(ctx, "textDocument/formatting", EncodeMessage(param))
if err != nil || respErr != nil {
return nil, respErr, err
}
// result: TextEdit[] | null
if string(resp) == "null" {
return nil, nil, nil
}
var res []TextEdit
return res, nil, json.Unmarshal(resp, &res)
}
func (client *Client) TextDocumentRangeFormatting(ctx context.Context, param *DocumentRangeFormattingParams) ([]TextEdit, *jsonrpc.ResponseError, error) {
resp, respErr, err := client.conn.SendRequest(ctx, "textDocument/rangeFormatting", EncodeMessage(param))
if err != nil || respErr != nil {
return nil, respErr, err
}
// result: TextEdit[] | null
if string(resp) == "null" {
return nil, nil, nil
}
var res []TextEdit
return res, nil, json.Unmarshal(resp, &res)
}
func (client *Client) TextDocumentOnTypeFormatting(ctx context.Context, param *DocumentOnTypeFormattingParams) ([]TextEdit, *jsonrpc.ResponseError, error) {
resp, respErr, err := client.conn.SendRequest(ctx, "textDocument/onTypeFormatting", EncodeMessage(param))
if err != nil || respErr != nil {
return nil, respErr, err
}
// result: TextEdit[] | null
if string(resp) == "null" {
return nil, nil, nil
}
var res []TextEdit
return res, nil, json.Unmarshal(resp, &res)
}
func (client *Client) TextDocumentRename(ctx context.Context, param *RenameParams) (*WorkspaceEdit, *jsonrpc.ResponseError, error) {
resp, respErr, err := client.conn.SendRequest(ctx, "textDocument/rename", EncodeMessage(param))
if err != nil || respErr != nil {
return nil, respErr, err
}
// result: WorkspaceEdit | null
if string(resp) == "null" {
return nil, nil, nil
}
var res WorkspaceEdit
return &res, nil, json.Unmarshal(resp, &res)
}
func (client *Client) TextDocumentPrepareRename(ctx context.Context, param *PrepareRenameParams) (json.RawMessage, *jsonrpc.ResponseError, error) {
panic("unimplemented")
// _, _, err := client.conn.SendRequest(ctx, "textDocument/prepareRename", EncodeMessage(param))
// if err != nil || respErr!=nil{
// return nil, respErr, err
// }
// // result: Range | { range: Range, placeholder: string } | { defaultBehavior: boolean } | null
// return nil, nil, nil
}
func (client *Client) TextDocumentFoldingRange(ctx context.Context, param *FoldingRangeParams) ([]FoldingRange, *jsonrpc.ResponseError, error) {
resp, respErr, err := client.conn.SendRequest(ctx, "textDocument/foldingRange", EncodeMessage(param))
if err != nil || respErr != nil {
return nil, respErr, err
}
// result: FoldingRange[] | null
if string(resp) == "null" {
return nil, nil, nil
}
var res []FoldingRange
return res, nil, json.Unmarshal(resp, &res)
}
func (client *Client) TextDocumentSelectionRange(ctx context.Context, param *SelectionRangeParams) ([]SelectionRange, *jsonrpc.ResponseError, error) {
resp, respErr, err := client.conn.SendRequest(ctx, "textDocument/selectionRange", EncodeMessage(param))
if err != nil || respErr != nil {
return nil, respErr, err
}
// result: SelectionRange[] | null
if string(resp) == "null" {
return nil, nil, nil
}
var res []SelectionRange
return res, nil, json.Unmarshal(resp, &res)
}
func (client *Client) TextDocumentPrepareCallHierarchy(ctx context.Context, param *CallHierarchyPrepareParams) ([]CallHierarchyItem, *jsonrpc.ResponseError, error) {
resp, respErr, err := client.conn.SendRequest(ctx, "textDocument/prepareCallHierarchy", EncodeMessage(param))
if err != nil || respErr != nil {
return nil, respErr, err
}
// result: CallHierarchyItem[] | null
if string(resp) == "null" {
return nil, nil, nil
}
var res []CallHierarchyItem
return res, nil, json.Unmarshal(resp, &res)
}
func (client *Client) CallHierarchyIncomingCalls(ctx context.Context, param *CallHierarchyIncomingCallsParams) ([]CallHierarchyIncomingCall, *jsonrpc.ResponseError, error) {
resp, respErr, err := client.conn.SendRequest(ctx, "callHierarchy/incomingCalls", EncodeMessage(param))
if err != nil || respErr != nil {
return nil, respErr, err
}
// result: CallHierarchyIncomingCall[] | null
if string(resp) == "null" {
return nil, nil, nil
}
var res []CallHierarchyIncomingCall
return res, nil, json.Unmarshal(resp, &res)
}
func (client *Client) CallHierarchyOutgoingCalls(ctx context.Context, param *CallHierarchyOutgoingCallsParams) ([]CallHierarchyOutgoingCall, *jsonrpc.ResponseError, error) {
resp, respErr, err := client.conn.SendRequest(ctx, "callHierarchy/outgoingCalls", EncodeMessage(param))
if err != nil || respErr != nil {
return nil, respErr, err
}
// result: CallHierarchyOutgoingCall[] | null
if string(resp) == "null" {
return nil, nil, nil
}
var res []CallHierarchyOutgoingCall
return res, nil, json.Unmarshal(resp, &res)
}
func (client *Client) TextDocumentSemanticTokensFull(ctx context.Context, param *SemanticTokensParams) (*SemanticTokens, *jsonrpc.ResponseError, error) {
resp, respErr, err := client.conn.SendRequest(ctx, "textDocument/semanticTokens/full", EncodeMessage(param))
if err != nil || respErr != nil {
return nil, respErr, err
}
// result: SemanticTokens | null
if string(resp) == "null" {
return nil, nil, nil
}
var res SemanticTokens
return &res, nil, json.Unmarshal(resp, &res)
}
func (client *Client) TextDocumentSemanticTokensFullDelta(ctx context.Context, param *SemanticTokensDeltaParams) (*SemanticTokens, *SemanticTokensDelta, *jsonrpc.ResponseError, error) {
resp, respErr, err := client.conn.SendRequest(ctx, "textDocument/semanticTokens/full/delta", EncodeMessage(param))
if err != nil || respErr != nil {
return nil, nil, respErr, err
}
// result: SemanticTokens | SemanticTokensDelta | null
if string(resp) == "null" {
return nil, nil, nil, nil
}
var delta SemanticTokensDelta
if err := json.Unmarshal(resp, &delta); err == nil {
return nil, &delta, nil, nil
}
var res SemanticTokens
return &res, nil, nil, json.Unmarshal(resp, &res)
}
func (client *Client) TextDocumentSemanticTokensRange(ctx context.Context, param *SemanticTokensRangeParams) (*SemanticTokens, *jsonrpc.ResponseError, error) {
resp, respErr, err := client.conn.SendRequest(ctx, "textDocument/semanticTokens/range", EncodeMessage(param))
if err != nil || respErr != nil {
return nil, respErr, err
}
// result: SemanticTokens | null
if string(resp) == "null" {
return nil, nil, nil
}
var res SemanticTokens
return &res, nil, json.Unmarshal(resp, &res)
}
func (client *Client) WorkspaceSemanticTokensRefresh(ctx context.Context) (*jsonrpc.ResponseError, error) {
_, respErr, err := client.conn.SendRequest(ctx, "workspace/semanticTokens/refresh", EncodeMessage(jsonrpc.NullResult))
return respErr, err
}
func (client *Client) TextDocumentLinkedEditingRange(ctx context.Context, param *LinkedEditingRangeParams) (*LinkedEditingRanges, *jsonrpc.ResponseError, error) {
resp, respErr, err := client.conn.SendRequest(ctx, "textDocument/linkedEditingRange", EncodeMessage(param))
if err != nil || respErr != nil {
return nil, respErr, err
}
// result: LinkedEditingRanges | null
if string(resp) == "null" {
return nil, nil, nil
}
var res LinkedEditingRanges
return &res, nil, json.Unmarshal(resp, &res)
}
func (client *Client) TextDocumentMoniker(ctx context.Context, param *MonikerParams) ([]Moniker, *jsonrpc.ResponseError, error) {
resp, respErr, err := client.conn.SendRequest(ctx, "textDocument/moniker", EncodeMessage(param))
if err != nil || respErr != nil {
return nil, respErr, err
}
// result: Moniker[] | null
if string(resp) == "null" {
return nil, nil, nil
}
var res []Moniker
return res, nil, json.Unmarshal(resp, &res)
}
// Notifications to Server
func (client *Client) Progress(param *ProgressParams) error {
return client.conn.SendNotification("$/progress", EncodeMessage(param))
}
func (client *Client) Initialized(param *InitializedParams) error {
return client.conn.SendNotification("initialized", EncodeMessage(param))
}
func (client *Client) Exit() error {
return client.conn.SendNotification("exit", EncodeMessage(jsonrpc.NullResult))
}
func (client *Client) SetTrace(param *SetTraceParams) error {
return client.conn.SendNotification("$/setTrace", EncodeMessage(param))
}
func (client *Client) WindowWorkDoneProgressCancel(param *WorkDoneProgressCancelParams) error {
return client.conn.SendNotification("window/workDoneProgress/cancel", EncodeMessage(param))
}
func (client *Client) WorkspaceDidChangeWorkspaceFolders(param *DidChangeWorkspaceFoldersParams) error {
return client.conn.SendNotification("workspace/didChangeWorkspaceFolders", EncodeMessage(param))
}
func (client *Client) WorkspaceDidChangeConfiguration(param *DidChangeConfigurationParams) error {
return client.conn.SendNotification("workspace/didChangeConfiguration", EncodeMessage(param))
}
func (client *Client) WorkspaceDidChangeWatchedFiles(param *DidChangeWatchedFilesParams) error {
return client.conn.SendNotification("workspace/didChangeWatchedFiles", EncodeMessage(param))
}
func (client *Client) WorkspaceDidCreateFiles(param *CreateFilesParams) error {
return client.conn.SendNotification("workspace/didCreateFiles", EncodeMessage(param))
}
func (client *Client) WorkspaceDidRenameFiles(param *RenameFilesParams) error {
return client.conn.SendNotification("workspace/didRenameFiles", EncodeMessage(param))
}
func (client *Client) WorkspaceDidDeleteFiles(param *DeleteFilesParams) error {
return client.conn.SendNotification("workspace/didDeleteFiles", EncodeMessage(param))
}
func (client *Client) TextDocumentDidOpen(param *DidOpenTextDocumentParams) error {
return client.conn.SendNotification("textDocument/didOpen", EncodeMessage(param))
}
func (client *Client) TextDocumentDidChange(param *DidChangeTextDocumentParams) error {
return client.conn.SendNotification("textDocument/didChange", EncodeMessage(param))
}
func (client *Client) TextDocumentWillSave(param *WillSaveTextDocumentParams) error {
return client.conn.SendNotification("textDocument/willSave", EncodeMessage(param))
}
func (client *Client) TextDocumentDidSave(param *DidSaveTextDocumentParams) error {
return client.conn.SendNotification("textDocument/didSave", EncodeMessage(param))
}
func (client *Client) TextDocumentDidClose(param *DidCloseTextDocumentParams) error {
return client.conn.SendNotification("textDocument/didClose", EncodeMessage(param))
}