-
Notifications
You must be signed in to change notification settings - Fork 12.6k
/
fourslashInterfaceImpl.ts
2049 lines (1763 loc) · 71.8 KB
/
fourslashInterfaceImpl.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
import * as FourSlash from "./_namespaces/FourSlash.js";
import * as ts from "./_namespaces/ts.js";
export class Test {
constructor(private state: FourSlash.TestState) {
}
public markers(): FourSlash.Marker[] {
return this.state.getMarkers();
}
public markerNames(): string[] {
return this.state.getMarkerNames();
}
public marker(name: string): FourSlash.Marker {
return this.state.getMarkerByName(name);
}
public markerName(m: FourSlash.Marker): string {
return this.state.markerName(m);
}
public ranges(): FourSlash.Range[] {
return this.state.getRanges();
}
public rangesInFile(fileName?: string): FourSlash.Range[] {
return this.state.getRangesInFile(fileName);
}
public spans(): ts.TextSpan[] {
return this.ranges().map(r => ts.createTextSpan(r.pos, r.end - r.pos));
}
public rangesByText(): Map<string, FourSlash.Range[]> {
return this.state.rangesByText();
}
public markerByName(s: string): FourSlash.Marker {
return this.state.getMarkerByName(s);
}
public symbolsInScope(range: FourSlash.Range): ts.Symbol[] {
return this.state.symbolsInScope(range);
}
public setTypesRegistry(map: ts.MapLike<void>): void {
this.state.setTypesRegistry(map);
}
public getSemanticDiagnostics(): Diagnostic[] {
return this.state.getSemanticDiagnostics().map<Diagnostic>(tsDiag => ({
message: ts.flattenDiagnosticMessageText(tsDiag.messageText, "\n"),
range: tsDiag.start ? {
fileName: this.state.activeFile.fileName,
pos: tsDiag.start,
end: tsDiag.start + tsDiag.length!,
} : undefined,
code: tsDiag.code,
reportsUnnecessary: tsDiag.reportsUnnecessary ? true : undefined,
reportsDeprecated: !!tsDiag.reportsDeprecated ? true : undefined,
}));
}
}
export class Config {
constructor(private state: FourSlash.TestState) {
}
public configurePlugin(pluginName: string, configuration: any): void {
this.state.configurePlugin(pluginName, configuration);
}
public setCompilerOptionsForInferredProjects(options: ts.server.protocol.CompilerOptions): void {
this.state.setCompilerOptionsForInferredProjects(options);
}
}
export class GoTo {
constructor(private state: FourSlash.TestState) {
}
// Moves the caret to the specified marker,
// or the anonymous marker ('/**/') if no name
// is given
public marker(name?: string | FourSlash.Marker): void {
this.state.goToMarker(name);
}
public eachMarker(markers: readonly string[], action: (marker: FourSlash.Marker, index: number) => void): void;
public eachMarker(action: (marker: FourSlash.Marker, index: number) => void): void;
public eachMarker(a: readonly string[] | ((marker: FourSlash.Marker, index: number) => void), b?: (marker: FourSlash.Marker, index: number) => void): void {
const markers = typeof a === "function" ? this.state.getMarkers() : a.map(m => this.state.getMarkerByName(m));
this.state.goToEachMarker(markers, typeof a === "function" ? a : b!);
}
public rangeStart(range: FourSlash.Range): void {
this.state.goToRangeStart(range);
}
public eachRange(action: (range: FourSlash.Range) => void): void {
this.state.goToEachRange(action);
}
public bof(): void {
this.state.goToBOF();
}
public eof(): void {
this.state.goToEOF();
}
public position(positionOrLineAndCharacter: number | ts.LineAndCharacter, fileNameOrIndex?: string | number): void {
if (fileNameOrIndex !== undefined) {
this.file(fileNameOrIndex);
}
this.state.goToPosition(positionOrLineAndCharacter);
}
// Opens a file, given either its index as it
// appears in the test source, or its filename
// as specified in the test metadata
public file(indexOrName: number | string, content?: string, scriptKindName?: string): void {
this.state.openFile(indexOrName, content, scriptKindName);
}
public select(startMarker: string, endMarker: string): void {
this.state.select(startMarker, endMarker);
}
public selectAllInFile(fileName: string): void {
this.state.selectAllInFile(fileName);
}
public selectRange(range: FourSlash.Range): void {
this.state.selectRange(range);
}
}
export class VerifyNegatable {
public not: VerifyNegatable | undefined;
constructor(protected state: FourSlash.TestState, private negative = false) {
if (!negative) {
this.not = new VerifyNegatable(state, /*negative*/ true);
}
}
public assertHasRanges(ranges: FourSlash.Range[]): void {
assert(ranges.length !== 0, "Array of ranges is expected to be non-empty");
}
public noSignatureHelp(...markers: (string | FourSlash.Marker)[]): void {
this.state.verifySignatureHelpPresence(/*expectPresent*/ false, /*triggerReason*/ undefined, markers);
}
public noSignatureHelpForTriggerReason(reason: ts.SignatureHelpTriggerReason, ...markers: (string | FourSlash.Marker)[]): void {
this.state.verifySignatureHelpPresence(/*expectPresent*/ false, reason, markers);
}
public signatureHelpPresentForTriggerReason(reason: ts.SignatureHelpTriggerReason, ...markers: (string | FourSlash.Marker)[]): void {
this.state.verifySignatureHelpPresence(/*expectPresent*/ true, reason, markers);
}
public signatureHelp(...options: VerifySignatureHelpOptions[]): void {
this.state.verifySignatureHelp(options);
}
public errorExistsBetweenMarkers(startMarker: string, endMarker: string): void {
this.state.verifyErrorExistsBetweenMarkers(startMarker, endMarker, !this.negative);
}
public errorExistsAfterMarker(markerName = ""): void {
this.state.verifyErrorExistsAfterMarker(markerName, !this.negative, /*after*/ true);
}
public errorExistsBeforeMarker(markerName = ""): void {
this.state.verifyErrorExistsAfterMarker(markerName, !this.negative, /*after*/ false);
}
public quickInfoExists(): void {
this.state.verifyQuickInfoExists(this.negative);
}
public isValidBraceCompletionAtPosition(openingBrace: string): void {
this.state.verifyBraceCompletionAtPosition(this.negative, openingBrace);
}
public jsxClosingTag(map: { [markerName: string]: ts.JsxClosingTagInfo | undefined; }): void {
this.state.verifyJsxClosingTag(map);
}
public linkedEditing(map: { [markerName: string]: ts.LinkedEditingInfo | undefined; }): void {
this.state.verifyLinkedEditingRange(map);
}
public baselineLinkedEditing(): void {
this.state.baselineLinkedEditing();
}
public isInCommentAtPosition(onlyMultiLineDiverges?: boolean): void {
this.state.verifySpanOfEnclosingComment(this.negative, onlyMultiLineDiverges);
}
public codeFix(options: VerifyCodeFixOptions): void {
this.state.verifyCodeFix(options);
}
public codeFixAvailable(options?: VerifyCodeFixAvailableOptions[]): void {
this.state.verifyCodeFixAvailable(this.negative, options);
}
public codeFixAllAvailable(fixName: string): void {
this.state.verifyCodeFixAllAvailable(this.negative, fixName);
}
public applicableRefactorAvailableAtMarker(markerName: string): void {
this.state.verifyApplicableRefactorAvailableAtMarker(this.negative, markerName);
}
public applicableRefactorAvailableForRange(): void {
this.state.verifyApplicableRefactorAvailableForRange(this.negative);
}
public refactorsAvailable(names: readonly string[]): void {
this.state.verifyRefactorsAvailable(names);
}
public refactorAvailable(name: string, actionName?: string, actionDescription?: string, kind?: string, preferences: {} = ts.emptyOptions, includeInteractiveActions?: boolean): void {
this.state.verifyRefactorAvailable(this.negative, "implicit", name, actionName, actionDescription, kind, preferences, includeInteractiveActions);
}
public refactorAvailableForTriggerReason(triggerReason: ts.RefactorTriggerReason, name: string, actionName?: string, actionDescription?: string, kind?: string, preferences: {} = ts.emptyOptions, includeInteractiveActions?: boolean): void {
this.state.verifyRefactorAvailable(this.negative, triggerReason, name, actionName, actionDescription, kind, preferences, includeInteractiveActions);
}
public refactorKindAvailable(kind: string, expected: string[], preferences: {} = ts.emptyOptions): void {
this.state.verifyRefactorKindsAvailable(kind, expected, preferences);
}
public toggleLineComment(newFileContent: string): void {
this.state.toggleLineComment(newFileContent);
}
public toggleMultilineComment(newFileContent: string): void {
this.state.toggleMultilineComment(newFileContent);
}
public commentSelection(newFileContent: string): void {
this.state.commentSelection(newFileContent);
}
public uncommentSelection(newFileContent: string): void {
this.state.uncommentSelection(newFileContent);
}
public baselineMapCode(ranges: FourSlash.Range[][], changes: string[] = []): void {
this.state.baselineMapCode(ranges, changes);
}
}
export interface CompletionsResult {
andApplyCodeAction: (options: {
name: string;
source: string;
description: string;
newFileContent?: string;
newRangeContent?: string;
}) => void;
}
export class Verify extends VerifyNegatable {
constructor(state: FourSlash.TestState) {
super(state);
}
public completions(...optionsArray: VerifyCompletionsOptions[]): CompletionsResult | undefined {
if (optionsArray.length === 1) {
return this.state.verifyCompletions(optionsArray[0]);
}
for (const options of optionsArray) {
this.state.verifyCompletions(options);
}
return {
andApplyCodeAction: () => {
throw new Error("Cannot call andApplyCodeAction on multiple completions requests");
},
};
}
public baselineInlayHints(span: ts.TextSpan, preference?: ts.UserPreferences): void {
this.state.baselineInlayHints(span, preference);
}
public quickInfoIs(expectedText: string, expectedDocumentation?: string, expectedTags?: { name: string; text: string; }[]): void {
this.state.verifyQuickInfoString(expectedText, expectedDocumentation, expectedTags);
}
public quickInfoAt(markerName: string | FourSlash.Range, expectedText: string, expectedDocumentation?: string, expectedTags?: { name: string; text: string; }[]): void {
this.state.verifyQuickInfoAt(markerName, expectedText, expectedDocumentation, expectedTags);
}
public quickInfos(namesAndTexts: { [name: string]: string; }): void {
this.state.verifyQuickInfos(namesAndTexts);
}
public caretAtMarker(markerName?: string): void {
this.state.verifyCaretAtMarker(markerName);
}
public indentationIs(numberOfSpaces: number): void {
this.state.verifyIndentationAtCurrentPosition(numberOfSpaces);
}
public indentationAtPositionIs(fileName: string, position: number, numberOfSpaces: number, indentStyle: ts.IndentStyle = ts.IndentStyle.Smart, baseIndentSize = 0): void {
this.state.verifyIndentationAtPosition(fileName, position, numberOfSpaces, indentStyle, baseIndentSize);
}
public textAtCaretIs(text: string): void {
this.state.verifyTextAtCaretIs(text);
}
/**
* Compiles the current file and evaluates 'expr' in a context containing
* the emitted output, then compares (using ===) the result of that expression
* to 'value'. Do not use this function with external modules as it is not supported.
*/
public eval(expr: string, value: any): void {
this.state.verifyEval(expr, value);
}
public currentLineContentIs(text: string): void {
this.state.verifyCurrentLineContent(text);
}
public currentFileContentIs(text: string): void {
this.state.verifyCurrentFileContent(text);
}
public formatDocumentChangesNothing(): void {
this.state.verifyFormatDocumentChangesNothing();
}
public verifyGetEmitOutputForCurrentFile(expected: string): void {
this.state.verifyGetEmitOutputForCurrentFile(expected);
}
public verifyGetEmitOutputContentsForCurrentFile(expected: ts.OutputFile[]): void {
this.state.verifyGetEmitOutputContentsForCurrentFile(expected);
}
public symbolAtLocation(startRange: FourSlash.Range, ...declarationRanges: FourSlash.Range[]): void {
this.state.verifySymbolAtLocation(startRange, declarationRanges);
}
public typeOfSymbolAtLocation(range: FourSlash.Range, symbol: ts.Symbol, expected: string): void {
this.state.verifyTypeOfSymbolAtLocation(range, symbol, expected);
}
public typeAtLocation(range: FourSlash.Range, expected: string): void {
this.state.verifyTypeAtLocation(range, expected);
}
public baselineFindAllReferences(...markerOrRange: FourSlash.MarkerOrNameOrRange[]): void {
this.state.baselineFindAllReferences(markerOrRange, /*rangeText*/ undefined);
}
public baselineFindAllReferencesAtRangesWithText(...rangeText: string[]): void {
this.state.baselineFindAllReferences(/*markerOrRange*/ undefined, rangeText);
}
public baselineGetFileReferences(...fileName: string[]): void {
this.state.baselineGetFileReferences(fileName);
}
public baselineGoToDefinition(...markerOrRange: FourSlash.MarkerOrNameOrRange[]): void {
this.state.baselineGoToDefinition(markerOrRange, /*rangeText*/ undefined);
}
public baselineGoToDefinitionAtRangesWithText(...rangeText: string[]): void {
this.state.baselineGoToDefinition(/*markerOrRange*/ undefined, rangeText);
}
public baselineGetDefinitionAtPosition(...markerOrRange: FourSlash.MarkerOrNameOrRange[]): void {
this.state.baselineGetDefinitionAtPosition(markerOrRange, /*rangeText*/ undefined);
}
public baselineGetDefinitionAtRangesWithText(...rangeText: string[]): void {
this.state.baselineGetDefinitionAtPosition(/*markerOrRange*/ undefined, rangeText);
}
public baselineGoToSourceDefinition(...markerOrRange: FourSlash.MarkerOrNameOrRange[]): void {
this.state.baselineGoToSourceDefinition(markerOrRange, /*rangeText*/ undefined);
}
public baselineGoToSourceDefinitionAtRangesWithText(...rangeText: string[]): void {
this.state.baselineGoToSourceDefinition(/*markerOrRange*/ undefined, rangeText);
}
public baselineGoToType(...markerOrRange: FourSlash.MarkerOrNameOrRange[]): void {
this.state.baselineGoToType(markerOrRange, /*rangeText*/ undefined);
}
public baselineGoToTypeAtRangesWithText(...rangeText: string[]): void {
this.state.baselineGoToType(/*markerOrRange*/ undefined, rangeText);
}
public baselineGoToImplementation(...markerOrRange: FourSlash.MarkerOrNameOrRange[]): void {
this.state.baselineGoToImplementation(markerOrRange, /*rangeText*/ undefined);
}
public baselineGoToImplementationAtRangesWithText(...rangeText: string[]): void {
this.state.baselineGoToImplementation(/*markerOrRange*/ undefined, rangeText);
}
public baselineDocumentHighlights(markerOrRange?: ArrayOrSingle<FourSlash.MarkerOrNameOrRange>, options?: VerifyDocumentHighlightsOptions): void {
this.state.baselineDocumentHighlights(markerOrRange, /*rangeText*/ undefined, options);
}
public baselineDocumentHighlightsAtRangesWithText(rangeText?: ArrayOrSingle<string>, options?: VerifyDocumentHighlightsOptions): void {
this.state.baselineDocumentHighlights(/*markerOrRange*/ undefined, rangeText, options);
}
public noErrors(): void {
this.state.verifyNoErrors();
}
public errorExistsAtRange(range: FourSlash.Range, code: number, message?: string): void {
this.state.verifyErrorExistsAtRange(range, code, message);
}
public numberOfErrorsInCurrentFile(expected: number): void {
this.state.verifyNumberOfErrorsInCurrentFile(expected);
}
public baselineCurrentFileBreakpointLocations(): void {
this.state.baselineCurrentFileBreakpointLocations();
}
public baselineCurrentFileNameOrDottedNameSpans(): void {
this.state.baselineCurrentFileNameOrDottedNameSpans();
}
public getEmitOutput(expectedOutputFiles: readonly string[]): void {
this.state.verifyGetEmitOutput(expectedOutputFiles);
}
public baselineGetEmitOutput(): void {
this.state.baselineGetEmitOutput();
}
public baselineQuickInfo(verbosityLevels?: FourSlash.VerbosityLevels): void {
this.state.baselineQuickInfo(verbosityLevels);
}
public baselineSignatureHelp(): void {
this.state.baselineSignatureHelp();
}
public baselineCompletions(preferences?: ts.UserPreferences): void {
this.state.baselineCompletions(preferences);
}
public baselineSmartSelection(): void {
this.state.baselineSmartSelection();
}
public baselineSyntacticDiagnostics(): void {
this.state.baselineSyntacticDiagnostics();
}
public baselineSyntacticAndSemanticDiagnostics(): void {
this.state.baselineSyntacticAndSemanticDiagnostics();
}
public nameOrDottedNameSpanTextIs(text: string): void {
this.state.verifyCurrentNameOrDottedNameSpanText(text);
}
public outliningSpansInCurrentFile(spans: FourSlash.Range[], kind?: "comment" | "region" | "code" | "imports"): void {
this.state.verifyOutliningSpans(spans, kind);
}
public outliningHintSpansInCurrentFile(spans: FourSlash.Range[]): void {
this.state.verifyOutliningHintSpans(spans);
}
public todoCommentsInCurrentFile(descriptors: string[]): void {
this.state.verifyTodoComments(descriptors, this.state.getRanges());
}
public matchingBracePositionInCurrentFile(bracePosition: number, expectedMatchPosition: number): void {
this.state.verifyMatchingBracePosition(bracePosition, expectedMatchPosition);
}
public noMatchingBracePositionInCurrentFile(bracePosition: number): void {
this.state.verifyNoMatchingBracePosition(bracePosition);
}
public docCommentTemplateAt(marker: string | FourSlash.Marker, expectedOffset: number, expectedText: string, options?: ts.DocCommentTemplateOptions): void {
this.state.goToMarker(marker);
this.state.verifyDocCommentTemplate({ newText: expectedText.replace(/\r?\n/g, ts.testFormatSettings.newLineCharacter!), caretOffset: expectedOffset }, options);
}
public noDocCommentTemplateAt(marker: string | FourSlash.Marker): void {
this.state.goToMarker(marker);
this.state.verifyDocCommentTemplate(/*expected*/ undefined);
}
public rangeAfterCodeFix(expectedText: string, includeWhiteSpace?: boolean, errorCode?: number, index?: number): void {
this.state.verifyRangeAfterCodeFix(expectedText, includeWhiteSpace, errorCode, index);
}
public codeFixAll(options: VerifyCodeFixAllOptions): void {
this.state.verifyCodeFixAll(options);
}
public fileAfterApplyingRefactorAtMarker(markerName: string, expectedContent: string, refactorNameToApply: string, actionName: string, formattingOptions?: ts.FormatCodeSettings): void {
this.state.verifyFileAfterApplyingRefactorAtMarker(markerName, expectedContent, refactorNameToApply, actionName, formattingOptions);
}
public rangeIs(expectedText: string, includeWhiteSpace?: boolean): void {
this.state.verifyRangeIs(expectedText, includeWhiteSpace);
}
public getAndApplyCodeFix(errorCode?: number, index?: number): void {
this.state.getAndApplyCodeActions(errorCode, index);
}
public applyCodeActionFromCompletion(markerName: string | undefined, options: VerifyCompletionActionOptions): void {
this.state.applyCodeActionFromCompletion(markerName, options);
}
public importFixAtPosition(expectedTextArray: string[], errorCode?: number, preferences?: ts.UserPreferences): void {
this.state.verifyImportFixAtPosition(expectedTextArray, errorCode, preferences);
}
public importFixModuleSpecifiers(marker: string, moduleSpecifiers: string[], preferences?: ts.UserPreferences): void {
this.state.verifyImportFixModuleSpecifiers(marker, moduleSpecifiers, preferences);
}
public baselineAutoImports(marker: string, fullNamesForCodeFix?: string[], options?: ts.UserPreferences): void {
this.state.baselineAutoImports(marker, fullNamesForCodeFix, options);
}
public navigationBar(json: any, options?: { checkSpans?: boolean; }): void {
this.state.verifyNavigationBar(json, options);
}
public navigationTree(json: any, options?: { checkSpans?: boolean; }): void {
this.state.verifyNavigationTree(json, options);
}
public navigateTo(...options: VerifyNavigateToOptions[]): void {
this.state.verifyNavigateTo(options);
}
/**
* This method *requires* a contiguous, complete, and ordered stream of classifications for a file.
*/
public syntacticClassificationsAre(...classifications: { classificationType: string; text: string; }[]): void {
this.state.verifySyntacticClassifications(classifications);
}
public encodedSyntacticClassificationsLength(length: number): void {
this.state.verifyEncodedSyntacticClassificationsLength(length);
}
public encodedSemanticClassificationsLength(format: ts.SemanticClassificationFormat, length: number): void {
this.state.verifyEncodedSemanticClassificationsLength(format, length);
}
/**
* This method *requires* an ordered stream of classifications for a file, and spans are highly recommended.
*/
public semanticClassificationsAre(format: ts.SemanticClassificationFormat, ...classifications: Classification[]): void {
this.state.verifySemanticClassifications(format, classifications);
}
public replaceWithSemanticClassifications(format: ts.SemanticClassificationFormat.TwentyTwenty): void {
this.state.replaceWithSemanticClassifications(format);
}
public renameInfoSucceeded(
displayName?: string,
fullDisplayName?: string,
kind?: string,
kindModifiers?: string,
fileToRename?: string,
expectedRange?: FourSlash.Range,
preferences?: ts.UserPreferences,
): void {
this.state.verifyRenameInfoSucceeded(displayName, fullDisplayName, kind, kindModifiers, fileToRename, expectedRange, preferences);
}
public renameInfoFailed(message?: string, preferences?: ts.UserPreferences): void {
this.state.verifyRenameInfoFailed(message, preferences);
}
public baselineRename(markerOrRange?: ArrayOrSingle<FourSlash.MarkerOrNameOrRange>, options?: RenameOptions): void {
this.state.baselineRename(markerOrRange, /*rangeText*/ undefined, options);
}
public baselineRenameAtRangesWithText(rangeText?: ArrayOrSingle<string>, options?: RenameOptions): void {
this.state.baselineRename(/*markerOrRange*/ undefined, rangeText, options);
}
public verifyQuickInfoDisplayParts(kind: string, kindModifiers: string, textSpan: FourSlash.TextSpan, displayParts: ts.SymbolDisplayPart[], documentation: ts.SymbolDisplayPart[], tags: ts.JSDocTagInfo[]): void {
this.state.verifyQuickInfoDisplayParts(kind, kindModifiers, textSpan, displayParts, documentation, tags);
}
public getSyntacticDiagnostics(expected: readonly Diagnostic[]): void {
this.state.getSyntacticDiagnostics(expected);
}
public getSemanticDiagnostics(expected: readonly Diagnostic[]): void {
this.state.verifySemanticDiagnostics(expected);
}
public getRegionSemanticDiagnostics(
ranges: ts.TextRange[],
expectedDiagnostics: readonly Diagnostic[],
expectedRanges: ts.TextRange[] | undefined,
): void {
this.state.getRegionSemanticDiagnostics(ranges, expectedDiagnostics, expectedRanges);
}
public getSuggestionDiagnostics(expected: readonly Diagnostic[]): void {
this.state.getSuggestionDiagnostics(expected);
}
public ProjectInfo(expected: string[]): void {
this.state.verifyProjectInfo(expected);
}
public getEditsForFileRename(options: GetEditsForFileRenameOptions): void {
this.state.getEditsForFileRename(options);
}
public baselineCallHierarchy(): void {
this.state.baselineCallHierarchy();
}
public moveToNewFile(options: MoveToNewFileOptions): void {
this.state.moveToNewFile(options);
}
public moveToFile(options: MoveToFileOptions): void {
this.state.moveToFile(options);
}
public noMoveToNewFile(): void {
this.state.noMoveToNewFile();
}
public organizeImports(newContent: string, mode?: ts.OrganizeImportsMode, preferences?: ts.UserPreferences): void {
this.state.verifyOrganizeImports(newContent, mode, preferences);
}
public preparePasteEdits(options: PreparePasteEditsOptions): void {
this.state.verifyPreparePasteEdits(options);
}
public pasteEdits(options: PasteEditsOptions): void {
this.state.verifyPasteEdits(options);
}
}
export class Edit {
constructor(private state: FourSlash.TestState) {
}
public caretPosition(): FourSlash.Marker {
return this.state.caretPosition();
}
public backspace(count?: number): void {
this.state.deleteCharBehindMarker(count);
}
public deleteAtCaret(times?: number): void {
this.state.deleteChar(times);
}
public replace(start: number, length: number, text: string): void {
this.state.replace(start, length, text);
}
public paste(text: string): void {
this.state.paste(text);
}
public insert(text: string): void {
this.insertLines(text);
}
public insertLine(text: string): void {
this.insertLines(text + "\n");
}
public insertLines(...lines: string[]): void {
this.state.type(lines.join("\n"));
}
public deleteLine(index: number): void {
this.deleteLineRange(index, index);
}
public deleteLineRange(startIndex: number, endIndexInclusive: number): void {
this.state.deleteLineRange(startIndex, endIndexInclusive);
}
public replaceLine(index: number, text: string): void {
this.state.selectLine(index);
this.state.type(text);
}
public moveRight(count?: number): void {
this.state.moveCaretRight(count);
}
public moveLeft(count?: number): void {
if (typeof count === "undefined") {
count = 1;
}
this.state.moveCaretRight(count * -1);
}
public enableFormatting(): void {
this.state.enableFormatting = true;
}
public disableFormatting(): void {
this.state.enableFormatting = false;
}
public applyRefactor(options: ApplyRefactorOptions): void {
this.state.applyRefactor(options);
}
}
export class Debug {
constructor(private state: FourSlash.TestState) {
}
public printCurrentParameterHelp(): void {
this.state.printCurrentParameterHelp();
}
public printCurrentFileState(): void {
this.state.printCurrentFileState(/*showWhitespace*/ false, /*makeCaretVisible*/ true);
}
public printCurrentFileStateWithWhitespace(): void {
this.state.printCurrentFileState(/*showWhitespace*/ true, /*makeCaretVisible*/ true);
}
public printCurrentFileStateWithoutCaret(): void {
this.state.printCurrentFileState(/*showWhitespace*/ false, /*makeCaretVisible*/ false);
}
public printCurrentQuickInfo(): void {
this.state.printCurrentQuickInfo();
}
public printCurrentSignatureHelp(): void {
this.state.printCurrentSignatureHelp();
}
public printCompletionListMembers(options: ts.UserPreferences | undefined): void {
this.state.printCompletionListMembers(options);
}
public printAvailableCodeFixes(): void {
this.state.printAvailableCodeFixes();
}
public printBreakpointLocation(pos: number): void {
this.state.printBreakpointLocation(pos);
}
public printBreakpointAtCurrentLocation(): void {
this.state.printBreakpointAtCurrentLocation();
}
public printNameOrDottedNameSpans(pos: number): void {
this.state.printNameOrDottedNameSpans(pos);
}
public printErrorList(): void {
this.state.printErrorList();
}
public printNavigationItems(searchValue = ".*"): void {
this.state.printNavigationItems(searchValue);
}
public printNavigationBar(): void {
this.state.printNavigationBar();
}
public printContext(): void {
this.state.printContext();
}
public printOutliningSpans(): void {
this.state.printOutliningSpans();
}
}
export class Format {
constructor(private state: FourSlash.TestState) {
}
public document(): void {
this.state.formatDocument();
}
public copyFormatOptions(): ts.FormatCodeSettings {
return this.state.copyFormatOptions();
}
public setFormatOptions(options: ts.FormatCodeOptions): ts.FormatCodeSettings {
return this.state.setFormatOptions(options);
}
public selection(startMarker: string, endMarker: string): void {
this.state.formatSelection(this.state.getMarkerByName(startMarker).position, this.state.getMarkerByName(endMarker).position);
}
public onType(posMarker: string, key: string): void {
this.state.formatOnType(this.state.getMarkerByName(posMarker).position, key);
}
public setOption(name: keyof ts.FormatCodeSettings, value: number | string | boolean): void {
this.state.setFormatOptions({ ...this.state.formatCodeSettings, [name]: value });
}
}
export class Cancellation {
constructor(private state: FourSlash.TestState) {
}
public resetCancelled(): void {
this.state.resetCancelled();
}
public setCancelled(numberOfCalls = 0): void {
this.state.setCancelled(numberOfCalls);
}
}
interface OlderClassification {
classificationType: ts.ClassificationTypeNames;
text: string;
textSpan?: FourSlash.TextSpan;
}
// The VS Code LSP
interface ModernClassification {
classificationType: string;
text?: string;
textSpan?: FourSlash.TextSpan;
}
type Classification = OlderClassification | ModernClassification;
export function classification(format: ts.SemanticClassificationFormat): {
semanticToken: (identifier: string, text: string, _position: number) => Classification;
comment?: undefined;
identifier?: undefined;
keyword?: undefined;
numericLiteral?: undefined;
operator?: undefined;
stringLiteral?: undefined;
whiteSpace?: undefined;
text?: undefined;
punctuation?: undefined;
docCommentTagName?: undefined;
className?: undefined;
enumName?: undefined;
interfaceName?: undefined;
moduleName?: undefined;
typeParameterName?: undefined;
parameterName?: undefined;
typeAliasName?: undefined;
jsxOpenTagName?: undefined;
jsxCloseTagName?: undefined;
jsxSelfClosingTagName?: undefined;
jsxAttribute?: undefined;
jsxText?: undefined;
jsxAttributeStringLiteralValue?: undefined;
getClassification?: undefined;
} | {
comment: (text: string, position?: number) => Classification;
identifier: (text: string, position?: number) => Classification;
keyword: (text: string, position?: number) => Classification;
numericLiteral: (text: string, position?: number) => Classification;
operator: (text: string, position?: number) => Classification;
stringLiteral: (text: string, position?: number) => Classification;
whiteSpace: (text: string, position?: number) => Classification;
text: (text: string, position?: number) => Classification;
punctuation: (text: string, position?: number) => Classification;
docCommentTagName: (text: string, position?: number) => Classification;
className: (text: string, position?: number) => Classification;
enumName: (text: string, position?: number) => Classification;
interfaceName: (text: string, position?: number) => Classification;
moduleName: (text: string, position?: number) => Classification;
typeParameterName: (text: string, position?: number) => Classification;
parameterName: (text: string, position?: number) => Classification;
typeAliasName: (text: string, position?: number) => Classification;
jsxOpenTagName: (text: string, position?: number) => Classification;
jsxCloseTagName: (text: string, position?: number) => Classification;
jsxSelfClosingTagName: (text: string, position?: number) => Classification;
jsxAttribute: (text: string, position?: number) => Classification;
jsxText: (text: string, position?: number) => Classification;
jsxAttributeStringLiteralValue: (text: string, position?: number) => Classification;
getClassification: (classificationType: ts.ClassificationTypeNames, text: string, position?: number) => Classification;
semanticToken?: undefined;
} {
function semanticToken(identifier: string, text: string, _position: number): Classification {
return {
classificationType: identifier,
text,
};
}
if (format === ts.SemanticClassificationFormat.TwentyTwenty) {
return {
semanticToken,
};
}
// Defaults to the previous semantic classifier factory functions
function comment(text: string, position?: number): Classification {
return getClassification(ts.ClassificationTypeNames.comment, text, position);
}
function identifier(text: string, position?: number): Classification {
return getClassification(ts.ClassificationTypeNames.identifier, text, position);
}
function keyword(text: string, position?: number): Classification {
return getClassification(ts.ClassificationTypeNames.keyword, text, position);
}
function numericLiteral(text: string, position?: number): Classification {
return getClassification(ts.ClassificationTypeNames.numericLiteral, text, position);
}
function operator(text: string, position?: number): Classification {
return getClassification(ts.ClassificationTypeNames.operator, text, position);
}
function stringLiteral(text: string, position?: number): Classification {
return getClassification(ts.ClassificationTypeNames.stringLiteral, text, position);
}
function whiteSpace(text: string, position?: number): Classification {
return getClassification(ts.ClassificationTypeNames.whiteSpace, text, position);
}
function text(text: string, position?: number): Classification {
return getClassification(ts.ClassificationTypeNames.text, text, position);
}
function punctuation(text: string, position?: number): Classification {
return getClassification(ts.ClassificationTypeNames.punctuation, text, position);
}
function docCommentTagName(text: string, position?: number): Classification {
return getClassification(ts.ClassificationTypeNames.docCommentTagName, text, position);
}
function className(text: string, position?: number): Classification {
return getClassification(ts.ClassificationTypeNames.className, text, position);
}
function enumName(text: string, position?: number): Classification {
return getClassification(ts.ClassificationTypeNames.enumName, text, position);
}
function interfaceName(text: string, position?: number): Classification {
return getClassification(ts.ClassificationTypeNames.interfaceName, text, position);
}
function moduleName(text: string, position?: number): Classification {
return getClassification(ts.ClassificationTypeNames.moduleName, text, position);
}
function typeParameterName(text: string, position?: number): Classification {
return getClassification(ts.ClassificationTypeNames.typeParameterName, text, position);
}
function parameterName(text: string, position?: number): Classification {
return getClassification(ts.ClassificationTypeNames.parameterName, text, position);
}
function typeAliasName(text: string, position?: number): Classification {
return getClassification(ts.ClassificationTypeNames.typeAliasName, text, position);
}
function jsxOpenTagName(text: string, position?: number): Classification {