forked from microsoft/language-server-protocol
-
Notifications
You must be signed in to change notification settings - Fork 0
/
protocol.ts
868 lines (729 loc) · 19.3 KB
/
protocol.ts
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
/* --------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
* ------------------------------------------------------------------------------------------ */
'use strict';
import * as lsp from 'vscode-languageserver-protocol';
/**
* An `Id` to identify a vertex or an edge.
*/
export type Id = number | string;
/**
* An element in the graph.
*/
export interface Element {
id: Id;
type: 'vertex' | 'edge';
}
/**
* All know vertices literal types.
*/
export type VertexLiterals =
'metaData' |
'project' |
'range' |
'location' |
'document' |
'externalImportItem' |
'externalImportResult' |
'exportItem' |
'exportResult' |
'resultSet' |
'documentSymbolResult' |
'foldingRangeResult' |
'documentLinkResult' |
'diagnosticResult' |
'declarationResult' |
'definitionResult' |
'typeDefinitionResult' |
'hoverResult' |
'referenceResult' |
'implementationResult';
/**
* Uris are currently stored as strings.
*/
export type Uri = string;
export interface V extends Element {
id: Id;
type: 'vertex';
label: VertexLiterals;
}
/**
* A result set acts as a hub to share n LSP request results
* between different ranges.
*/
export interface ResultSet extends V {
label: 'resultSet';
}
/**
* All know range tag literal types.
*/
export type RangeTagLiterals = 'declaration' | 'definition' | 'reference' | 'unknown';
/**
* The range represents a declaration.
*/
export interface DeclarationTag {
/**
* A type identifier for the declaration tag.
*/
type: 'declaration';
/**
* The text covered by the range.
*/
text: string;
/**
* The symbol kind.
*/
kind: lsp.SymbolKind;
/**
* Indicates if this symbol is deprecated.
*/
deprecated?: boolean;
/**
* The full range of the declaration not including leading/trailing whitespace but everything else, e.g comments and code.
* The range must be included in fullRange.
*/
fullRange: lsp.Range;
/**
* Optional detail information for the declaration.
*/
detail?: string;
}
/**
* The range represents a definition
*/
export interface DefinitionTag {
/**
* A type identifier for the declaration tag.
*/
type: 'definition';
/**
* The text covered by the range
*/
text: string;
/**
* The symbol kind.
*/
kind: lsp.SymbolKind;
/**
* Indicates if this symbol is deprecated.
*/
deprecated?: boolean;
/**
* The full range of the definition not including leading/trailing whitespace but everything else, e.g comments and code.
* The range must be included in fullRange.
*/
fullRange: lsp.Range;
/**
* Optional detail information for the definition.
*/
detail?: string;
}
/**
* The range represents a reference.
*/
export interface ReferenceTag {
/**
* A type identifier for the reference tag.
*/
type: 'reference';
/**
* The text covered by the range.
*/
text: string;
}
/**
* The type of the range is unknown.
*/
export interface UnknownTag {
/**
* A type identifier for the unknown tag.
*/
type: 'unknown';
/**
* The text covered by the range.
*/
text: string;
}
/**
* All available range tag types.
*/
export type RangeTag = DefinitionTag | DeclarationTag | ReferenceTag | UnknownTag;
/**
* The const definitions for range tags.
*/
export namespace RangeTag {
/** definition tag */
export const definition: 'definition' = 'definition';
/** declaration tag */
export const declaration: 'declaration' = 'declaration';
/** reference tag */
export const reference: 'reference' = 'reference';
/** unknown tag */
export const unknown: 'unknown' = 'unknown';
}
/**
* A vertex representing a range inside a document.
*/
export interface Range extends V, lsp.Range {
label: 'range';
/**
* Some optional meta data for the range.
*/
tag?: RangeTag;
}
/**
* The id type of the range is a normal id.
*/
export type RangeId = Id;
/**
* A range representing a definition.
*/
export interface DefinitionRange extends Range {
/**
* The definition meta data.
*/
tag: DefinitionTag;
}
/**
* A range representing a declaration.
*/
export interface DeclarationRange extends Range {
/**
* The declaration meta data.
*/
tag: DeclarationTag;
}
/**
* A range representing a reference.
*/
export interface ReferenceRange extends Range {
/**
* The reference meta data.
*/
tag: ReferenceTag;
}
/**
* A location emittable in LSIF. It has no uri since
* like ranges locations should be connected to a document
* using a `contains`edge.
*/
export interface Location extends V {
/**
* The label property.
*/
label: 'location';
/**
* The location's range
*/
range: lsp.Range;
}
/**
* The meta data vertex.
*/
export interface MetaData extends V {
/**
* The label property.
*/
label: 'metaData';
/**
* The dump version
*/
version: string;
}
export type AdditionDataValueType = string | number | boolean | string[] | number[] | boolean[];
export interface AdditionalData {
[key: string]: AdditionDataValueType | AdditionalData | AdditionalData[];
}
/**
* A document tag allows Indexers to tag documents for special
* purposes
*/
export interface ProjectData extends AdditionalData {
}
/**
* A project vertex.
*/
export interface Project extends V {
/**
* The label property.
*/
label: 'project';
/**
* The project kind like 'typescript' or 'csharp'. See also the language ids
* in the [specification](https://microsoft.github.io/language-server-protocol/specification)
*/
kind: string;
/**
* The resource URI of the project file.
*/
resource?: Uri;
/**
* Optional project data specific to the programming language.
*/
data?: ProjectData;
/**
* Optional the content of the project file, `base64` encoded.
*/
contents?: string;
}
/**
* A document tag allows Indexers to tag documents for special
* purposes
*/
export interface DocumentData extends AdditionalData {
}
export type DocumentId = Id;
/**
* A vertex representing a document in the project
*/
export interface Document extends V {
/**
* The label property.
*/
label: 'document';
/**
* The Uri of the document.
*/
uri: Uri;
/**
* The document's language Id as defined in the LSP
* (https://microsoft.github.io/language-server-protocol/specification)
*/
languageId: string;
/**
* Optional document data specific to the programming language.
*/
data?: DocumentData;
/**
* Optional the content of the document, `based64` encoded
*/
contents?: string;
}
export namespace inline {
export interface ExternalImportItem {
/**
* A position independent handle to identify a range in a document.
*/
moniker: string;
/**
* The range ids this moniker refers to.
*/
rangeIds: RangeId[];
}
export interface ExportItem {
/**
* A position independent handle to identify a range in a document.
*/
moniker: string;
/**
* The range ids this moniker refers to.
*/
rangeIds: RangeId[];
}
}
/**
* An item in the external export result.
*/
export interface ExternalImportItem extends inline.ExternalImportItem, V {
label: 'externalImportItem';
}
export type ExternalImportResultId = Id;
/**
* The imported items of a document. The imported items can either
* be inlined or added to the import result using an item edge.
*/
export interface ExternalImportResult extends V {
label: 'externalImportResult';
/**
* The result when inlined.
*/
result?: inline.ExternalImportItem[];
}
/**
* An item in a export result.
*/
export interface ExportItem extends inline.ExportItem, V {
label: 'exportItem';
}
export type ExportResultId = Id;
/**
* The exported items of a document. The export items can either
* be inlined or added to the export result using an item edge.
*/
export interface ExportResult extends V {
label: 'exportResult';
/**
* The result when inlined.
*/
result?: inline.ExportItem[];
}
/**
* A range based document symbol. This allows to reuse already
* emitted ranges with a `declaration` tag in a document symbol
* result.
*/
export interface RangeBasedDocumentSymbol {
/**
* The range to reference.
*/
id: RangeId
/**
* The child symbols.
*/
children?: RangeBasedDocumentSymbol[];
}
/**
* A vertex representing the document symbol result.
*/
export interface DocumentSymbolResult extends V {
label: 'documentSymbolResult';
result: lsp.DocumentSymbol[] | RangeBasedDocumentSymbol[];
}
/**
* A vertex representing a diagnostic result.
*/
export interface DiagnosticResult extends V {
/**
* The label property.
*/
label: 'diagnosticResult';
/**
* The diagnostics.
*/
result: lsp.Diagnostic[];
}
/**
* A vertex representing a folding range result.
*/
export interface FoldingRangeResult extends V {
/**
* The label property.
*/
label: 'foldingRangeResult';
/**
* The actual folding ranges.
*/
result: lsp.FoldingRange[];
}
/**
* A vertex representing a document link result.
*/
export interface DocumentLinkResult extends V {
/**
* The label property.
*/
label: 'documentLinkResult';
/**
* The actual document links.
*/
result: lsp.DocumentLink[];
}
/**
* The LSP defines the result of a `textDocument/definition` request as
* `Location | Location[]. In the SIP we allow to use range ids as well.
*/
export type DeclarationResultTypeSingle = RangeId | lsp.Location;
export type DeclarationResultTypeMany = (RangeId | lsp.Location)[];
export type DeclarationResultType = DeclarationResultTypeSingle | DeclarationResultTypeMany;
export interface DeclarationResult extends V {
/**
* The label property.
*/
label: 'declarationResult';
/**
* The actual result.
*/
result: DeclarationResultType;
}
/**
* The LSP defines the result of a `textDocument/definition` request as
* `Location | Location[]. In the SIP we allow to use range ids as well.
*/
export type DefinitionResultTypeSingle = RangeId | lsp.Location;
export type DefinitionResultTypeMany = (RangeId | lsp.Location)[];
export type DefinitionResultType = DefinitionResultTypeSingle | DefinitionResultTypeMany;
/**
* A vertex representing a definition result.
*/
export interface DefinitionResult extends V {
/**
* The label property.
*/
label: 'definitionResult';
/**
* The actual result.
*/
result: DefinitionResultType;
}
/**
* The LSP defines the result of a `textDocument/typeDefinition` request as
* `Location | Location[]. In the SIP we allow to use range ids as well.
*/
export type TypeDefinitionResultTypeSingle = RangeId | lsp.Location;
export type TypeDefinitionResultTypeMany = (RangeId | lsp.Location)[];
export type TypeDefinitionResultType = TypeDefinitionResultTypeSingle | TypeDefinitionResultTypeMany;
/**
* A vertex representing a type definition result.
*/
export interface TypeDefinitionResult extends V {
/**
* The label property.
*/
label: 'typeDefinitionResult';
/**
* The actual result.
*/
result: TypeDefinitionResultType;
}
/**
* A vertex representing a Hover.
*
* Extends the `Hover` type defined in LSP.
*/
export interface HoverResult extends V {
/**
* The label property.
*/
label: 'hoverResult';
/**
* The hover result. This is the normal LSP hover result.
*/
result: lsp.Hover;
}
/**
* The id type of a reference result is a normal id.
*/
export type ReferenceResultId = Id;
/**
* A vertex representing a reference result.
*/
export interface ReferenceResult extends V {
/**
* The label property.
*/
label: 'referenceResult';
/**
* The declarations belonging to the reference result.
*/
declarations?: (RangeId | lsp.Location)[];
/**
* The definitions belonging to the reference result.
*/
definitions?: (RangeId | lsp.Location)[];
/**
* The references belonging to the reference result.
*/
references?: (RangeId | lsp.Location)[];
/**
* The reference results belonging to this reference result.
*/
referenceResults?: ReferenceResultId[];
}
/**
* The id type of an implementation result is a normal id.
*/
export type ImplementationResultId = Id;
/**
* A vertex representing an implementation result.
*/
export interface ImplementationResult extends V {
/**
* The label property.
*/
label: 'implementationResult';
/**
* The ranges and locations belong to the implementation result.
*/
result?: (RangeId | lsp.Location)[];
/**
* The other implementation results belonging to this result.
*/
implementationResults?: ImplementationResultId[];
}
/**
* All available vertex types
*/
export type Vertex =
MetaData |
Project |
Document |
ExternalImportItem |
ExternalImportResult |
ExportItem |
ExportResult |
ResultSet |
Range |
DocumentSymbolResult |
FoldingRangeResult |
DocumentLinkResult |
DiagnosticResult |
DefinitionResult |
DeclarationResult |
TypeDefinitionResult |
HoverResult |
ReferenceResult |
ImplementationResult;
/**
* All know edge literal types.
*/
export type EdgeLiterals =
'contains' |
'item' |
'refersTo' |
'exports' |
'imports' |
'textDocument/documentSymbol' |
'textDocument/foldingRange' |
'textDocument/documentLink' |
'textDocument/diagnostic' |
'textDocument/definition' |
'textDocument/declaration' |
'textDocument/typeDefinition' |
'textDocument/hover' |
'textDocument/references' |
'textDocument/implementation';
/**
* A common base type of all edge types. The type parameters `S` and `T` are for typing and
* documentation purpose only. An edge never holds a direct reference to a vertex. They are
* referenced by `Id`.
*/
export interface E<S extends V, T extends V, K extends EdgeLiterals> extends Element {
/* The brand. This is only necessary to make make type instantiation differ from each other. */
_?: [S, T];
id: Id;
type: 'edge';
label: K;
/**
* The id of the from Vertex.
*/
outV: Id;
/**
* The id of the to Vertex.
*/
inV: Id;
}
export interface ItemEdge<S extends V, T extends V> extends E<S, T, 'item'> {
property?: string;
}
/**
* An edge expressing containment relationship. The relationship exist between:
*
* - `Project` -> `Document`
* - `Package` -> `Document`
* - `Document` -> `Range`
*/
export type contains = E<Project, Document, 'contains'> | E<Document, Range, 'contains'>;
/**
* An edge associating a range with a result set. The relationship exists between:
*
* - `Range` -> `ResultSet`
*/
export type refersTo = E<Range, ResultSet, 'refersTo'>;
/**
* An edge associating a export result with a document. The relationship exists between:
*
* - `Document` -> `ExportResult`
*/
export type $exports = E<Document, ExportResult, 'exports'>;
/**
* An edge associating a external import result with a document. The relationship exists between:
*
* - `Document` -> `ExternalImportResult`
*/
export type $imports = E<Document, ExternalImportResult, 'imports'>;
/**
* An edge representing a item in a result set. The relationship exists between:
*
* - `ReferenceResult` -> `Range`
* - `ReferenceResult` -> `ReferenceResult`
* - `ExportResult` -> `ExportResultItem`
* - `ExternalImportResult` -> `ExternalImportItem`
*/
export type item = ItemEdge<ReferenceResult, Range> | ItemEdge<ReferenceResult, ReferenceResult> | ItemEdge<ExportResult, ExportItem> | ItemEdge<ExternalImportResult, ExternalImportItem>;
/**
* An edge representing a `textDocument/documentSymbol` relationship. The relationship exists between:
*
* - `Document` -> `DocumentSymbolResult`
*/
export type textDocument_documentSymbol = E<Document, DocumentSymbolResult, 'textDocument/documentSymbol'>;
/**
* An edge representing a `textDocument/foldingRange` relationship. The relationship exists between:
*
* - `Document` -> `FoldingRangeResult`
*/
export type textDocument_foldingRange = E<Document, FoldingRangeResult, 'textDocument/foldingRange'>;
/**
* An edge representing a `textDocument/documentLink` relationship. The relationship exists between:
*
* - `Document` -> `DocumentLinkResult`
*/
export type textDocument_documentLink = E<Document, DocumentLinkResult, 'textDocument/documentLink'>;
/**
* An edge representing a `textDocument/diagnostic` relationship. The relationship exists between:
*
* - `Project` -> `DiagnosticResult`
* - `Document` -> `DiagnosticResult`
*/
export type textDocument_diagnostic = E<Project, DiagnosticResult, 'textDocument/diagnostic'> | E<Document, DiagnosticResult, 'textDocument/diagnostic'>;
/**
* An edge representing a declaration relationship. The relationship exists between:
*
* - `Range` -> `DefinitionResult`
* - `ResultSet` -> `DefinitionResult`
*/
export type textDocument_declaration = E<Range, DeclarationResult, 'textDocument/declaration'> | E<ResultSet, DeclarationResult, 'textDocument/declaration'>;
/**
* An edge representing a definition relationship. The relationship exists between:
*
* - `Range` -> `DefinitionResult`
* - `ResultSet` -> `DefinitionResult`
*/
export type textDocument_definition = E<Range, DefinitionResult, 'textDocument/definition'> | E<ResultSet, DefinitionResult, 'textDocument/definition'>;
/**
* An edge representing a type definition relations ship. The relationship exists between:
*
* - `Range` -> `TypeDefinitionResult`
* - `ResultSet` -> `TypeDefinitionResult`
*/
export type textDocument_typeDefinition = E<Range, TypeDefinitionResult, 'textDocument/typeDefinition'> | E<ResultSet, TypeDefinitionResult, 'textDocument/typeDefinition'>;
/**
* An edge representing a hover relationship. The relationship exists between:
*
* - `Range` -> `HoverResult`
* - `ResultSet` -> `HoverResult`
*/
export type textDocument_hover = E<Range, HoverResult, 'textDocument/hover'> | E<ResultSet, HoverResult, 'textDocument/hover'>;
/**
* An edge representing a references relationship. The relationship exists between:
*
* - `Range` -> `ReferenceResult`
* - `ResultSet` -> `ReferenceResult`
*/
export type textDocument_references = E<Range, ReferenceResult, 'textDocument/references'> | E<ResultSet, ReferenceResult, 'textDocument/references'>;
/**
* An edge representing a implementation relationship. The relationship exists between:
*
* - `Range` -> `ImplementationResult`
* - `ResultSet` -> `ImplementationResult`
*/
export type textDocument_implementation = E<Range, ImplementationResult, 'textDocument/implementation'> | E<ResultSet, ImplementationResult, 'textDocument/implementation'>;
/**
*
* All available Edge types.
*/
export type Edge =
contains |
item |
refersTo |
$exports |
$imports |
textDocument_documentSymbol |
textDocument_foldingRange |
textDocument_documentLink |
textDocument_diagnostic |
textDocument_definition |
textDocument_typeDefinition |
textDocument_hover |
textDocument_references |
textDocument_implementation;