-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathserver.go
1894 lines (1419 loc) · 74.6 KB
/
server.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
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// SPDX-FileCopyrightText: 2019 The Go Language Server Authors
// SPDX-License-Identifier: BSD-3-Clause
package protocol
import (
"bytes"
"context"
"fmt"
"github.com/segmentio/encoding/json"
"go.uber.org/zap"
"go.lsp.dev/jsonrpc2"
"go.lsp.dev/pkg/xcontext"
)
// ServerDispatcher returns a Server that dispatches LSP requests across the
// given jsonrpc2 connection.
func ServerDispatcher(conn jsonrpc2.Conn, logger *zap.Logger) Server {
return &server{
Conn: conn,
logger: logger,
}
}
// ServerHandler jsonrpc2.Handler of Language Server Prococol Server.
//
//nolint:unparam,revive
func ServerHandler(server Server, handler jsonrpc2.Handler) jsonrpc2.Handler {
h := func(ctx context.Context, reply jsonrpc2.Replier, req jsonrpc2.Request) error {
if ctx.Err() != nil {
xctx := xcontext.Detach(ctx)
return reply(xctx, nil, ErrRequestCancelled)
}
handled, err := serverDispatch(ctx, server, reply, req)
if handled || err != nil {
return err
}
// TODO: This code is wrong, it ignores handler and assumes non standard
// request handles everything
// non standard request should just be a layered handler.
var params interface{}
if err := json.Unmarshal(req.Params(), ¶ms); err != nil {
return replyParseError(ctx, reply, err)
}
resp, err := server.Request(ctx, req.Method(), params)
return reply(ctx, resp, err)
}
return h
}
// serverDispatch implements jsonrpc2.Handler.
//
//nolint:gocognit,funlen,gocyclo,cyclop,maintidx
func serverDispatch(ctx context.Context, server Server, reply jsonrpc2.Replier, req jsonrpc2.Request) (handled bool, err error) {
if ctx.Err() != nil {
return true, reply(ctx, nil, ErrRequestCancelled)
}
dec := json.NewDecoder(bytes.NewReader(req.Params()))
logger := LoggerFromContext(ctx)
switch req.Method() {
case MethodInitialize: // request
defer logger.Debug(MethodInitialize, zap.Error(err))
var params InitializeParams
if err := dec.Decode(¶ms); err != nil {
return true, replyParseError(ctx, reply, err)
}
resp, err := server.Initialize(ctx, ¶ms)
return true, reply(ctx, resp, err)
case MethodInitialized: // notification
defer logger.Debug(MethodInitialized, zap.Error(err))
var params InitializedParams
if err := dec.Decode(¶ms); err != nil {
return true, replyParseError(ctx, reply, err)
}
err := server.Initialized(ctx, ¶ms)
return true, reply(ctx, nil, err)
case MethodShutdown: // request
defer logger.Debug(MethodShutdown, zap.Error(err))
if len(req.Params()) > 0 {
return true, reply(ctx, nil, fmt.Errorf("expected no params: %w", jsonrpc2.ErrInvalidParams))
}
err := server.Shutdown(ctx)
return true, reply(ctx, nil, err)
case MethodExit: // notification
defer logger.Debug(MethodExit, zap.Error(err))
if len(req.Params()) > 0 {
return true, reply(ctx, nil, fmt.Errorf("expected no params: %w", jsonrpc2.ErrInvalidParams))
}
err := server.Exit(ctx)
return true, reply(ctx, nil, err)
case MethodWorkDoneProgressCancel: // notification
defer logger.Debug(MethodWorkDoneProgressCancel, zap.Error(err))
var params WorkDoneProgressCancelParams
if err := dec.Decode(¶ms); err != nil {
return true, replyParseError(ctx, reply, err)
}
err := server.WorkDoneProgressCancel(ctx, ¶ms)
return true, reply(ctx, nil, err)
case MethodLogTrace: // notification
defer logger.Debug(MethodLogTrace, zap.Error(err))
var params LogTraceParams
if err := dec.Decode(¶ms); err != nil {
return true, replyParseError(ctx, reply, err)
}
err := server.LogTrace(ctx, ¶ms)
return true, reply(ctx, nil, err)
case MethodSetTrace: // notification
defer logger.Debug(MethodSetTrace, zap.Error(err))
var params SetTraceParams
if err := dec.Decode(¶ms); err != nil {
return true, replyParseError(ctx, reply, err)
}
err := server.SetTrace(ctx, ¶ms)
return true, reply(ctx, nil, err)
case MethodTextDocumentCodeAction: // request
defer logger.Debug(MethodTextDocumentCodeAction, zap.Error(err))
var params CodeActionParams
if err := dec.Decode(¶ms); err != nil {
return true, replyParseError(ctx, reply, err)
}
resp, err := server.CodeAction(ctx, ¶ms)
return true, reply(ctx, resp, err)
case MethodTextDocumentCodeLens: // request
defer logger.Debug(MethodTextDocumentCodeLens, zap.Error(err))
var params CodeLensParams
if err := dec.Decode(¶ms); err != nil {
return true, replyParseError(ctx, reply, err)
}
resp, err := server.CodeLens(ctx, ¶ms)
return true, reply(ctx, resp, err)
case MethodCodeLensResolve: // request
defer logger.Debug(MethodCodeLensResolve, zap.Error(err))
var params CodeLens
if err := dec.Decode(¶ms); err != nil {
return true, replyParseError(ctx, reply, err)
}
resp, err := server.CodeLensResolve(ctx, ¶ms)
return true, reply(ctx, resp, err)
case MethodTextDocumentColorPresentation: // request
defer logger.Debug(MethodTextDocumentColorPresentation, zap.Error(err))
var params ColorPresentationParams
if err := dec.Decode(¶ms); err != nil {
return true, replyParseError(ctx, reply, err)
}
resp, err := server.ColorPresentation(ctx, ¶ms)
return true, reply(ctx, resp, err)
case MethodTextDocumentCompletion: // request
defer logger.Debug(MethodTextDocumentCompletion, zap.Error(err))
var params CompletionParams
if err := dec.Decode(¶ms); err != nil {
return true, replyParseError(ctx, reply, err)
}
resp, err := server.Completion(ctx, ¶ms)
return true, reply(ctx, resp, err)
case MethodCompletionItemResolve: // request
defer logger.Debug(MethodCompletionItemResolve, zap.Error(err))
var params CompletionItem
if err := dec.Decode(¶ms); err != nil {
return true, replyParseError(ctx, reply, err)
}
resp, err := server.CompletionResolve(ctx, ¶ms)
return true, reply(ctx, resp, err)
case MethodTextDocumentDeclaration: // request
defer logger.Debug(MethodTextDocumentDeclaration, zap.Error(err))
var params DeclarationParams
if err := dec.Decode(¶ms); err != nil {
return true, replyParseError(ctx, reply, err)
}
resp, err := server.Declaration(ctx, ¶ms)
return true, reply(ctx, resp, err)
case MethodTextDocumentDefinition: // request
defer logger.Debug(MethodTextDocumentDefinition, zap.Error(err))
var params DefinitionParams
if err := dec.Decode(¶ms); err != nil {
return true, replyParseError(ctx, reply, err)
}
resp, err := server.Definition(ctx, ¶ms)
return true, reply(ctx, resp, err)
case MethodTextDocumentDidChange: // notification
defer logger.Debug(MethodTextDocumentDidChange, zap.Error(err))
var params DidChangeTextDocumentParams
if err := dec.Decode(¶ms); err != nil {
return true, replyParseError(ctx, reply, err)
}
err := server.DidChange(ctx, ¶ms)
return true, reply(ctx, nil, err)
case MethodWorkspaceDidChangeConfiguration: // notification
defer logger.Debug(MethodWorkspaceDidChangeConfiguration, zap.Error(err))
var params DidChangeConfigurationParams
if err := dec.Decode(¶ms); err != nil {
return true, replyParseError(ctx, reply, err)
}
err := server.DidChangeConfiguration(ctx, ¶ms)
return true, reply(ctx, nil, err)
case MethodWorkspaceDidChangeWatchedFiles: // notification
defer logger.Debug(MethodWorkspaceDidChangeWatchedFiles, zap.Error(err))
var params DidChangeWatchedFilesParams
if err := dec.Decode(¶ms); err != nil {
return true, replyParseError(ctx, reply, err)
}
err := server.DidChangeWatchedFiles(ctx, ¶ms)
return true, reply(ctx, nil, err)
case MethodWorkspaceDidChangeWorkspaceFolders: // notification
defer logger.Debug(MethodWorkspaceDidChangeWorkspaceFolders, zap.Error(err))
var params DidChangeWorkspaceFoldersParams
if err := dec.Decode(¶ms); err != nil {
return true, replyParseError(ctx, reply, err)
}
err := server.DidChangeWorkspaceFolders(ctx, ¶ms)
return true, reply(ctx, nil, err)
case MethodTextDocumentDidClose: // notification
defer logger.Debug(MethodTextDocumentDidClose, zap.Error(err))
var params DidCloseTextDocumentParams
if err := dec.Decode(¶ms); err != nil {
return true, replyParseError(ctx, reply, err)
}
err := server.DidClose(ctx, ¶ms)
return true, reply(ctx, nil, err)
case MethodTextDocumentDidOpen: // notification
defer logger.Debug(MethodTextDocumentDidOpen, zap.Error(err))
var params DidOpenTextDocumentParams
if err := dec.Decode(¶ms); err != nil {
return true, replyParseError(ctx, reply, err)
}
err := server.DidOpen(ctx, ¶ms)
return true, reply(ctx, nil, err)
case MethodTextDocumentDidSave: // notification
defer logger.Debug(MethodTextDocumentDidSave, zap.Error(err))
var params DidSaveTextDocumentParams
if err := dec.Decode(¶ms); err != nil {
return true, replyParseError(ctx, reply, err)
}
err := server.DidSave(ctx, ¶ms)
return true, reply(ctx, nil, err)
case MethodTextDocumentDocumentColor: // request
defer logger.Debug(MethodTextDocumentDocumentColor, zap.Error(err))
var params DocumentColorParams
if err := dec.Decode(¶ms); err != nil {
return true, replyParseError(ctx, reply, err)
}
resp, err := server.DocumentColor(ctx, ¶ms)
return true, reply(ctx, resp, err)
case MethodTextDocumentDocumentHighlight: // request
defer logger.Debug(MethodTextDocumentDocumentHighlight, zap.Error(err))
var params DocumentHighlightParams
if err := dec.Decode(¶ms); err != nil {
return true, replyParseError(ctx, reply, err)
}
resp, err := server.DocumentHighlight(ctx, ¶ms)
return true, reply(ctx, resp, err)
case MethodTextDocumentDocumentLink: // request
defer logger.Debug(MethodTextDocumentDocumentLink, zap.Error(err))
var params DocumentLinkParams
if err := dec.Decode(¶ms); err != nil {
return true, replyParseError(ctx, reply, err)
}
resp, err := server.DocumentLink(ctx, ¶ms)
return true, reply(ctx, resp, err)
case MethodDocumentLinkResolve: // request
defer logger.Debug(MethodDocumentLinkResolve, zap.Error(err))
var params DocumentLink
if err := dec.Decode(¶ms); err != nil {
return true, replyParseError(ctx, reply, err)
}
resp, err := server.DocumentLinkResolve(ctx, ¶ms)
return true, reply(ctx, resp, err)
case MethodTextDocumentDocumentSymbol: // request
defer logger.Debug(MethodTextDocumentDocumentSymbol, zap.Error(err))
var params DocumentSymbolParams
if err := dec.Decode(¶ms); err != nil {
return true, replyParseError(ctx, reply, err)
}
resp, err := server.DocumentSymbol(ctx, ¶ms)
return true, reply(ctx, resp, err)
case MethodWorkspaceExecuteCommand: // request
defer logger.Debug(MethodWorkspaceExecuteCommand, zap.Error(err))
var params ExecuteCommandParams
if err := dec.Decode(¶ms); err != nil {
return true, replyParseError(ctx, reply, err)
}
resp, err := server.ExecuteCommand(ctx, ¶ms)
return true, reply(ctx, resp, err)
case MethodTextDocumentFoldingRange: // request
defer logger.Debug(MethodTextDocumentFoldingRange, zap.Error(err))
var params FoldingRangeParams
if err := dec.Decode(¶ms); err != nil {
return true, replyParseError(ctx, reply, err)
}
resp, err := server.FoldingRanges(ctx, ¶ms)
return true, reply(ctx, resp, err)
case MethodTextDocumentFormatting: // request
defer logger.Debug(MethodTextDocumentFormatting, zap.Error(err))
var params DocumentFormattingParams
if err := dec.Decode(¶ms); err != nil {
return true, replyParseError(ctx, reply, err)
}
resp, err := server.Formatting(ctx, ¶ms)
return true, reply(ctx, resp, err)
case MethodTextDocumentHover: // request
defer logger.Debug(MethodTextDocumentHover, zap.Error(err))
var params HoverParams
if err := dec.Decode(¶ms); err != nil {
return true, replyParseError(ctx, reply, err)
}
resp, err := server.Hover(ctx, ¶ms)
return true, reply(ctx, resp, err)
case MethodTextDocumentImplementation: // request
defer logger.Debug(MethodTextDocumentImplementation, zap.Error(err))
var params ImplementationParams
if err := dec.Decode(¶ms); err != nil {
return true, replyParseError(ctx, reply, err)
}
resp, err := server.Implementation(ctx, ¶ms)
return true, reply(ctx, resp, err)
case MethodTextDocumentOnTypeFormatting: // request
defer logger.Debug(MethodTextDocumentOnTypeFormatting, zap.Error(err))
var params DocumentOnTypeFormattingParams
if err := dec.Decode(¶ms); err != nil {
return true, replyParseError(ctx, reply, err)
}
resp, err := server.OnTypeFormatting(ctx, ¶ms)
return true, reply(ctx, resp, err)
case MethodTextDocumentPrepareRename: // request
defer logger.Debug(MethodTextDocumentPrepareRename, zap.Error(err))
var params PrepareRenameParams
if err := dec.Decode(¶ms); err != nil {
return true, replyParseError(ctx, reply, err)
}
resp, err := server.PrepareRename(ctx, ¶ms)
return true, reply(ctx, resp, err)
case MethodTextDocumentRangeFormatting: // request
defer logger.Debug(MethodTextDocumentRangeFormatting, zap.Error(err))
var params DocumentRangeFormattingParams
if err := dec.Decode(¶ms); err != nil {
return true, replyParseError(ctx, reply, err)
}
resp, err := server.RangeFormatting(ctx, ¶ms)
return true, reply(ctx, resp, err)
case MethodTextDocumentReferences: // request
defer logger.Debug(MethodTextDocumentReferences, zap.Error(err))
var params ReferenceParams
if err := dec.Decode(¶ms); err != nil {
return true, replyParseError(ctx, reply, err)
}
resp, err := server.References(ctx, ¶ms)
return true, reply(ctx, resp, err)
case MethodTextDocumentRename: // request
defer logger.Debug(MethodTextDocumentRename, zap.Error(err))
var params RenameParams
if err := dec.Decode(¶ms); err != nil {
return true, replyParseError(ctx, reply, err)
}
resp, err := server.Rename(ctx, ¶ms)
return true, reply(ctx, resp, err)
case MethodTextDocumentSignatureHelp: // request
defer logger.Debug(MethodTextDocumentSignatureHelp, zap.Error(err))
var params SignatureHelpParams
if err := dec.Decode(¶ms); err != nil {
return true, replyParseError(ctx, reply, err)
}
resp, err := server.SignatureHelp(ctx, ¶ms)
return true, reply(ctx, resp, err)
case MethodWorkspaceSymbol: // request
defer logger.Debug(MethodWorkspaceSymbol, zap.Error(err))
var params WorkspaceSymbolParams
if err := dec.Decode(¶ms); err != nil {
return true, replyParseError(ctx, reply, err)
}
resp, err := server.Symbols(ctx, ¶ms)
return true, reply(ctx, resp, err)
case MethodTextDocumentTypeDefinition: // request
defer logger.Debug(MethodTextDocumentTypeDefinition, zap.Error(err))
var params TypeDefinitionParams
if err := dec.Decode(¶ms); err != nil {
return true, replyParseError(ctx, reply, err)
}
resp, err := server.TypeDefinition(ctx, ¶ms)
return true, reply(ctx, resp, err)
case MethodTextDocumentWillSave: // notification
defer logger.Debug(MethodTextDocumentWillSave, zap.Error(err))
var params WillSaveTextDocumentParams
if err := dec.Decode(¶ms); err != nil {
return true, replyParseError(ctx, reply, err)
}
err := server.WillSave(ctx, ¶ms)
return true, reply(ctx, nil, err)
case MethodTextDocumentWillSaveWaitUntil: // request
defer logger.Debug(MethodTextDocumentWillSaveWaitUntil, zap.Error(err))
var params WillSaveTextDocumentParams
if err := dec.Decode(¶ms); err != nil {
return true, replyParseError(ctx, reply, err)
}
resp, err := server.WillSaveWaitUntil(ctx, ¶ms)
return true, reply(ctx, resp, err)
case MethodShowDocument: // request
defer logger.Debug(MethodShowDocument, zap.Error(err))
var params ShowDocumentParams
if err := dec.Decode(¶ms); err != nil {
return true, replyParseError(ctx, reply, err)
}
resp, err := server.ShowDocument(ctx, ¶ms)
return true, reply(ctx, resp, err)
case MethodWillCreateFiles: // request
defer logger.Debug(MethodWillCreateFiles, zap.Error(err))
var params CreateFilesParams
if err := dec.Decode(¶ms); err != nil {
return true, replyParseError(ctx, reply, err)
}
resp, err := server.WillCreateFiles(ctx, ¶ms)
return true, reply(ctx, resp, err)
case MethodDidCreateFiles: // notification
defer logger.Debug(MethodDidCreateFiles, zap.Error(err))
var params CreateFilesParams
if err := dec.Decode(¶ms); err != nil {
return true, replyParseError(ctx, reply, err)
}
err := server.DidCreateFiles(ctx, ¶ms)
return true, reply(ctx, nil, err)
case MethodWillRenameFiles: // request
defer logger.Debug(MethodWillRenameFiles, zap.Error(err))
var params RenameFilesParams
if err := dec.Decode(¶ms); err != nil {
return true, replyParseError(ctx, reply, err)
}
resp, err := server.WillRenameFiles(ctx, ¶ms)
return true, reply(ctx, resp, err)
case MethodDidRenameFiles: // notification
defer logger.Debug(MethodDidRenameFiles, zap.Error(err))
var params RenameFilesParams
if err := dec.Decode(¶ms); err != nil {
return true, replyParseError(ctx, reply, err)
}
err := server.DidRenameFiles(ctx, ¶ms)
return true, reply(ctx, nil, err)
case MethodWillDeleteFiles: // request
defer logger.Debug(MethodWillDeleteFiles, zap.Error(err))
var params DeleteFilesParams
if err := dec.Decode(¶ms); err != nil {
return true, replyParseError(ctx, reply, err)
}
resp, err := server.WillDeleteFiles(ctx, ¶ms)
return true, reply(ctx, resp, err)
case MethodDidDeleteFiles: // notification
defer logger.Debug(MethodDidDeleteFiles, zap.Error(err))
var params DeleteFilesParams
if err := dec.Decode(¶ms); err != nil {
return true, replyParseError(ctx, reply, err)
}
err := server.DidDeleteFiles(ctx, ¶ms)
return true, reply(ctx, nil, err)
case MethodCodeLensRefresh: // request
defer logger.Debug(MethodCodeLensRefresh, zap.Error(err))
if len(req.Params()) > 0 {
return true, reply(ctx, nil, fmt.Errorf("expected no params: %w", jsonrpc2.ErrInvalidParams))
}
err := server.CodeLensRefresh(ctx)
return true, reply(ctx, nil, err)
case MethodTextDocumentPrepareCallHierarchy: // request
defer logger.Debug(MethodTextDocumentPrepareCallHierarchy, zap.Error(err))
var params CallHierarchyPrepareParams
if err := dec.Decode(¶ms); err != nil {
return true, replyParseError(ctx, reply, err)
}
resp, err := server.PrepareCallHierarchy(ctx, ¶ms)
return true, reply(ctx, resp, err)
case MethodCallHierarchyIncomingCalls: // request
defer logger.Debug(MethodCallHierarchyIncomingCalls, zap.Error(err))
var params CallHierarchyIncomingCallsParams
if err := dec.Decode(¶ms); err != nil {
return true, replyParseError(ctx, reply, err)
}
resp, err := server.IncomingCalls(ctx, ¶ms)
return true, reply(ctx, resp, err)
case MethodCallHierarchyOutgoingCalls: // request
defer logger.Debug(MethodCallHierarchyOutgoingCalls, zap.Error(err))
var params CallHierarchyOutgoingCallsParams
if err := dec.Decode(¶ms); err != nil {
return true, replyParseError(ctx, reply, err)
}
resp, err := server.OutgoingCalls(ctx, ¶ms)
return true, reply(ctx, resp, err)
case MethodSemanticTokensFull: // request
defer logger.Debug(MethodSemanticTokensFull, zap.Error(err))
var params SemanticTokensParams
if err := dec.Decode(¶ms); err != nil {
return true, replyParseError(ctx, reply, err)
}
resp, err := server.SemanticTokensFull(ctx, ¶ms)
return true, reply(ctx, resp, err)
case MethodSemanticTokensFullDelta: // request
defer logger.Debug(MethodSemanticTokensFullDelta, zap.Error(err))
var params SemanticTokensDeltaParams
if err := dec.Decode(¶ms); err != nil {
return true, replyParseError(ctx, reply, err)
}
resp, err := server.SemanticTokensFullDelta(ctx, ¶ms)
return true, reply(ctx, resp, err)
case MethodSemanticTokensRange: // request
defer logger.Debug(MethodSemanticTokensRange, zap.Error(err))
var params SemanticTokensRangeParams
if err := dec.Decode(¶ms); err != nil {
return true, replyParseError(ctx, reply, err)
}
resp, err := server.SemanticTokensRange(ctx, ¶ms)
return true, reply(ctx, resp, err)
case MethodSemanticTokensRefresh: // request
defer logger.Debug(MethodSemanticTokensRefresh, zap.Error(err))
if len(req.Params()) > 0 {
return true, reply(ctx, nil, fmt.Errorf("expected no params: %w", jsonrpc2.ErrInvalidParams))
}
err := server.SemanticTokensRefresh(ctx)
return true, reply(ctx, nil, err)
case MethodLinkedEditingRange: // request
defer logger.Debug(MethodLinkedEditingRange, zap.Error(err))
var params LinkedEditingRangeParams
if err := dec.Decode(¶ms); err != nil {
return true, replyParseError(ctx, reply, err)
}
resp, err := server.LinkedEditingRange(ctx, ¶ms)
return true, reply(ctx, resp, err)
case MethodMoniker: // request
defer logger.Debug(MethodMoniker, zap.Error(err))
var params MonikerParams
if err := dec.Decode(¶ms); err != nil {
return true, replyParseError(ctx, reply, err)
}
resp, err := server.Moniker(ctx, ¶ms)
return true, reply(ctx, resp, err)
default:
return false, nil
}
}
// Server represents a Language Server Protocol server.
type Server interface {
Initialize(ctx context.Context, params *InitializeParams) (result *InitializeResult, err error)
Initialized(ctx context.Context, params *InitializedParams) (err error)
Shutdown(ctx context.Context) (err error)
Exit(ctx context.Context) (err error)
WorkDoneProgressCancel(ctx context.Context, params *WorkDoneProgressCancelParams) (err error)
LogTrace(ctx context.Context, params *LogTraceParams) (err error)
SetTrace(ctx context.Context, params *SetTraceParams) (err error)
CodeAction(ctx context.Context, params *CodeActionParams) (result []CodeAction, err error)
CodeLens(ctx context.Context, params *CodeLensParams) (result []CodeLens, err error)
CodeLensResolve(ctx context.Context, params *CodeLens) (result *CodeLens, err error)
ColorPresentation(ctx context.Context, params *ColorPresentationParams) (result []ColorPresentation, err error)
Completion(ctx context.Context, params *CompletionParams) (result *CompletionList, err error)
CompletionResolve(ctx context.Context, params *CompletionItem) (result *CompletionItem, err error)
Declaration(ctx context.Context, params *DeclarationParams) (result []Location /* Declaration | DeclarationLink[] | null */, err error)
Definition(ctx context.Context, params *DefinitionParams) (result []Location /* Definition | DefinitionLink[] | null */, err error)
DidChange(ctx context.Context, params *DidChangeTextDocumentParams) (err error)
DidChangeConfiguration(ctx context.Context, params *DidChangeConfigurationParams) (err error)
DidChangeWatchedFiles(ctx context.Context, params *DidChangeWatchedFilesParams) (err error)
DidChangeWorkspaceFolders(ctx context.Context, params *DidChangeWorkspaceFoldersParams) (err error)
DidClose(ctx context.Context, params *DidCloseTextDocumentParams) (err error)
DidOpen(ctx context.Context, params *DidOpenTextDocumentParams) (err error)
DidSave(ctx context.Context, params *DidSaveTextDocumentParams) (err error)
DocumentColor(ctx context.Context, params *DocumentColorParams) (result []ColorInformation, err error)
DocumentHighlight(ctx context.Context, params *DocumentHighlightParams) (result []DocumentHighlight, err error)
DocumentLink(ctx context.Context, params *DocumentLinkParams) (result []DocumentLink, err error)
DocumentLinkResolve(ctx context.Context, params *DocumentLink) (result *DocumentLink, err error)
DocumentSymbol(ctx context.Context, params *DocumentSymbolParams) (result []interface{} /* []SymbolInformation | []DocumentSymbol */, err error)
ExecuteCommand(ctx context.Context, params *ExecuteCommandParams) (result interface{}, err error)
FoldingRanges(ctx context.Context, params *FoldingRangeParams) (result []FoldingRange, err error)
Formatting(ctx context.Context, params *DocumentFormattingParams) (result []TextEdit, err error)
Hover(ctx context.Context, params *HoverParams) (result *Hover, err error)
Implementation(ctx context.Context, params *ImplementationParams) (result []Location, err error)
OnTypeFormatting(ctx context.Context, params *DocumentOnTypeFormattingParams) (result []TextEdit, err error)
PrepareRename(ctx context.Context, params *PrepareRenameParams) (result *Range, err error)
RangeFormatting(ctx context.Context, params *DocumentRangeFormattingParams) (result []TextEdit, err error)
References(ctx context.Context, params *ReferenceParams) (result []Location, err error)
Rename(ctx context.Context, params *RenameParams) (result *WorkspaceEdit, err error)
SignatureHelp(ctx context.Context, params *SignatureHelpParams) (result *SignatureHelp, err error)
Symbols(ctx context.Context, params *WorkspaceSymbolParams) (result []SymbolInformation, err error)
TypeDefinition(ctx context.Context, params *TypeDefinitionParams) (result []Location, err error)
WillSave(ctx context.Context, params *WillSaveTextDocumentParams) (err error)
WillSaveWaitUntil(ctx context.Context, params *WillSaveTextDocumentParams) (result []TextEdit, err error)
ShowDocument(ctx context.Context, params *ShowDocumentParams) (result *ShowDocumentResult, err error)
WillCreateFiles(ctx context.Context, params *CreateFilesParams) (result *WorkspaceEdit, err error)
DidCreateFiles(ctx context.Context, params *CreateFilesParams) (err error)
WillRenameFiles(ctx context.Context, params *RenameFilesParams) (result *WorkspaceEdit, err error)
DidRenameFiles(ctx context.Context, params *RenameFilesParams) (err error)
WillDeleteFiles(ctx context.Context, params *DeleteFilesParams) (result *WorkspaceEdit, err error)
DidDeleteFiles(ctx context.Context, params *DeleteFilesParams) (err error)
CodeLensRefresh(ctx context.Context) (err error)
PrepareCallHierarchy(ctx context.Context, params *CallHierarchyPrepareParams) (result []CallHierarchyItem, err error)
IncomingCalls(ctx context.Context, params *CallHierarchyIncomingCallsParams) (result []CallHierarchyIncomingCall, err error)
OutgoingCalls(ctx context.Context, params *CallHierarchyOutgoingCallsParams) (result []CallHierarchyOutgoingCall, err error)
SemanticTokensFull(ctx context.Context, params *SemanticTokensParams) (result *SemanticTokens, err error)
SemanticTokensFullDelta(ctx context.Context, params *SemanticTokensDeltaParams) (result interface{} /* SemanticTokens | SemanticTokensDelta */, err error)
SemanticTokensRange(ctx context.Context, params *SemanticTokensRangeParams) (result *SemanticTokens, err error)
SemanticTokensRefresh(ctx context.Context) (err error)
LinkedEditingRange(ctx context.Context, params *LinkedEditingRangeParams) (result *LinkedEditingRanges, err error)
Moniker(ctx context.Context, params *MonikerParams) (result []Moniker, err error)
Request(ctx context.Context, method string, params interface{}) (result interface{}, err error)
}
// list of server methods.
const (
// MethodCancelRequest method name of "$/cancelRequest".
MethodCancelRequest = "$/cancelRequest"
// MethodInitialize method name of "initialize".
MethodInitialize = "initialize"
// MethodInitialized method name of "initialized".
MethodInitialized = "initialized"
// MethodShutdown method name of "shutdown".
MethodShutdown = "shutdown"
// MethodExit method name of "exit".
MethodExit = "exit"
// MethodWorkDoneProgressCancel method name of "window/workDoneProgress/cancel".
MethodWorkDoneProgressCancel = "window/workDoneProgress/cancel"
// MethodLogTrace method name of "$/logTrace".
MethodLogTrace = "$/logTrace"
// MethodSetTrace method name of "$/setTrace".
MethodSetTrace = "$/setTrace"
// MethodTextDocumentCodeAction method name of "textDocument/codeAction".
MethodTextDocumentCodeAction = "textDocument/codeAction"
// MethodTextDocumentCodeLens method name of "textDocument/codeLens".
MethodTextDocumentCodeLens = "textDocument/codeLens"
// MethodCodeLensResolve method name of "codeLens/resolve".
MethodCodeLensResolve = "codeLens/resolve"
// MethodTextDocumentColorPresentation method name of "textDocument/colorPresentation".
MethodTextDocumentColorPresentation = "textDocument/colorPresentation"
// MethodTextDocumentCompletion method name of "textDocument/completion".
MethodTextDocumentCompletion = "textDocument/completion"
// MethodCompletionItemResolve method name of "completionItem/resolve".
MethodCompletionItemResolve = "completionItem/resolve"
// MethodTextDocumentDeclaration method name of "textDocument/declaration".
MethodTextDocumentDeclaration = "textDocument/declaration"
// MethodTextDocumentDefinition method name of "textDocument/definition".
MethodTextDocumentDefinition = "textDocument/definition"
// MethodTextDocumentDidChange method name of "textDocument/didChange".
MethodTextDocumentDidChange = "textDocument/didChange"
// MethodWorkspaceDidChangeConfiguration method name of "workspace/didChangeConfiguration".
MethodWorkspaceDidChangeConfiguration = "workspace/didChangeConfiguration"
// MethodWorkspaceDidChangeWatchedFiles method name of "workspace/didChangeWatchedFiles".
MethodWorkspaceDidChangeWatchedFiles = "workspace/didChangeWatchedFiles"
// MethodWorkspaceDidChangeWorkspaceFolders method name of "workspace/didChangeWorkspaceFolders".
MethodWorkspaceDidChangeWorkspaceFolders = "workspace/didChangeWorkspaceFolders"
// MethodTextDocumentDidClose method name of "textDocument/didClose".
MethodTextDocumentDidClose = "textDocument/didClose"
// MethodTextDocumentDidOpen method name of "textDocument/didOpen".
MethodTextDocumentDidOpen = "textDocument/didOpen"
// MethodTextDocumentDidSave method name of "textDocument/didSave".
MethodTextDocumentDidSave = "textDocument/didSave"
// MethodTextDocumentDocumentColor method name of"textDocument/documentColor".
MethodTextDocumentDocumentColor = "textDocument/documentColor"
// MethodTextDocumentDocumentHighlight method name of "textDocument/documentHighlight".
MethodTextDocumentDocumentHighlight = "textDocument/documentHighlight"
// MethodTextDocumentDocumentLink method name of "textDocument/documentLink".
MethodTextDocumentDocumentLink = "textDocument/documentLink"
// MethodDocumentLinkResolve method name of "documentLink/resolve".
MethodDocumentLinkResolve = "documentLink/resolve"
// MethodTextDocumentDocumentSymbol method name of "textDocument/documentSymbol".
MethodTextDocumentDocumentSymbol = "textDocument/documentSymbol"
// MethodWorkspaceExecuteCommand method name of "workspace/executeCommand".
MethodWorkspaceExecuteCommand = "workspace/executeCommand"
// MethodTextDocumentFoldingRange method name of "textDocument/foldingRange".
MethodTextDocumentFoldingRange = "textDocument/foldingRange"
// MethodTextDocumentFormatting method name of "textDocument/formatting".
MethodTextDocumentFormatting = "textDocument/formatting"
// MethodTextDocumentHover method name of "textDocument/hover".
MethodTextDocumentHover = "textDocument/hover"
// MethodTextDocumentImplementation method name of "textDocument/implementation".
MethodTextDocumentImplementation = "textDocument/implementation"
// MethodTextDocumentOnTypeFormatting method name of "textDocument/onTypeFormatting".
MethodTextDocumentOnTypeFormatting = "textDocument/onTypeFormatting"
// MethodTextDocumentPrepareRename method name of "textDocument/prepareRename".
MethodTextDocumentPrepareRename = "textDocument/prepareRename"
// MethodTextDocumentRangeFormatting method name of "textDocument/rangeFormatting".
MethodTextDocumentRangeFormatting = "textDocument/rangeFormatting"
// MethodTextDocumentReferences method name of "textDocument/references".
MethodTextDocumentReferences = "textDocument/references"
// MethodTextDocumentRename method name of "textDocument/rename".
MethodTextDocumentRename = "textDocument/rename"
// MethodTextDocumentSignatureHelp method name of "textDocument/signatureHelp".
MethodTextDocumentSignatureHelp = "textDocument/signatureHelp"
// MethodWorkspaceSymbol method name of "workspace/symbol".
MethodWorkspaceSymbol = "workspace/symbol"
// MethodTextDocumentTypeDefinition method name of "textDocument/typeDefinition".
MethodTextDocumentTypeDefinition = "textDocument/typeDefinition"
// MethodTextDocumentWillSave method name of "textDocument/willSave".
MethodTextDocumentWillSave = "textDocument/willSave"
// MethodTextDocumentWillSaveWaitUntil method name of "textDocument/willSaveWaitUntil".
MethodTextDocumentWillSaveWaitUntil = "textDocument/willSaveWaitUntil"
// MethodShowDocument method name of "window/showDocument".
MethodShowDocument = "window/showDocument"
// MethodWillCreateFiles method name of "workspace/willCreateFiles".
MethodWillCreateFiles = "workspace/willCreateFiles"
// MethodDidCreateFiles method name of "workspace/didCreateFiles".
MethodDidCreateFiles = "workspace/didCreateFiles"
// MethodWillRenameFiles method name of "workspace/willRenameFiles".
MethodWillRenameFiles = "workspace/willRenameFiles"
// MethodDidRenameFiles method name of "workspace/didRenameFiles".
MethodDidRenameFiles = "workspace/didRenameFiles"
// MethodWillDeleteFiles method name of "workspace/willDeleteFiles".
MethodWillDeleteFiles = "workspace/willDeleteFiles"
// MethodDidDeleteFiles method name of "workspace/didDeleteFiles".
MethodDidDeleteFiles = "workspace/didDeleteFiles"
// MethodCodeLensRefresh method name of "workspace/codeLens/refresh".
MethodCodeLensRefresh = "workspace/codeLens/refresh"
// MethodTextDocumentPrepareCallHierarchy method name of "textDocument/prepareCallHierarchy".
MethodTextDocumentPrepareCallHierarchy = "textDocument/prepareCallHierarchy"