-
Notifications
You must be signed in to change notification settings - Fork 328
/
main.ts
4348 lines (3882 loc) · 123 KB
/
main.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
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
/* --------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
* ------------------------------------------------------------------------------------------ */
'use strict';
/**
* A tagging type for string properties that are actually document URIs.
*/
export type DocumentUri = string;
export namespace DocumentUri {
export function is(value: any): value is DocumentUri {
return typeof value === 'string';
}
}
/**
* A tagging type for string properties that are actually URIs
*
* @since 3.16.0
*/
export type URI = string;
export namespace URI {
export function is(value: any): value is URI {
return typeof value === 'string';
}
}
/**
* Defines an integer in the range of -2^31 to 2^31 - 1.
*/
export type integer = number;
export namespace integer {
export const MIN_VALUE = -2147483648;
export const MAX_VALUE = 2147483647;
export function is(value: any): value is integer {
return typeof value === 'number' && MIN_VALUE <= value && value <= MAX_VALUE;
}
}
/**
* Defines an unsigned integer in the range of 0 to 2^31 - 1.
*/
export type uinteger = number;
export namespace uinteger {
export const MIN_VALUE = 0;
export const MAX_VALUE = 2147483647;
export function is(value: any): value is uinteger {
return typeof value === 'number' && MIN_VALUE <= value && value <= MAX_VALUE;
}
}
/**
* Defines a decimal number. Since decimal numbers are very
* rare in the language server specification we denote the
* exact range with every decimal using the mathematics
* interval notations (e.g. [0, 1] denotes all decimals d with
* 0 <= d <= 1.
*/
export type decimal = number;
/**
* The LSP any type
*
* @since 3.17.0
*/
export type LSPAny = LSPObject | LSPArray | string | integer | uinteger | decimal | boolean | null;
/**
* LSP object definition.
*
* @since 3.17.0
*/
export type LSPObject = { [key: string]: LSPAny };
/**
* LSP arrays.
*
* @since 3.17.0
*/
export type LSPArray = LSPAny[];
/**
* Position in a text document expressed as zero-based line and character offset.
* The offsets are based on a UTF-16 string representation. So a string of the form
* `a𐐀b` the character offset of the character `a` is 0, the character offset of `𐐀`
* is 1 and the character offset of b is 3 since `𐐀` is represented using two code
* units in UTF-16.
*
* Positions are line end character agnostic. So you can not specify a position that
* denotes `\r|\n` or `\n|` where `|` represents the character offset.
*/
export interface Position {
/**
* Line position in a document (zero-based).
*/
line: uinteger;
/**
* Character offset on a line in a document (zero-based). Assuming that the line is
* represented as a string, the `character` value represents the gap between the
* `character` and `character + 1`.
*
* If the character value is greater than the line length it defaults back to the
* line length.
*/
character: uinteger;
}
/**
* The Position namespace provides helper functions to work with
* [Position](#Position) literals.
*/
export namespace Position {
/**
* Creates a new Position literal from the given line and character.
* @param line The position's line.
* @param character The position's character.
*/
export function create(line: uinteger, character: uinteger): Position {
if (line === Number.MAX_VALUE) { line = uinteger.MAX_VALUE; }
if (character === Number.MAX_VALUE) { character = uinteger.MAX_VALUE; }
return { line, character };
}
/**
* Checks whether the given literal conforms to the [Position](#Position) interface.
*/
export function is(value: any): value is Position {
let candidate = value as Position;
return Is.objectLiteral(candidate) && Is.uinteger(candidate.line) && Is.uinteger(candidate.character);
}
}
/**
* A range in a text document expressed as (zero-based) start and end positions.
*
* If you want to specify a range that contains a line including the line ending
* character(s) then use an end position denoting the start of the next line.
* For example:
* ```ts
* {
* start: { line: 5, character: 23 }
* end : { line 6, character : 0 }
* }
* ```
*/
export interface Range {
/**
* The range's start position
*/
start: Position;
/**
* The range's end position.
*/
end: Position;
}
/**
* The Range namespace provides helper functions to work with
* [Range](#Range) literals.
*/
export namespace Range {
/**
* Create a new Range literal.
* @param start The range's start position.
* @param end The range's end position.
*/
export function create(start: Position, end: Position): Range;
/**
* Create a new Range literal.
* @param startLine The start line number.
* @param startCharacter The start character.
* @param endLine The end line number.
* @param endCharacter The end character.
*/
export function create(startLine: uinteger, startCharacter: uinteger, endLine: uinteger, endCharacter: uinteger): Range;
export function create(one: Position | uinteger, two: Position | uinteger, three?: uinteger, four?: uinteger): Range {
if (Is.uinteger(one) && Is.uinteger(two) && Is.uinteger(three) && Is.uinteger(four)) {
return { start: Position.create(one, two), end: Position.create(three, four) };
} else if (Position.is(one) && Position.is(two)) {
return { start: one, end: two };
} else {
throw new Error(`Range#create called with invalid arguments[${one}, ${two}, ${three}, ${four}]`);
}
}
/**
* Checks whether the given literal conforms to the [Range](#Range) interface.
*/
export function is(value: any): value is Range {
let candidate = value as Range;
return Is.objectLiteral(candidate) && Position.is(candidate.start) && Position.is(candidate.end);
}
}
/**
* Represents a location inside a resource, such as a line
* inside a text file.
*/
export interface Location {
uri: DocumentUri;
range: Range;
}
/**
* The Location namespace provides helper functions to work with
* [Location](#Location) literals.
*/
export namespace Location {
/**
* Creates a Location literal.
* @param uri The location's uri.
* @param range The location's range.
*/
export function create(uri: DocumentUri, range: Range): Location {
return { uri, range };
}
/**
* Checks whether the given literal conforms to the [Location](#Location) interface.
*/
export function is(value: any): value is Location {
let candidate = value as Location;
return Is.defined(candidate) && Range.is(candidate.range) && (Is.string(candidate.uri) || Is.undefined(candidate.uri));
}
}
/**
* Represents the connection of two locations. Provides additional metadata over normal [locations](#Location),
* including an origin range.
*/
export interface LocationLink {
/**
* Span of the origin of this link.
*
* Used as the underlined span for mouse definition hover. Defaults to the word range at
* the definition position.
*/
originSelectionRange?: Range;
/**
* The target resource identifier of this link.
*/
targetUri: DocumentUri;
/**
* The full target range of this link. If the target for example is a symbol then target range is the
* range enclosing this symbol not including leading/trailing whitespace but everything else
* like comments. This information is typically used to highlight the range in the editor.
*/
targetRange: Range;
/**
* The range that should be selected and revealed when this link is being followed, e.g the name of a function.
* Must be contained by the the `targetRange`. See also `DocumentSymbol#range`
*/
targetSelectionRange: Range;
}
/**
* The LocationLink namespace provides helper functions to work with
* [LocationLink](#LocationLink) literals.
*/
export namespace LocationLink {
/**
* Creates a LocationLink literal.
* @param targetUri The definition's uri.
* @param targetRange The full range of the definition.
* @param targetSelectionRange The span of the symbol definition at the target.
* @param originSelectionRange The span of the symbol being defined in the originating source file.
*/
export function create(targetUri: DocumentUri, targetRange: Range, targetSelectionRange: Range, originSelectionRange?: Range): LocationLink {
return { targetUri, targetRange, targetSelectionRange, originSelectionRange };
}
/**
* Checks whether the given literal conforms to the [LocationLink](#LocationLink) interface.
*/
export function is(value: any): value is LocationLink {
let candidate = value as LocationLink;
return Is.defined(candidate) && Range.is(candidate.targetRange) && Is.string(candidate.targetUri)
&& Range.is(candidate.targetSelectionRange)
&& (Range.is(candidate.originSelectionRange) || Is.undefined(candidate.originSelectionRange));
}
}
/**
* Represents a color in RGBA space.
*/
export interface Color {
/**
* The red component of this color in the range [0-1].
*/
readonly red: decimal;
/**
* The green component of this color in the range [0-1].
*/
readonly green: decimal;
/**
* The blue component of this color in the range [0-1].
*/
readonly blue: decimal;
/**
* The alpha component of this color in the range [0-1].
*/
readonly alpha: decimal;
}
/**
* The Color namespace provides helper functions to work with
* [Color](#Color) literals.
*/
export namespace Color {
/**
* Creates a new Color literal.
*/
export function create(red: decimal, green: decimal, blue: decimal, alpha: decimal): Color {
return {
red,
green,
blue,
alpha,
};
}
/**
* Checks whether the given literal conforms to the [Color](#Color) interface.
*/
export function is(value: any): value is Color {
const candidate = value as Color;
return Is.objectLiteral(candidate) && Is.numberRange(candidate.red, 0, 1)
&& Is.numberRange(candidate.green, 0, 1)
&& Is.numberRange(candidate.blue, 0, 1)
&& Is.numberRange(candidate.alpha, 0, 1);
}
}
/**
* Represents a color range from a document.
*/
export interface ColorInformation {
/**
* The range in the document where this color appears.
*/
range: Range;
/**
* The actual color value for this color range.
*/
color: Color;
}
/**
* The ColorInformation namespace provides helper functions to work with
* [ColorInformation](#ColorInformation) literals.
*/
export namespace ColorInformation {
/**
* Creates a new ColorInformation literal.
*/
export function create(range: Range, color: Color): ColorInformation {
return {
range,
color,
};
}
/**
* Checks whether the given literal conforms to the [ColorInformation](#ColorInformation) interface.
*/
export function is(value: any): value is ColorInformation {
const candidate = value as ColorInformation;
return Is.objectLiteral(candidate) && Range.is(candidate.range) && Color.is(candidate.color);
}
}
export interface ColorPresentation {
/**
* The label of this color presentation. It will be shown on the color
* picker header. By default this is also the text that is inserted when selecting
* this color presentation.
*/
label: string;
/**
* An [edit](#TextEdit) which is applied to a document when selecting
* this presentation for the color. When `falsy` the [label](#ColorPresentation.label)
* is used.
*/
textEdit?: TextEdit;
/**
* An optional array of additional [text edits](#TextEdit) that are applied when
* selecting this color presentation. Edits must not overlap with the main [edit](#ColorPresentation.textEdit) nor with themselves.
*/
additionalTextEdits?: TextEdit[];
}
/**
* The Color namespace provides helper functions to work with
* [ColorPresentation](#ColorPresentation) literals.
*/
export namespace ColorPresentation {
/**
* Creates a new ColorInformation literal.
*/
export function create(label: string, textEdit?: TextEdit, additionalTextEdits?: TextEdit[]): ColorPresentation {
return {
label,
textEdit,
additionalTextEdits,
};
}
/**
* Checks whether the given literal conforms to the [ColorInformation](#ColorInformation) interface.
*/
export function is(value: any): value is ColorPresentation {
const candidate = value as ColorPresentation;
return Is.objectLiteral(candidate) && Is.string(candidate.label)
&& (Is.undefined(candidate.textEdit) || TextEdit.is(candidate))
&& (Is.undefined(candidate.additionalTextEdits) || Is.typedArray(candidate.additionalTextEdits, TextEdit.is));
}
}
/**
* Enum of known range kinds
*/
export enum FoldingRangeKind {
/**
* Folding range for a comment
*/
Comment = 'comment',
/**
* Folding range for a imports or includes
*/
Imports = 'imports',
/**
* Folding range for a region (e.g. `#region`)
*/
Region = 'region'
}
/**
* Represents a folding range. To be valid, start and end line must be bigger than zero and smaller
* than the number of lines in the document. Clients are free to ignore invalid ranges.
*/
export interface FoldingRange {
/**
* The zero-based start line of the range to fold. The folded area starts after the line's last character.
* To be valid, the end must be zero or larger and smaller than the number of lines in the document.
*/
startLine: uinteger;
/**
* The zero-based character offset from where the folded range starts. If not defined, defaults to the length of the start line.
*/
startCharacter?: uinteger;
/**
* The zero-based end line of the range to fold. The folded area ends with the line's last character.
* To be valid, the end must be zero or larger and smaller than the number of lines in the document.
*/
endLine: uinteger;
/**
* The zero-based character offset before the folded range ends. If not defined, defaults to the length of the end line.
*/
endCharacter?: uinteger;
/**
* Describes the kind of the folding range such as `comment' or 'region'. The kind
* is used to categorize folding ranges and used by commands like 'Fold all comments'. See
* [FoldingRangeKind](#FoldingRangeKind) for an enumeration of standardized kinds.
*/
kind?: string;
}
/**
* The folding range namespace provides helper functions to work with
* [FoldingRange](#FoldingRange) literals.
*/
export namespace FoldingRange {
/**
* Creates a new FoldingRange literal.
*/
export function create(startLine: uinteger, endLine: uinteger, startCharacter?: uinteger, endCharacter?: uinteger, kind?: string): FoldingRange {
const result: FoldingRange = {
startLine,
endLine
};
if (Is.defined(startCharacter)) {
result.startCharacter = startCharacter;
}
if (Is.defined(endCharacter)) {
result.endCharacter = endCharacter;
}
if (Is.defined(kind)) {
result.kind = kind;
}
return result;
}
/**
* Checks whether the given literal conforms to the [FoldingRange](#FoldingRange) interface.
*/
export function is(value: any): value is FoldingRange {
const candidate = value as FoldingRange;
return Is.objectLiteral(candidate) && Is.uinteger(candidate.startLine) && Is.uinteger(candidate.startLine)
&& (Is.undefined(candidate.startCharacter) || Is.uinteger(candidate.startCharacter))
&& (Is.undefined(candidate.endCharacter) || Is.uinteger(candidate.endCharacter))
&& (Is.undefined(candidate.kind) || Is.string(candidate.kind));
}
}
/**
* Represents a related message and source code location for a diagnostic. This should be
* used to point to code locations that cause or related to a diagnostics, e.g when duplicating
* a symbol in a scope.
*/
export interface DiagnosticRelatedInformation {
/**
* The location of this related diagnostic information.
*/
location: Location;
/**
* The message of this related diagnostic information.
*/
message: string;
}
/**
* The DiagnosticRelatedInformation namespace provides helper functions to work with
* [DiagnosticRelatedInformation](#DiagnosticRelatedInformation) literals.
*/
export namespace DiagnosticRelatedInformation {
/**
* Creates a new DiagnosticRelatedInformation literal.
*/
export function create(location: Location, message: string): DiagnosticRelatedInformation {
return {
location,
message
};
}
/**
* Checks whether the given literal conforms to the [DiagnosticRelatedInformation](#DiagnosticRelatedInformation) interface.
*/
export function is(value: any): value is DiagnosticRelatedInformation {
let candidate: DiagnosticRelatedInformation = value as DiagnosticRelatedInformation;
return Is.defined(candidate) && Location.is(candidate.location) && Is.string(candidate.message);
}
}
/**
* The diagnostic's severity.
*/
export namespace DiagnosticSeverity {
/**
* Reports an error.
*/
export const Error: 1 = 1;
/**
* Reports a warning.
*/
export const Warning: 2 = 2;
/**
* Reports an information.
*/
export const Information: 3 = 3;
/**
* Reports a hint.
*/
export const Hint: 4 = 4;
}
export type DiagnosticSeverity = 1 | 2 | 3 | 4;
/**
* The diagnostic tags.
*
* @since 3.15.0
*/
export namespace DiagnosticTag {
/**
* Unused or unnecessary code.
*
* Clients are allowed to render diagnostics with this tag faded out instead of having
* an error squiggle.
*/
export const Unnecessary: 1 = 1;
/**
* Deprecated or obsolete code.
*
* Clients are allowed to rendered diagnostics with this tag strike through.
*/
export const Deprecated: 2 = 2;
}
export type DiagnosticTag = 1 | 2;
/**
* Structure to capture a description for an error code.
*
* @since 3.16.0
*/
export interface CodeDescription {
/**
* An URI to open with more information about the diagnostic error.
*/
href: URI;
}
/**
* The CodeDescription namespace provides functions to deal with descriptions for diagnostic codes.
*
* @since 3.16.0
*/
export namespace CodeDescription {
export function is(value: any): value is CodeDescription {
const candidate: CodeDescription = value as CodeDescription;
return Is.objectLiteral(candidate) && Is.string(candidate.href);
}
}
/**
* Represents a diagnostic, such as a compiler error or warning. Diagnostic objects
* are only valid in the scope of a resource.
*/
export interface Diagnostic {
/**
* The range at which the message applies
*/
range: Range;
/**
* The diagnostic's severity. Can be omitted. If omitted it is up to the
* client to interpret diagnostics as error, warning, info or hint.
*/
severity?: DiagnosticSeverity;
/**
* The diagnostic's code, which usually appear in the user interface.
*/
code?: integer | string;
/**
* An optional property to describe the error code.
* Requires the code field (above) to be present/not null.
*
* @since 3.16.0
*/
codeDescription?: CodeDescription;
/**
* A human-readable string describing the source of this
* diagnostic, e.g. 'typescript' or 'super lint'. It usually
* appears in the user interface.
*/
source?: string;
/**
* The diagnostic's message. It usually appears in the user interface
*/
message: string;
/**
* Additional metadata about the diagnostic.
*
* @since 3.15.0
*/
tags?: DiagnosticTag[];
/**
* An array of related diagnostic information, e.g. when symbol-names within
* a scope collide all definitions can be marked via this property.
*/
relatedInformation?: DiagnosticRelatedInformation[];
/**
* A data entry field that is preserved between a `textDocument/publishDiagnostics`
* notification and `textDocument/codeAction` request.
*
* @since 3.16.0
*/
data?: LSPAny;
}
/**
* The Diagnostic namespace provides helper functions to work with
* [Diagnostic](#Diagnostic) literals.
*/
export namespace Diagnostic {
/**
* Creates a new Diagnostic literal.
*/
export function create(range: Range, message: string, severity?: DiagnosticSeverity, code?: integer | string, source?: string, relatedInformation?: DiagnosticRelatedInformation[]): Diagnostic {
let result: Diagnostic = { range, message };
if (Is.defined(severity)) {
result.severity = severity;
}
if (Is.defined(code)) {
result.code = code;
}
if (Is.defined(source)) {
result.source = source;
}
if (Is.defined(relatedInformation)) {
result.relatedInformation = relatedInformation;
}
return result;
}
/**
* Checks whether the given literal conforms to the [Diagnostic](#Diagnostic) interface.
*/
export function is(value: any): value is Diagnostic {
let candidate = value as Diagnostic;
return Is.defined(candidate)
&& Range.is(candidate.range)
&& Is.string(candidate.message)
&& (Is.number(candidate.severity) || Is.undefined(candidate.severity))
&& (Is.integer(candidate.code) || Is.string(candidate.code) || Is.undefined(candidate.code))
&& (Is.undefined(candidate.codeDescription) || (Is.string(candidate.codeDescription?.href)))
&& (Is.string(candidate.source) || Is.undefined(candidate.source))
&& (Is.undefined(candidate.relatedInformation) || Is.typedArray<DiagnosticRelatedInformation>(candidate.relatedInformation, DiagnosticRelatedInformation.is));
}
}
/**
* Represents a reference to a command. Provides a title which
* will be used to represent a command in the UI and, optionally,
* an array of arguments which will be passed to the command handler
* function when invoked.
*/
export interface Command {
/**
* Title of the command, like `save`.
*/
title: string;
/**
* The identifier of the actual command handler.
*/
command: string;
/**
* Arguments that the command handler should be
* invoked with.
*/
arguments?: LSPAny[];
}
/**
* The Command namespace provides helper functions to work with
* [Command](#Command) literals.
*/
export namespace Command {
/**
* Creates a new Command literal.
*/
export function create(title: string, command: string, ...args: any[]): Command {
let result: Command = { title, command };
if (Is.defined(args) && args.length > 0) {
result.arguments = args;
}
return result;
}
/**
* Checks whether the given literal conforms to the [Command](#Command) interface.
*/
export function is(value: any): value is Command {
let candidate = value as Command;
return Is.defined(candidate) && Is.string(candidate.title) && Is.string(candidate.command);
}
}
/**
* A text edit applicable to a text document.
*/
export interface TextEdit {
/**
* The range of the text document to be manipulated. To insert
* text into a document create a range where start === end.
*/
range: Range;
/**
* The string to be inserted. For delete operations use an
* empty string.
*/
newText: string;
}
/**
* The TextEdit namespace provides helper function to create replace,
* insert and delete edits more easily.
*/
export namespace TextEdit {
/**
* Creates a replace text edit.
* @param range The range of text to be replaced.
* @param newText The new text.
*/
export function replace(range: Range, newText: string): TextEdit {
return { range, newText };
}
/**
* Creates a insert text edit.
* @param position The position to insert the text at.
* @param newText The text to be inserted.
*/
export function insert(position: Position, newText: string): TextEdit {
return { range: { start: position, end: position }, newText };
}
/**
* Creates a delete text edit.
* @param range The range of text to be deleted.
*/
export function del(range: Range): TextEdit {
return { range, newText: '' };
}
export function is(value: any): value is TextEdit {
const candidate = value as TextEdit;
return Is.objectLiteral(candidate)
&& Is.string(candidate.newText)
&& Range.is(candidate.range);
}
}
/**
* Additional information that describes document changes.
*
* @since 3.16.0
*/
export interface ChangeAnnotation {
/**
* A human-readable string describing the actual change. The string
* is rendered prominent in the user interface.
*/
label: string;
/**
* A flag which indicates that user confirmation is needed
* before applying the change.
*/
needsConfirmation?: boolean;
/**
* A human-readable string which is rendered less prominent in
* the user interface.
*/
description?: string;
}
export namespace ChangeAnnotation {
export function create(label: string, needsConfirmation?: boolean, description?: string): ChangeAnnotation {
const result: ChangeAnnotation = { label };
if (needsConfirmation !== undefined) {
result.needsConfirmation = needsConfirmation;
}
if (description !== undefined) {
result.description = description;
}
return result;
}
export function is(value: any): value is ChangeAnnotation {
const candidate = value as ChangeAnnotation;
return Is.objectLiteral(candidate) && Is.string(candidate.label) &&
(Is.boolean(candidate.needsConfirmation) || candidate.needsConfirmation === undefined) &&
(Is.string(candidate.description) || candidate.description === undefined);
}
}
export namespace ChangeAnnotationIdentifier {
export function is(value: any): value is ChangeAnnotationIdentifier {
const candidate = value as ChangeAnnotationIdentifier;
return Is.string(candidate);
}
}
/**
* An identifier to refer to a change annotation stored with a workspace edit.
*/
export type ChangeAnnotationIdentifier = string;
/**
* A special text edit with an additional change annotation.
*
* @since 3.16.0.
*/
export interface AnnotatedTextEdit extends TextEdit {
/**
* The actual identifier of the change annotation
*/
annotationId: ChangeAnnotationIdentifier;
}
export namespace AnnotatedTextEdit {
/**
* Creates an annotated replace text edit.
*
* @param range The range of text to be replaced.
* @param newText The new text.
* @param annotation The annotation.
*/
export function replace(range: Range, newText: string, annotation: ChangeAnnotationIdentifier): AnnotatedTextEdit {
return { range, newText, annotationId: annotation };
}
/**
* Creates an annotated insert text edit.
*
* @param position The position to insert the text at.
* @param newText The text to be inserted.
* @param annotation The annotation.
*/
export function insert(position: Position, newText: string, annotation: ChangeAnnotationIdentifier): AnnotatedTextEdit {
return { range: { start: position, end: position }, newText, annotationId: annotation };
}
/**
* Creates an annotated delete text edit.
*
* @param range The range of text to be deleted.
* @param annotation The annotation.
*/
export function del(range: Range, annotation: ChangeAnnotationIdentifier): AnnotatedTextEdit {
return { range, newText: '', annotationId: annotation };
}
export function is(value: any): value is AnnotatedTextEdit {
const candidate: AnnotatedTextEdit = value as AnnotatedTextEdit;
return TextEdit.is(candidate) && (ChangeAnnotation.is(candidate.annotationId) || ChangeAnnotationIdentifier.is(candidate.annotationId));
}
}
/**
* Describes textual changes on a text document. A TextDocumentEdit describes all changes
* on a document version Si and after they are applied move the document to version Si+1.
* So the creator of a TextDocumentEdit doesn't need to sort the array of edits or do any
* kind of ordering. However the edits must be non overlapping.
*/
export interface TextDocumentEdit {
/**
* The text document to change.
*/
textDocument: OptionalVersionedTextDocumentIdentifier;
/**
* The edits to be applied.
*
* @since 3.16.0 - support for AnnotatedTextEdit. This is guarded using a
* client capability.
*/
edits: (TextEdit | AnnotatedTextEdit)[];
}
/**
* The TextDocumentEdit namespace provides helper function to create
* an edit that manipulates a text document.
*/
export namespace TextDocumentEdit {
/**
* Creates a new `TextDocumentEdit`
*/
export function create(textDocument: OptionalVersionedTextDocumentIdentifier, edits: (TextEdit | AnnotatedTextEdit)[]): TextDocumentEdit {
return { textDocument, edits };
}
export function is(value: any): value is TextDocumentEdit {
let candidate = value as TextDocumentEdit;
return Is.defined(candidate)
&& OptionalVersionedTextDocumentIdentifier.is(candidate.textDocument)
&& Array.isArray(candidate.edits);
}
}
/**
* A generic resource operation.
*/
interface ResourceOperation {
/**
* The resource operation kind.
*/