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
use super::*;
use serde::{de::DeserializeOwned, Serialize};
pub trait Request {
type Params: DeserializeOwned + Serialize;
type Result: DeserializeOwned + Serialize;
const METHOD: &'static str;
}
#[macro_export]
macro_rules! lsp_request {
("initialize") => {
$crate::request::Initialize
};
("shutdown") => {
$crate::request::Shutdown
};
("window/showMessageRequest") => {
$crate::request::ShowMessageRequest
};
("client/registerCapability") => {
$crate::request::RegisterCapability
};
("client/unregisterCapability") => {
$crate::request::UnregisterCapability
};
("workspace/symbol") => {
$crate::request::WorkspaceSymbol
};
("workspace/executeCommand") => {
$crate::request::ExecuteCommand
};
("textDocument/willSaveWaitUntil") => {
$crate::request::WillSaveWaitUntil
};
("textDocument/completion") => {
$crate::request::Completion
};
("completionItem/resolve") => {
$crate::request::ResolveCompletionItem
};
("textDocument/hover") => {
$crate::request::HoverRequest
};
("textDocument/signatureHelp") => {
$crate::request::SignatureHelpRequest
};
("textDocument/declaration") => {
$crate::request::GotoDeclaration
};
("textDocument/definition") => {
$crate::request::GotoDefinition
};
("textDocument/references") => {
$crate::request::References
};
("textDocument/documentHighlight") => {
$crate::request::DocumentHighlightRequest
};
("textDocument/documentSymbol") => {
$crate::request::DocumentSymbolRequest
};
("textDocument/codeAction") => {
$crate::request::CodeActionRequest
};
("textDocument/codeLens") => {
$crate::request::CodeLensRequest
};
("codeLens/resolve") => {
$crate::request::CodeLensResolve
};
("textDocument/documentLink") => {
$crate::request::DocumentLinkRequest
};
("documentLink/resolve") => {
$crate::request::DocumentLinkResolve
};
("workspace/applyEdit") => {
$crate::request::ApplyWorkspaceEdit
};
("textDocument/rangeFormatting") => {
$crate::request::RangeFormatting
};
("textDocument/onTypeFormatting") => {
$crate::request::OnTypeFormatting
};
("textDocument/formatting") => {
$crate::request::Formatting
};
("textDocument/rename") => {
$crate::request::Rename
};
("textDocument/documentColor") => {
$crate::request::DocumentColor
};
("textDocument/colorPresentation") => {
$crate::request::ColorPresentationRequest
};
("textDocument/foldingRange") => {
$crate::request::FoldingRangeRequest
};
("textDocument/prepareRename") => {
$crate::request::PrepareRenameRequest
};
("textDocument/implementation") => {
$crate::request::GotoImplementation
};
("textDocument/typeDefinition") => {
$crate::request::GotoTypeDefinition
};
("textDocument/selectionRange") => {
$crate::request::SelectionRangeRequest
};
("workspace/workspaceFolders") => {
$crate::request::WorkspaceFoldersRequest
};
("workspace/configuration") => {
$crate::request::WorkspaceConfiguration
};
("window/workDoneProgress/create") => {
$crate::request::WorkDoneProgressCreate
};
("callHierarchy/incomingCalls") => {
$crate::request::CallHierarchyIncomingCalls
};
("callHierarchy/outgoingCalls") => {
$crate::request::CallHierarchyOutgoingCalls
};
("textDocument/moniker") => {
$crate::request::MonikerRequest
};
("textDocument/linkedEditingRange") => {
$crate::request::LinkedEditingRange
};
("textDocument/prepareCallHierarchy") => {
$crate::request::CallHierarchyPrepare
};
("textDocument/semanticTokens/full") => {
$crate::request::SemanticTokensFullRequest
};
("textDocument/semanticTokens/full/delta") => {
$crate::request::SemanticTokensFullDeltaRequest
};
("textDocument/semanticTokens/range") => {
$crate::request::SemanticTokensRangeRequest
};
("workspace/willCreateFiles") => {
$crate::request::WillCreateFiles
};
("workspace/willRenameFiles") => {
$crate::request::WillRenameFiles
};
("workspace/willDeleteFiles") => {
$crate::request::WillDeleteFiles
};
("workspace/semanticTokens/refresh") => {
$crate::request::SemanticTokensRefesh
};
("workspace/codeLens/refresh") => {
$crate::request::CodeLensRefresh
};
("codeAction/resolve") => {
$crate::request::CodeActionResolveRequest
};
("window/showDocument") => {
$crate::request::ShowDocument
};
}
#[derive(Debug)]
pub enum Initialize {}
impl Request for Initialize {
type Params = InitializeParams;
type Result = InitializeResult;
const METHOD: &'static str = "initialize";
}
#[derive(Debug)]
pub enum Shutdown {}
impl Request for Shutdown {
type Params = ();
type Result = ();
const METHOD: &'static str = "shutdown";
}
#[derive(Debug)]
pub enum ShowMessageRequest {}
impl Request for ShowMessageRequest {
type Params = ShowMessageRequestParams;
type Result = Option<MessageActionItem>;
const METHOD: &'static str = "window/showMessageRequest";
}
#[derive(Debug)]
pub enum RegisterCapability {}
impl Request for RegisterCapability {
type Params = RegistrationParams;
type Result = ();
const METHOD: &'static str = "client/registerCapability";
}
#[derive(Debug)]
pub enum UnregisterCapability {}
impl Request for UnregisterCapability {
type Params = UnregistrationParams;
type Result = ();
const METHOD: &'static str = "client/unregisterCapability";
}
#[derive(Debug)]
pub enum Completion {}
impl Request for Completion {
type Params = CompletionParams;
type Result = Option<CompletionResponse>;
const METHOD: &'static str = "textDocument/completion";
}
#[derive(Debug)]
pub enum ResolveCompletionItem {}
impl Request for ResolveCompletionItem {
type Params = CompletionItem;
type Result = CompletionItem;
const METHOD: &'static str = "completionItem/resolve";
}
#[derive(Debug)]
pub enum HoverRequest {}
impl Request for HoverRequest {
type Params = HoverParams;
type Result = Option<Hover>;
const METHOD: &'static str = "textDocument/hover";
}
#[derive(Debug)]
pub enum SignatureHelpRequest {}
impl Request for SignatureHelpRequest {
type Params = SignatureHelpParams;
type Result = Option<SignatureHelp>;
const METHOD: &'static str = "textDocument/signatureHelp";
}
#[derive(Debug)]
pub enum GotoDeclaration {}
pub type GotoDeclarationParams = GotoDefinitionParams;
pub type GotoDeclarationResponse = GotoDefinitionResponse;
impl Request for GotoDeclaration {
type Params = GotoDeclarationParams;
type Result = Option<GotoDeclarationResponse>;
const METHOD: &'static str = "textDocument/declaration";
}
#[derive(Debug)]
pub enum GotoDefinition {}
impl Request for GotoDefinition {
type Params = GotoDefinitionParams;
type Result = Option<GotoDefinitionResponse>;
const METHOD: &'static str = "textDocument/definition";
}
#[derive(Debug)]
pub enum References {}
impl Request for References {
type Params = ReferenceParams;
type Result = Option<Vec<Location>>;
const METHOD: &'static str = "textDocument/references";
}
#[derive(Debug)]
pub enum GotoTypeDefinition {}
pub type GotoTypeDefinitionParams = GotoDefinitionParams;
pub type GotoTypeDefinitionResponse = GotoDefinitionResponse;
impl Request for GotoTypeDefinition {
type Params = GotoTypeDefinitionParams;
type Result = Option<GotoTypeDefinitionResponse>;
const METHOD: &'static str = "textDocument/typeDefinition";
}
#[derive(Debug)]
pub enum GotoImplementation {}
pub type GotoImplementationParams = GotoTypeDefinitionParams;
pub type GotoImplementationResponse = GotoDefinitionResponse;
impl Request for GotoImplementation {
type Params = GotoImplementationParams;
type Result = Option<GotoImplementationResponse>;
const METHOD: &'static str = "textDocument/implementation";
}
#[derive(Debug)]
pub enum DocumentHighlightRequest {}
impl Request for DocumentHighlightRequest {
type Params = DocumentHighlightParams;
type Result = Option<Vec<DocumentHighlight>>;
const METHOD: &'static str = "textDocument/documentHighlight";
}
#[derive(Debug)]
pub enum DocumentSymbolRequest {}
impl Request for DocumentSymbolRequest {
type Params = DocumentSymbolParams;
type Result = Option<DocumentSymbolResponse>;
const METHOD: &'static str = "textDocument/documentSymbol";
}
#[derive(Debug)]
pub enum WorkspaceSymbol {}
impl Request for WorkspaceSymbol {
type Params = WorkspaceSymbolParams;
type Result = Option<Vec<SymbolInformation>>;
const METHOD: &'static str = "workspace/symbol";
}
#[derive(Debug)]
pub enum ExecuteCommand {}
impl Request for ExecuteCommand {
type Params = ExecuteCommandParams;
type Result = Option<Value>;
const METHOD: &'static str = "workspace/executeCommand";
}
#[derive(Debug)]
pub enum WillSaveWaitUntil {}
impl Request for WillSaveWaitUntil {
type Params = WillSaveTextDocumentParams;
type Result = Option<Vec<TextEdit>>;
const METHOD: &'static str = "textDocument/willSaveWaitUntil";
}
#[derive(Debug)]
pub enum ApplyWorkspaceEdit {}
impl Request for ApplyWorkspaceEdit {
type Params = ApplyWorkspaceEditParams;
type Result = ApplyWorkspaceEditResponse;
const METHOD: &'static str = "workspace/applyEdit";
}
#[derive(Debug)]
pub enum WorkspaceConfiguration {}
impl Request for WorkspaceConfiguration {
type Params = ConfigurationParams;
type Result = Vec<Value>;
const METHOD: &'static str = "workspace/configuration";
}
#[derive(Debug)]
pub enum CodeActionRequest {}
impl Request for CodeActionRequest {
type Params = CodeActionParams;
type Result = Option<CodeActionResponse>;
const METHOD: &'static str = "textDocument/codeAction";
}
#[derive(Debug)]
pub enum CodeActionResolveRequest {}
impl Request for CodeActionResolveRequest {
type Params = CodeAction;
type Result = CodeAction;
const METHOD: &'static str = "codeAction/resolve";
}
#[derive(Debug)]
pub enum CodeLensRequest {}
impl Request for CodeLensRequest {
type Params = CodeLensParams;
type Result = Option<Vec<CodeLens>>;
const METHOD: &'static str = "textDocument/codeLens";
}
#[derive(Debug)]
pub enum CodeLensResolve {}
impl Request for CodeLensResolve {
type Params = CodeLens;
type Result = CodeLens;
const METHOD: &'static str = "codeLens/resolve";
}
#[derive(Debug)]
pub enum DocumentLinkRequest {}
impl Request for DocumentLinkRequest {
type Params = DocumentLinkParams;
type Result = Option<Vec<DocumentLink>>;
const METHOD: &'static str = "textDocument/documentLink";
}
#[derive(Debug)]
pub enum DocumentLinkResolve {}
impl Request for DocumentLinkResolve {
type Params = DocumentLink;
type Result = DocumentLink;
const METHOD: &'static str = "documentLink/resolve";
}
#[derive(Debug)]
pub enum Formatting {}
impl Request for Formatting {
type Params = DocumentFormattingParams;
type Result = Option<Vec<TextEdit>>;
const METHOD: &'static str = "textDocument/formatting";
}
#[derive(Debug)]
pub enum RangeFormatting {}
impl Request for RangeFormatting {
type Params = DocumentRangeFormattingParams;
type Result = Option<Vec<TextEdit>>;
const METHOD: &'static str = "textDocument/rangeFormatting";
}
#[derive(Debug)]
pub enum OnTypeFormatting {}
impl Request for OnTypeFormatting {
type Params = DocumentOnTypeFormattingParams;
type Result = Option<Vec<TextEdit>>;
const METHOD: &'static str = "textDocument/onTypeFormatting";
}
#[derive(Debug)]
pub enum LinkedEditingRange {}
impl Request for LinkedEditingRange {
type Params = LinkedEditingRangeParams;
type Result = Option<LinkedEditingRanges>;
const METHOD: &'static str = "textDocument/linkedEditingRange";
}
#[derive(Debug)]
pub enum Rename {}
impl Request for Rename {
type Params = RenameParams;
type Result = Option<WorkspaceEdit>;
const METHOD: &'static str = "textDocument/rename";
}
#[derive(Debug)]
pub enum DocumentColor {}
impl Request for DocumentColor {
type Params = DocumentColorParams;
type Result = Vec<ColorInformation>;
const METHOD: &'static str = "textDocument/documentColor";
}
#[derive(Debug)]
pub enum ColorPresentationRequest {}
impl Request for ColorPresentationRequest {
type Params = ColorPresentationParams;
type Result = Vec<ColorPresentation>;
const METHOD: &'static str = "textDocument/colorPresentation";
}
#[derive(Debug)]
pub enum FoldingRangeRequest {}
impl Request for FoldingRangeRequest {
type Params = FoldingRangeParams;
type Result = Option<Vec<FoldingRange>>;
const METHOD: &'static str = "textDocument/foldingRange";
}
#[derive(Debug)]
pub enum PrepareRenameRequest {}
impl Request for PrepareRenameRequest {
type Params = TextDocumentPositionParams;
type Result = Option<PrepareRenameResponse>;
const METHOD: &'static str = "textDocument/prepareRename";
}
#[derive(Debug)]
pub enum WorkspaceFoldersRequest {}
impl Request for WorkspaceFoldersRequest {
type Params = ();
type Result = Option<Vec<WorkspaceFolder>>;
const METHOD: &'static str = "workspace/workspaceFolders";
}
#[derive(Debug)]
pub enum WorkDoneProgressCreate {}
impl Request for WorkDoneProgressCreate {
type Params = WorkDoneProgressCreateParams;
type Result = ();
const METHOD: &'static str = "window/workDoneProgress/create";
}
pub enum SelectionRangeRequest {}
impl Request for SelectionRangeRequest {
type Params = SelectionRangeParams;
type Result = Option<Vec<SelectionRange>>;
const METHOD: &'static str = "textDocument/selectionRange";
}
pub enum CallHierarchyPrepare {}
impl Request for CallHierarchyPrepare {
type Params = CallHierarchyPrepareParams;
type Result = Option<Vec<CallHierarchyItem>>;
const METHOD: &'static str = "textDocument/prepareCallHierarchy";
}
pub enum CallHierarchyIncomingCalls {}
impl Request for CallHierarchyIncomingCalls {
type Params = CallHierarchyIncomingCallsParams;
type Result = Option<Vec<CallHierarchyIncomingCall>>;
const METHOD: &'static str = "callHierarchy/incomingCalls";
}
pub enum CallHierarchyOutgoingCalls {}
impl Request for CallHierarchyOutgoingCalls {
type Params = CallHierarchyOutgoingCallsParams;
type Result = Option<Vec<CallHierarchyOutgoingCall>>;
const METHOD: &'static str = "callHierarchy/outgoingCalls";
}
pub enum SemanticTokensFullRequest {}
impl Request for SemanticTokensFullRequest {
type Params = SemanticTokensParams;
type Result = Option<SemanticTokensResult>;
const METHOD: &'static str = "textDocument/semanticTokens/full";
}
pub enum SemanticTokensFullDeltaRequest {}
impl Request for SemanticTokensFullDeltaRequest {
type Params = SemanticTokensDeltaParams;
type Result = Option<SemanticTokensFullDeltaResult>;
const METHOD: &'static str = "textDocument/semanticTokens/full/delta";
}
pub enum SemanticTokensRangeRequest {}
impl Request for SemanticTokensRangeRequest {
type Params = SemanticTokensRangeParams;
type Result = Option<SemanticTokensRangeResult>;
const METHOD: &'static str = "textDocument/semanticTokens/range";
}
pub enum SemanticTokensRefesh {}
impl Request for SemanticTokensRefesh {
type Params = ();
type Result = ();
const METHOD: &'static str = "workspace/semanticTokens/refresh";
}
pub enum CodeLensRefresh {}
impl Request for CodeLensRefresh {
type Params = ();
type Result = ();
const METHOD: &'static str = "workspace/codeLens/refresh";
}
pub enum WillCreateFiles {}
impl Request for WillCreateFiles {
type Params = CreateFilesParams;
type Result = Option<WorkspaceEdit>;
const METHOD: &'static str = "workspace/willCreateFiles";
}
pub enum WillRenameFiles {}
impl Request for WillRenameFiles {
type Params = RenameFilesParams;
type Result = Option<WorkspaceEdit>;
const METHOD: &'static str = "workspace/willRenameFiles";
}
pub enum WillDeleteFiles {}
impl Request for WillDeleteFiles {
type Params = DeleteFilesParams;
type Result = Option<WorkspaceEdit>;
const METHOD: &'static str = "workspace/willDeleteFiles";
}
pub enum ShowDocument {}
impl Request for ShowDocument {
type Params = ShowDocumentParams;
type Result = ShowDocumentResult;
const METHOD: &'static str = "window/showDocument";
}
pub enum MonikerRequest {}
impl Request for MonikerRequest {
type Params = MonikerParams;
type Result = Option<Vec<Moniker>>;
const METHOD: &'static str = "textDocument/moniker";
}
#[cfg(test)]
mod test {
use super::*;
fn fake_call<R>()
where
R: Request,
R::Params: serde::Serialize,
R::Result: serde::de::DeserializeOwned,
{
}
macro_rules! check_macro {
($name:tt) => {
assert_eq!(<lsp_request!($name) as Request>::METHOD, $name);
fake_call::<lsp_request!($name)>();
};
}
#[test]
fn check_macro_definitions() {
check_macro!("initialize");
check_macro!("shutdown");
check_macro!("window/showDocument");
check_macro!("window/showMessageRequest");
check_macro!("window/workDoneProgress/create");
check_macro!("client/registerCapability");
check_macro!("client/unregisterCapability");
check_macro!("textDocument/willSaveWaitUntil");
check_macro!("textDocument/completion");
check_macro!("textDocument/hover");
check_macro!("textDocument/signatureHelp");
check_macro!("textDocument/declaration");
check_macro!("textDocument/definition");
check_macro!("textDocument/references");
check_macro!("textDocument/documentHighlight");
check_macro!("textDocument/documentSymbol");
check_macro!("textDocument/codeAction");
check_macro!("textDocument/codeLens");
check_macro!("textDocument/documentLink");
check_macro!("textDocument/rangeFormatting");
check_macro!("textDocument/onTypeFormatting");
check_macro!("textDocument/formatting");
check_macro!("textDocument/rename");
check_macro!("textDocument/documentColor");
check_macro!("textDocument/colorPresentation");
check_macro!("textDocument/foldingRange");
check_macro!("textDocument/prepareRename");
check_macro!("textDocument/implementation");
check_macro!("textDocument/selectionRange");
check_macro!("textDocument/typeDefinition");
check_macro!("textDocument/moniker");
check_macro!("textDocument/linkedEditingRange");
check_macro!("textDocument/prepareCallHierarchy");
check_macro!("textDocument/semanticTokens/full");
check_macro!("textDocument/semanticTokens/full/delta");
check_macro!("textDocument/semanticTokens/range");
check_macro!("workspace/applyEdit");
check_macro!("workspace/symbol");
check_macro!("workspace/executeCommand");
check_macro!("workspace/configuration");
check_macro!("workspace/willCreateFiles");
check_macro!("workspace/willRenameFiles");
check_macro!("workspace/willDeleteFiles");
check_macro!("workspace/workspaceFolders");
check_macro!("workspace/semanticTokens/refresh");
check_macro!("workspace/codeLens/refresh");
check_macro!("codeAction/resolve");
check_macro!("codeLens/resolve");
check_macro!("completionItem/resolve");
check_macro!("documentLink/resolve");
check_macro!("callHierarchy/incomingCalls");
check_macro!("callHierarchy/outgoingCalls");
}
#[test]
#[cfg(feature = "proposed")]
fn check_proposed_macro_definitions() {}
}