-
Notifications
You must be signed in to change notification settings - Fork 12.5k
/
types.ts
1961 lines (1708 loc) · 74 KB
/
types.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 {
CancellationToken,
CompilerHost,
CompilerOptions,
CustomTransformers,
Diagnostic,
DiagnosticWithLocation,
DocumentHighlights,
DocumentPositionMapper,
EmitOutput,
ExportInfoMap,
ExportMapInfoKey,
FileReference,
GetEffectiveTypeRootsHost,
HasChangedAutomaticTypeDirectiveNames,
HasInvalidatedResolutions,
JSDocParsingMode,
LineAndCharacter,
MinimalResolutionCacheHost,
ModuleResolutionCache,
ModuleSpecifierCache,
ParsedCommandLine,
Path,
Program,
ProjectReference,
ResolutionMode,
ResolvedModule,
ResolvedModuleWithFailedLookupLocations,
ResolvedProjectReference,
ResolvedTypeReferenceDirective,
ResolvedTypeReferenceDirectiveWithFailedLookupLocations,
ScriptKind,
SourceFile,
SourceFileLike,
SourceMapper,
StringLiteralLike,
Symbol,
SymlinkCache,
TextChangeRange,
textChanges,
TextRange,
TextSpan,
UserPreferences,
} from "./_namespaces/ts.js";
declare module "../compiler/types.js" {
// Module transform: converted from interface augmentation
export interface Node {
getSourceFile(): SourceFile;
getChildCount(sourceFile?: SourceFile): number;
getChildAt(index: number, sourceFile?: SourceFile): Node;
getChildren(sourceFile?: SourceFile): readonly Node[];
/** @internal */
getChildren(sourceFile?: SourceFileLike): readonly Node[]; // eslint-disable-line @typescript-eslint/unified-signatures
getStart(sourceFile?: SourceFile, includeJsDocComment?: boolean): number;
/** @internal */
getStart(sourceFile?: SourceFileLike, includeJsDocComment?: boolean): number; // eslint-disable-line @typescript-eslint/unified-signatures
getFullStart(): number;
getEnd(): number;
getWidth(sourceFile?: SourceFileLike): number;
getFullWidth(): number;
getLeadingTriviaWidth(sourceFile?: SourceFile): number;
getFullText(sourceFile?: SourceFile): string;
getText(sourceFile?: SourceFile): string;
getFirstToken(sourceFile?: SourceFile): Node | undefined;
/** @internal */
getFirstToken(sourceFile?: SourceFileLike): Node | undefined; // eslint-disable-line @typescript-eslint/unified-signatures
getLastToken(sourceFile?: SourceFile): Node | undefined;
/** @internal */
getLastToken(sourceFile?: SourceFileLike): Node | undefined; // eslint-disable-line @typescript-eslint/unified-signatures
// See ts.forEachChild for documentation.
forEachChild<T>(cbNode: (node: Node) => T | undefined, cbNodeArray?: (nodes: NodeArray<Node>) => T | undefined): T | undefined;
}
}
declare module "../compiler/types.js" {
// Module transform: converted from interface augmentation
export interface Identifier {
readonly text: string;
}
}
declare module "../compiler/types.js" {
// Module transform: converted from interface augmentation
export interface PrivateIdentifier {
readonly text: string;
}
}
declare module "../compiler/types.js" {
// Module transform: converted from interface augmentation
export interface Symbol {
readonly name: string;
getFlags(): SymbolFlags;
getEscapedName(): __String;
getName(): string;
getDeclarations(): Declaration[] | undefined;
getDocumentationComment(typeChecker: TypeChecker | undefined): SymbolDisplayPart[];
/** @internal */
getContextualDocumentationComment(context: Node | undefined, checker: TypeChecker | undefined): SymbolDisplayPart[];
getJsDocTags(checker?: TypeChecker): JSDocTagInfo[];
/** @internal */
getContextualJsDocTags(context: Node | undefined, checker: TypeChecker | undefined): JSDocTagInfo[];
}
}
declare module "../compiler/types.js" {
// Module transform: converted from interface augmentation
export interface Type {
getFlags(): TypeFlags;
getSymbol(): Symbol | undefined;
getProperties(): Symbol[];
getProperty(propertyName: string): Symbol | undefined;
getApparentProperties(): Symbol[];
getCallSignatures(): readonly Signature[];
getConstructSignatures(): readonly Signature[];
getStringIndexType(): Type | undefined;
getNumberIndexType(): Type | undefined;
getBaseTypes(): BaseType[] | undefined;
getNonNullableType(): Type;
/** @internal */ getNonOptionalType(): Type;
/** @internal */ isNullableType(): boolean;
getConstraint(): Type | undefined;
getDefault(): Type | undefined;
isUnion(): this is UnionType;
isIntersection(): this is IntersectionType;
isUnionOrIntersection(): this is UnionOrIntersectionType;
isLiteral(): this is LiteralType;
isStringLiteral(): this is StringLiteralType;
isNumberLiteral(): this is NumberLiteralType;
isTypeParameter(): this is TypeParameter;
isClassOrInterface(): this is InterfaceType;
isClass(): this is InterfaceType;
isIndexType(): this is IndexType;
}
}
declare module "../compiler/types.js" {
// Module transform: converted from interface augmentation
export interface TypeReference {
typeArguments?: readonly Type[];
}
}
declare module "../compiler/types.js" {
// Module transform: converted from interface augmentation
export interface Signature {
getDeclaration(): SignatureDeclaration;
getTypeParameters(): TypeParameter[] | undefined;
getParameters(): Symbol[];
getTypeParameterAtPosition(pos: number): Type;
getReturnType(): Type;
getDocumentationComment(typeChecker: TypeChecker | undefined): SymbolDisplayPart[];
getJsDocTags(): JSDocTagInfo[];
}
}
declare module "../compiler/types.js" {
// Module transform: converted from interface augmentation
export interface SourceFile {
/** @internal */ version: string;
/** @internal */ scriptSnapshot: IScriptSnapshot | undefined;
/** @internal */ nameTable: Map<__String, number> | undefined;
/** @internal */ getNamedDeclarations(): Map<string, readonly Declaration[]>;
getLineAndCharacterOfPosition(pos: number): LineAndCharacter;
getLineEndOfPosition(pos: number): number;
getLineStarts(): readonly number[];
getPositionOfLineAndCharacter(line: number, character: number): number;
update(newText: string, textChangeRange: TextChangeRange): SourceFile;
/** @internal */ sourceMapper?: DocumentPositionMapper;
}
}
declare module "../compiler/types.js" {
// Module transform: converted from interface augmentation
export interface SourceFileLike {
getLineAndCharacterOfPosition(pos: number): LineAndCharacter;
}
}
declare module "../compiler/types.js" {
// Module transform: converted from interface augmentation
export interface SourceMapSource {
getLineAndCharacterOfPosition(pos: number): LineAndCharacter;
}
}
/**
* Represents an immutable snapshot of a script at a specified time.Once acquired, the
* snapshot is observably immutable. i.e. the same calls with the same parameters will return
* the same values.
*/
// eslint-disable-next-line @typescript-eslint/naming-convention
export interface IScriptSnapshot {
/** Gets a portion of the script snapshot specified by [start, end). */
getText(start: number, end: number): string;
/** Gets the length of this script snapshot. */
getLength(): number;
/**
* Gets the TextChangeRange that describe how the text changed between this text and
* an older version. This information is used by the incremental parser to determine
* what sections of the script need to be re-parsed. 'undefined' can be returned if the
* change range cannot be determined. However, in that case, incremental parsing will
* not happen and the entire document will be re - parsed.
*/
getChangeRange(oldSnapshot: IScriptSnapshot): TextChangeRange | undefined;
/** Releases all resources held by this script snapshot */
dispose?(): void;
}
export namespace ScriptSnapshot {
class StringScriptSnapshot implements IScriptSnapshot {
constructor(private text: string) {
}
public getText(start: number, end: number): string {
return start === 0 && end === this.text.length
? this.text
: this.text.substring(start, end);
}
public getLength(): number {
return this.text.length;
}
public getChangeRange(): TextChangeRange | undefined {
// Text-based snapshots do not support incremental parsing. Return undefined
// to signal that to the caller.
return undefined;
}
}
export function fromString(text: string): IScriptSnapshot {
return new StringScriptSnapshot(text);
}
}
export interface PreProcessedFileInfo {
referencedFiles: FileReference[];
typeReferenceDirectives: FileReference[];
libReferenceDirectives: FileReference[];
importedFiles: FileReference[];
ambientExternalModules?: string[];
isLibFile: boolean;
}
export interface HostCancellationToken {
isCancellationRequested(): boolean;
}
export interface InstallPackageOptions {
fileName: Path;
packageName: string;
}
/** @internal */
export const enum PackageJsonDependencyGroup {
Dependencies = 1 << 0,
DevDependencies = 1 << 1,
PeerDependencies = 1 << 2,
OptionalDependencies = 1 << 3,
All = Dependencies | DevDependencies | PeerDependencies | OptionalDependencies,
}
/** @internal */
export interface ProjectPackageJsonInfo {
fileName: string;
parseable: boolean;
dependencies?: Map<string, string>;
devDependencies?: Map<string, string>;
peerDependencies?: Map<string, string>;
optionalDependencies?: Map<string, string>;
get(dependencyName: string, inGroups?: PackageJsonDependencyGroup): string | undefined;
has(dependencyName: string, inGroups?: PackageJsonDependencyGroup): boolean;
}
/** @internal */
export interface FormattingHost {
getNewLine?(): string;
}
/** @internal */
export const enum PackageJsonAutoImportPreference {
Off,
On,
Auto,
}
export interface PerformanceEvent {
kind: "UpdateGraph" | "CreatePackageJsonAutoImportProvider";
durationMs: number;
}
export enum LanguageServiceMode {
Semantic,
PartialSemantic,
Syntactic,
}
export interface IncompleteCompletionsCache {
get(): CompletionInfo | undefined;
set(response: CompletionInfo): void;
clear(): void;
}
//
// Public interface of the host of a language service instance.
//
export interface LanguageServiceHost extends GetEffectiveTypeRootsHost, MinimalResolutionCacheHost {
getCompilationSettings(): CompilerOptions;
getNewLine?(): string;
/** @internal */ updateFromProject?(): void;
/** @internal */ updateFromProjectInProgress?: boolean;
getProjectVersion?(): string;
getScriptFileNames(): string[];
getScriptKind?(fileName: string): ScriptKind;
getScriptVersion(fileName: string): string;
getScriptSnapshot(fileName: string): IScriptSnapshot | undefined;
getProjectReferences?(): readonly ProjectReference[] | undefined;
getLocalizedDiagnosticMessages?(): any;
getCancellationToken?(): HostCancellationToken;
getCurrentDirectory(): string;
getDefaultLibFileName(options: CompilerOptions): string;
log?(s: string): void;
trace?(s: string): void;
error?(s: string): void;
useCaseSensitiveFileNames?(): boolean;
/*
* LS host can optionally implement these methods to support completions for module specifiers.
* Without these methods, only completions for ambient modules will be provided.
*/
readDirectory?(path: string, extensions?: readonly string[], exclude?: readonly string[], include?: readonly string[], depth?: number): string[];
realpath?(path: string): string;
/** @internal */ createHash?: ((data: string) => string) | undefined;
/*
* Unlike `realpath and `readDirectory`, `readFile` and `fileExists` are now _required_
* to properly acquire and setup source files under module: node16+ modes.
*/
readFile(path: string, encoding?: string): string | undefined;
fileExists(path: string): boolean;
/*
* LS host can optionally implement these methods to support automatic updating when new type libraries are installed
*/
getTypeRootsVersion?(): number;
/*
* LS host can optionally implement this method if it wants to be completely in charge of module name resolution.
* if implementation is omitted then language service will use built-in module resolution logic and get answers to
* host specific questions using 'getScriptSnapshot'.
*
* If this is implemented, `getResolvedModuleWithFailedLookupLocationsFromCache` should be too.
*/
/** @deprecated supply resolveModuleNameLiterals instead for resolution that can handle newer resolution modes like nodenext */
resolveModuleNames?(moduleNames: string[], containingFile: string, reusedNames: string[] | undefined, redirectedReference: ResolvedProjectReference | undefined, options: CompilerOptions, containingSourceFile?: SourceFile): (ResolvedModule | undefined)[];
getResolvedModuleWithFailedLookupLocationsFromCache?(modulename: string, containingFile: string, resolutionMode?: ResolutionMode): ResolvedModuleWithFailedLookupLocations | undefined;
/** @deprecated supply resolveTypeReferenceDirectiveReferences instead for resolution that can handle newer resolution modes like nodenext */
resolveTypeReferenceDirectives?(typeDirectiveNames: string[] | FileReference[], containingFile: string, redirectedReference: ResolvedProjectReference | undefined, options: CompilerOptions, containingFileMode?: ResolutionMode): (ResolvedTypeReferenceDirective | undefined)[];
resolveModuleNameLiterals?(
moduleLiterals: readonly StringLiteralLike[],
containingFile: string,
redirectedReference: ResolvedProjectReference | undefined,
options: CompilerOptions,
containingSourceFile: SourceFile,
reusedNames: readonly StringLiteralLike[] | undefined,
): readonly ResolvedModuleWithFailedLookupLocations[];
resolveTypeReferenceDirectiveReferences?<T extends FileReference | string>(
typeDirectiveReferences: readonly T[],
containingFile: string,
redirectedReference: ResolvedProjectReference | undefined,
options: CompilerOptions,
containingSourceFile: SourceFile | undefined,
reusedNames: readonly T[] | undefined,
): readonly ResolvedTypeReferenceDirectiveWithFailedLookupLocations[];
/** @internal */
resolveLibrary?(
libraryName: string,
resolveFrom: string,
options: CompilerOptions,
libFileName: string,
): ResolvedModuleWithFailedLookupLocations;
/**
* If provided along with custom resolveLibrary, used to determine if we should redo library resolutions
* @internal
*/
hasInvalidatedLibResolutions?: ((libFileName: string) => boolean) | undefined;
/** @internal */ hasInvalidatedResolutions?: HasInvalidatedResolutions | undefined;
/** @internal */ hasChangedAutomaticTypeDirectiveNames?: HasChangedAutomaticTypeDirectiveNames;
/** @internal */ getGlobalTypingsCacheLocation?(): string | undefined;
/** @internal */ getSymlinkCache?(files?: readonly SourceFile[]): SymlinkCache;
/* Lets the Program from a AutoImportProviderProject use its host project's ModuleResolutionCache */
/** @internal */ getModuleResolutionCache?(): ModuleResolutionCache | undefined;
/*
* Required for full import and type reference completions.
* These should be unprefixed names. E.g. `getDirectories("/foo/bar")` should return `["a", "b"]`, not `["/foo/bar/a", "/foo/bar/b"]`.
*/
getDirectories?(directoryName: string): string[];
/**
* Gets a set of custom transformers to use during emit.
*/
getCustomTransformers?(): CustomTransformers | undefined;
isKnownTypesPackageName?(name: string): boolean;
installPackage?(options: InstallPackageOptions): Promise<ApplyCodeActionCommandResult>;
writeFile?(fileName: string, content: string): void;
/** @internal */ getDocumentPositionMapper?(generatedFileName: string, sourceFileName?: string): DocumentPositionMapper | undefined;
/** @internal */ getSourceFileLike?(fileName: string): SourceFileLike | undefined;
/** @internal */ getPackageJsonsVisibleToFile?(fileName: string, rootDir?: string): readonly ProjectPackageJsonInfo[];
/** @internal */ getNearestAncestorDirectoryWithPackageJson?(fileName: string): string | undefined;
/** @internal */ getPackageJsonsForAutoImport?(rootDir?: string): readonly ProjectPackageJsonInfo[];
/** @internal */ getCachedExportInfoMap?(): ExportInfoMap;
/** @internal */ getModuleSpecifierCache?(): ModuleSpecifierCache;
/** @internal */ setCompilerHost?(host: CompilerHost): void;
/** @internal */ useSourceOfProjectReferenceRedirect?(): boolean;
/** @internal */ getPackageJsonAutoImportProvider?(): Program | undefined;
/** @internal */ sendPerformanceEvent?(kind: PerformanceEvent["kind"], durationMs: number): void;
getParsedCommandLine?(fileName: string): ParsedCommandLine | undefined;
/** @internal */ onReleaseParsedCommandLine?(configFileName: string, oldResolvedRef: ResolvedProjectReference | undefined, optionOptions: CompilerOptions): void;
/** @internal */ onReleaseOldSourceFile?(oldSourceFile: SourceFile, oldOptions: CompilerOptions, hasSourceFileByPath: boolean, newSourceFileByResolvedPath: SourceFile | undefined): void;
/** @internal */ getIncompleteCompletionsCache?(): IncompleteCompletionsCache;
/** @internal */ runWithTemporaryFileUpdate?(rootFile: string, updatedText: string, cb: (updatedProgram: Program, originalProgram: Program | undefined, updatedPastedText: SourceFile) => void): void;
jsDocParsingMode?: JSDocParsingMode | undefined;
}
/** @internal */
export const emptyOptions = {};
export type WithMetadata<T> = T & { metadata?: unknown; };
export const enum SemanticClassificationFormat {
Original = "original",
TwentyTwenty = "2020",
}
/** @internal */
export interface RegionDiagnosticsResult {
diagnostics: Diagnostic[];
spans: TextSpan[];
}
//
// Public services of a language service instance associated
// with a language service host instance
//
export interface LanguageService {
/** This is used as a part of restarting the language service. */
cleanupSemanticCache(): void;
/**
* Gets errors indicating invalid syntax in a file.
*
* In English, "this cdeo have, erorrs" is syntactically invalid because it has typos,
* grammatical errors, and misplaced punctuation. Likewise, examples of syntax
* errors in TypeScript are missing parentheses in an `if` statement, mismatched
* curly braces, and using a reserved keyword as a variable name.
*
* These diagnostics are inexpensive to compute and don't require knowledge of
* other files. Note that a non-empty result increases the likelihood of false positives
* from `getSemanticDiagnostics`.
*
* While these represent the majority of syntax-related diagnostics, there are some
* that require the type system, which will be present in `getSemanticDiagnostics`.
*
* @param fileName A path to the file you want syntactic diagnostics for
*/
getSyntacticDiagnostics(fileName: string): DiagnosticWithLocation[];
/**
* Gets warnings or errors indicating type system issues in a given file.
* Requesting semantic diagnostics may start up the type system and
* run deferred work, so the first call may take longer than subsequent calls.
*
* Unlike the other get*Diagnostics functions, these diagnostics can potentially not
* include a reference to a source file. Specifically, the first time this is called,
* it will return global diagnostics with no associated location.
*
* To contrast the differences between semantic and syntactic diagnostics, consider the
* sentence: "The sun is green." is syntactically correct; those are real English words with
* correct sentence structure. However, it is semantically invalid, because it is not true.
*
* @param fileName A path to the file you want semantic diagnostics for
*/
getSemanticDiagnostics(fileName: string): Diagnostic[];
/**
* Similar to {@link getSemanticDiagnostics}, but only checks the specified ranges of the file for diagnostics.
* @internal
*/
getRegionSemanticDiagnostics(fileName: string, ranges: TextRange[]): RegionDiagnosticsResult | undefined;
/**
* Gets suggestion diagnostics for a specific file. These diagnostics tend to
* proactively suggest refactors, as opposed to diagnostics that indicate
* potentially incorrect runtime behavior.
*
* @param fileName A path to the file you want semantic diagnostics for
*/
getSuggestionDiagnostics(fileName: string): DiagnosticWithLocation[];
// TODO: Rename this to getProgramDiagnostics to better indicate that these are any
// diagnostics present for the program level, and not just 'options' diagnostics.
/**
* Gets global diagnostics related to the program configuration and compiler options.
*/
getCompilerOptionsDiagnostics(): Diagnostic[];
/** @deprecated Use getEncodedSyntacticClassifications instead. */
getSyntacticClassifications(fileName: string, span: TextSpan): ClassifiedSpan[];
getSyntacticClassifications(fileName: string, span: TextSpan, format: SemanticClassificationFormat): ClassifiedSpan[] | ClassifiedSpan2020[];
/** @deprecated Use getEncodedSemanticClassifications instead. */
getSemanticClassifications(fileName: string, span: TextSpan): ClassifiedSpan[];
getSemanticClassifications(fileName: string, span: TextSpan, format: SemanticClassificationFormat): ClassifiedSpan[] | ClassifiedSpan2020[];
/** Encoded as triples of [start, length, ClassificationType]. */
getEncodedSyntacticClassifications(fileName: string, span: TextSpan): Classifications;
/**
* Gets semantic highlights information for a particular file. Has two formats, an older
* version used by VS and a format used by VS Code.
*
* @param fileName The path to the file
* @param position A text span to return results within
* @param format Which format to use, defaults to "original"
* @returns a number array encoded as triples of [start, length, ClassificationType, ...].
*/
getEncodedSemanticClassifications(fileName: string, span: TextSpan, format?: SemanticClassificationFormat): Classifications;
/**
* Gets completion entries at a particular position in a file.
*
* @param fileName The path to the file
* @param position A zero-based index of the character where you want the entries
* @param options An object describing how the request was triggered and what kinds
* of code actions can be returned with the completions.
* @param formattingSettings settings needed for calling formatting functions.
*/
getCompletionsAtPosition(fileName: string, position: number, options: GetCompletionsAtPositionOptions | undefined, formattingSettings?: FormatCodeSettings): WithMetadata<CompletionInfo> | undefined;
/**
* Gets the extended details for a completion entry retrieved from `getCompletionsAtPosition`.
*
* @param fileName The path to the file
* @param position A zero based index of the character where you want the entries
* @param entryName The `name` from an existing completion which came from `getCompletionsAtPosition`
* @param formatOptions How should code samples in the completions be formatted, can be undefined for backwards compatibility
* @param source `source` property from the completion entry
* @param preferences User settings, can be undefined for backwards compatibility
* @param data `data` property from the completion entry
*/
getCompletionEntryDetails(
fileName: string,
position: number,
entryName: string,
formatOptions: FormatCodeOptions | FormatCodeSettings | undefined,
source: string | undefined,
preferences: UserPreferences | undefined,
data: CompletionEntryData | undefined,
): CompletionEntryDetails | undefined;
getCompletionEntrySymbol(fileName: string, position: number, name: string, source: string | undefined): Symbol | undefined;
/**
* Gets semantic information about the identifier at a particular position in a
* file. Quick info is what you typically see when you hover in an editor.
*
* @param fileName The path to the file
* @param position A zero-based index of the character where you want the quick info
*/
getQuickInfoAtPosition(fileName: string, position: number): QuickInfo | undefined;
/** @internal */
getQuickInfoAtPosition(fileName: string, position: number, verbosityLevel: number | undefined): QuickInfo | undefined; // eslint-disable-line @typescript-eslint/unified-signatures
getNameOrDottedNameSpan(fileName: string, startPos: number, endPos: number): TextSpan | undefined;
getBreakpointStatementAtPosition(fileName: string, position: number): TextSpan | undefined;
getSignatureHelpItems(fileName: string, position: number, options: SignatureHelpItemsOptions | undefined): SignatureHelpItems | undefined;
getRenameInfo(fileName: string, position: number, preferences: UserPreferences): RenameInfo;
/** @deprecated Use the signature with `UserPreferences` instead. */
getRenameInfo(fileName: string, position: number, options?: RenameInfoOptions): RenameInfo;
findRenameLocations(fileName: string, position: number, findInStrings: boolean, findInComments: boolean, preferences: UserPreferences): readonly RenameLocation[] | undefined;
/** @deprecated Pass `providePrefixAndSuffixTextForRename` as part of a `UserPreferences` parameter. */
findRenameLocations(fileName: string, position: number, findInStrings: boolean, findInComments: boolean, providePrefixAndSuffixTextForRename?: boolean): readonly RenameLocation[] | undefined;
getSmartSelectionRange(fileName: string, position: number): SelectionRange;
/** @internal */
getDefinitionAtPosition(fileName: string, position: number, searchOtherFilesOnly: false, stopAtAlias: boolean): readonly DefinitionInfo[] | undefined;
/** @internal */
getDefinitionAtPosition(fileName: string, position: number, searchOtherFilesOnly: boolean, stopAtAlias: false): readonly DefinitionInfo[] | undefined;
getDefinitionAtPosition(fileName: string, position: number): readonly DefinitionInfo[] | undefined;
getDefinitionAndBoundSpan(fileName: string, position: number): DefinitionInfoAndBoundSpan | undefined;
getTypeDefinitionAtPosition(fileName: string, position: number): readonly DefinitionInfo[] | undefined;
getImplementationAtPosition(fileName: string, position: number): readonly ImplementationLocation[] | undefined;
getReferencesAtPosition(fileName: string, position: number): ReferenceEntry[] | undefined;
findReferences(fileName: string, position: number): ReferencedSymbol[] | undefined;
getDocumentHighlights(fileName: string, position: number, filesToSearch: string[]): DocumentHighlights[] | undefined;
getFileReferences(fileName: string): ReferenceEntry[];
getNavigateToItems(searchValue: string, maxResultCount?: number, fileName?: string, excludeDtsFiles?: boolean, excludeLibFiles?: boolean): NavigateToItem[];
getNavigationBarItems(fileName: string): NavigationBarItem[];
getNavigationTree(fileName: string): NavigationTree;
prepareCallHierarchy(fileName: string, position: number): CallHierarchyItem | CallHierarchyItem[] | undefined;
provideCallHierarchyIncomingCalls(fileName: string, position: number): CallHierarchyIncomingCall[];
provideCallHierarchyOutgoingCalls(fileName: string, position: number): CallHierarchyOutgoingCall[];
provideInlayHints(fileName: string, span: TextSpan, preferences: UserPreferences | undefined): InlayHint[];
getOutliningSpans(fileName: string): OutliningSpan[];
getTodoComments(fileName: string, descriptors: TodoCommentDescriptor[]): TodoComment[];
getBraceMatchingAtPosition(fileName: string, position: number): TextSpan[];
getIndentationAtPosition(fileName: string, position: number, options: EditorOptions | EditorSettings): number;
getFormattingEditsForRange(fileName: string, start: number, end: number, options: FormatCodeOptions | FormatCodeSettings): TextChange[];
getFormattingEditsForDocument(fileName: string, options: FormatCodeOptions | FormatCodeSettings): TextChange[];
getFormattingEditsAfterKeystroke(fileName: string, position: number, key: string, options: FormatCodeOptions | FormatCodeSettings): TextChange[];
getDocCommentTemplateAtPosition(fileName: string, position: number, options?: DocCommentTemplateOptions, formatOptions?: FormatCodeSettings): TextInsertion | undefined;
isValidBraceCompletionAtPosition(fileName: string, position: number, openingBrace: number): boolean;
/**
* This will return a defined result if the position is after the `>` of the opening tag, or somewhere in the text, of a JSXElement with no closing tag.
* Editors should call this after `>` is typed.
*/
getJsxClosingTagAtPosition(fileName: string, position: number): JsxClosingTagInfo | undefined;
getLinkedEditingRangeAtPosition(fileName: string, position: number): LinkedEditingInfo | undefined;
getSpanOfEnclosingComment(fileName: string, position: number, onlyMultiLine: boolean): TextSpan | undefined;
toLineColumnOffset?(fileName: string, position: number): LineAndCharacter;
/** @internal */
getSourceMapper(): SourceMapper;
/** @internal */
clearSourceMapperCache(): void;
getCodeFixesAtPosition(fileName: string, start: number, end: number, errorCodes: readonly number[], formatOptions: FormatCodeSettings, preferences: UserPreferences): readonly CodeFixAction[];
getCombinedCodeFix(scope: CombinedCodeFixScope, fixId: {}, formatOptions: FormatCodeSettings, preferences: UserPreferences): CombinedCodeActions;
applyCodeActionCommand(action: CodeActionCommand, formatSettings?: FormatCodeSettings): Promise<ApplyCodeActionCommandResult>;
applyCodeActionCommand(action: CodeActionCommand[], formatSettings?: FormatCodeSettings): Promise<ApplyCodeActionCommandResult[]>;
applyCodeActionCommand(action: CodeActionCommand | CodeActionCommand[], formatSettings?: FormatCodeSettings): Promise<ApplyCodeActionCommandResult | ApplyCodeActionCommandResult[]>;
/** @deprecated `fileName` will be ignored */
applyCodeActionCommand(fileName: string, action: CodeActionCommand): Promise<ApplyCodeActionCommandResult>;
/** @deprecated `fileName` will be ignored */
applyCodeActionCommand(fileName: string, action: CodeActionCommand[]): Promise<ApplyCodeActionCommandResult[]>;
/** @deprecated `fileName` will be ignored */
applyCodeActionCommand(fileName: string, action: CodeActionCommand | CodeActionCommand[]): Promise<ApplyCodeActionCommandResult | ApplyCodeActionCommandResult[]>;
/**
* @param includeInteractiveActions Include refactor actions that require additional arguments to be
* passed when calling `getEditsForRefactor`. When true, clients should inspect the `isInteractive`
* property of each returned `RefactorActionInfo` and ensure they are able to collect the appropriate
* arguments for any interactive action before offering it.
*/
getApplicableRefactors(fileName: string, positionOrRange: number | TextRange, preferences: UserPreferences | undefined, triggerReason?: RefactorTriggerReason, kind?: string, includeInteractiveActions?: boolean): ApplicableRefactorInfo[];
getEditsForRefactor(fileName: string, formatOptions: FormatCodeSettings, positionOrRange: number | TextRange, refactorName: string, actionName: string, preferences: UserPreferences | undefined, interactiveRefactorArguments?: InteractiveRefactorArguments): RefactorEditInfo | undefined;
getMoveToRefactoringFileSuggestions(fileName: string, positionOrRange: number | TextRange, preferences: UserPreferences | undefined, triggerReason?: RefactorTriggerReason, kind?: string): { newFileName: string; files: string[]; };
organizeImports(args: OrganizeImportsArgs, formatOptions: FormatCodeSettings, preferences: UserPreferences | undefined): readonly FileTextChanges[];
getEditsForFileRename(oldFilePath: string, newFilePath: string, formatOptions: FormatCodeSettings, preferences: UserPreferences | undefined): readonly FileTextChanges[];
getEmitOutput(fileName: string, emitOnlyDtsFiles?: boolean, forceDtsEmit?: boolean): EmitOutput;
getProgram(): Program | undefined;
/** @internal */ getCurrentProgram(): Program | undefined;
/** @internal */ getNonBoundSourceFile(fileName: string): SourceFile;
/** @internal */ getAutoImportProvider(): Program | undefined;
/// Returns true if a suitable symbol was found in the project.
/// May set isDefinition properties in `referencedSymbols` to false.
/// May add elements to `knownSymbolSpans`.
/** @internal */ updateIsDefinitionOfReferencedSymbols(referencedSymbols: readonly ReferencedSymbol[], knownSymbolSpans: Set<DocumentSpan>): boolean;
toggleLineComment(fileName: string, textRange: TextRange): TextChange[];
toggleMultilineComment(fileName: string, textRange: TextRange): TextChange[];
commentSelection(fileName: string, textRange: TextRange): TextChange[];
uncommentSelection(fileName: string, textRange: TextRange): TextChange[];
getSupportedCodeFixes(fileName?: string): readonly string[];
/** @internal */ mapCode(fileName: string, contents: string[], focusLocations: TextSpan[][] | undefined, formatOptions: FormatCodeSettings, preferences: UserPreferences): readonly FileTextChanges[];
dispose(): void;
preparePasteEditsForFile(fileName: string, copiedTextRanges: TextRange[]): boolean;
getPasteEdits(
args: PasteEditsArgs,
formatOptions: FormatCodeSettings,
): PasteEdits;
}
export interface JsxClosingTagInfo {
readonly newText: string;
}
export interface LinkedEditingInfo {
readonly ranges: TextSpan[];
wordPattern?: string;
}
export interface CombinedCodeFixScope {
type: "file";
fileName: string;
}
export const enum OrganizeImportsMode {
All = "All",
SortAndCombine = "SortAndCombine",
RemoveUnused = "RemoveUnused",
}
export interface PasteEdits {
edits: readonly FileTextChanges[];
fixId?: {};
}
export interface PasteEditsArgs {
targetFile: string;
pastedText: string[];
pasteLocations: TextRange[];
copiedFrom: { file: string; range: TextRange[]; } | undefined;
preferences: UserPreferences;
}
export interface OrganizeImportsArgs extends CombinedCodeFixScope {
/** @deprecated Use `mode` instead */
skipDestructiveCodeActions?: boolean;
mode?: OrganizeImportsMode;
}
export type CompletionsTriggerCharacter = "." | '"' | "'" | "`" | "/" | "@" | "<" | "#" | " ";
export const enum CompletionTriggerKind {
/** Completion was triggered by typing an identifier, manual invocation (e.g Ctrl+Space) or via API. */
Invoked = 1,
/** Completion was triggered by a trigger character. */
TriggerCharacter = 2,
/** Completion was re-triggered as the current completion list is incomplete. */
TriggerForIncompleteCompletions = 3,
}
export interface GetCompletionsAtPositionOptions extends UserPreferences {
/**
* If the editor is asking for completions because a certain character was typed
* (as opposed to when the user explicitly requested them) this should be set.
*/
triggerCharacter?: CompletionsTriggerCharacter;
triggerKind?: CompletionTriggerKind;
/**
* Include a `symbol` property on each completion entry object.
* Symbols reference cyclic data structures and sometimes an entire TypeChecker instance,
* so use caution when serializing or retaining completion entries retrieved with this option.
* @default false
*/
includeSymbol?: boolean;
/** @deprecated Use includeCompletionsForModuleExports */
includeExternalModuleExports?: boolean;
/** @deprecated Use includeCompletionsWithInsertText */
includeInsertTextCompletions?: boolean;
}
export type SignatureHelpTriggerCharacter = "," | "(" | "<";
export type SignatureHelpRetriggerCharacter = SignatureHelpTriggerCharacter | ")";
export interface SignatureHelpItemsOptions {
triggerReason?: SignatureHelpTriggerReason;
}
export type SignatureHelpTriggerReason =
| SignatureHelpInvokedReason
| SignatureHelpCharacterTypedReason
| SignatureHelpRetriggeredReason;
/**
* Signals that the user manually requested signature help.
* The language service will unconditionally attempt to provide a result.
*/
export interface SignatureHelpInvokedReason {
kind: "invoked";
triggerCharacter?: undefined;
}
/**
* Signals that the signature help request came from a user typing a character.
* Depending on the character and the syntactic context, the request may or may not be served a result.
*/
export interface SignatureHelpCharacterTypedReason {
kind: "characterTyped";
/**
* Character that was responsible for triggering signature help.
*/
triggerCharacter: SignatureHelpTriggerCharacter;
}
/**
* Signals that this signature help request came from typing a character or moving the cursor.
* This should only occur if a signature help session was already active and the editor needs to see if it should adjust.
* The language service will unconditionally attempt to provide a result.
* `triggerCharacter` can be `undefined` for a retrigger caused by a cursor move.
*/
export interface SignatureHelpRetriggeredReason {
kind: "retrigger";
/**
* Character that was responsible for triggering signature help.
*/
triggerCharacter?: SignatureHelpRetriggerCharacter;
}
export interface ApplyCodeActionCommandResult {
successMessage: string;
}
export interface Classifications {
spans: number[];
endOfLineState: EndOfLineState;
}
export interface ClassifiedSpan {
textSpan: TextSpan;
classificationType: ClassificationTypeNames;
}
export interface ClassifiedSpan2020 {
textSpan: TextSpan;
classificationType: number;
}
/**
* Navigation bar interface designed for visual studio's dual-column layout.
* This does not form a proper tree.
* The navbar is returned as a list of top-level items, each of which has a list of child items.
* Child items always have an empty array for their `childItems`.
*/
export interface NavigationBarItem {
text: string;
kind: ScriptElementKind;
kindModifiers: string;
spans: TextSpan[];
childItems: NavigationBarItem[];
indent: number;
bolded: boolean;
grayed: boolean;
}
/**
* Node in a tree of nested declarations in a file.
* The top node is always a script or module node.
*/
export interface NavigationTree {
/** Name of the declaration, or a short description, e.g. "<class>". */
text: string;
kind: ScriptElementKind;
/** ScriptElementKindModifier separated by commas, e.g. "public,abstract" */
kindModifiers: string;
/**
* Spans of the nodes that generated this declaration.
* There will be more than one if this is the result of merging.
*/
spans: TextSpan[];
nameSpan: TextSpan | undefined;
/** Present if non-empty */
childItems?: NavigationTree[];
}
export interface CallHierarchyItem {
name: string;
kind: ScriptElementKind;
kindModifiers?: string;
file: string;
span: TextSpan;
selectionSpan: TextSpan;
containerName?: string;
}
export interface CallHierarchyIncomingCall {
from: CallHierarchyItem;
fromSpans: TextSpan[];
}
export interface CallHierarchyOutgoingCall {
to: CallHierarchyItem;
fromSpans: TextSpan[];
}
export const enum InlayHintKind {
Type = "Type",
Parameter = "Parameter",
Enum = "Enum",
}
export interface InlayHint {
/** This property will be the empty string when displayParts is set. */
text: string;
position: number;
kind: InlayHintKind;
whitespaceBefore?: boolean;
whitespaceAfter?: boolean;
displayParts?: InlayHintDisplayPart[];
}
export interface InlayHintDisplayPart {
text: string;
span?: TextSpan;
file?: string;
}
export interface TodoCommentDescriptor {
text: string;
priority: number;
}
export interface TodoComment {
descriptor: TodoCommentDescriptor;
message: string;
position: number;
}
export interface TextChange {
span: TextSpan;
newText: string;
}
export interface FileTextChanges {
fileName: string;
textChanges: readonly TextChange[];
isNewFile?: boolean;
}
export interface CodeAction {
/** Description of the code action to display in the UI of the editor */
description: string;
/** Text changes to apply to each file as part of the code action */
changes: FileTextChanges[];
/**
* If the user accepts the code fix, the editor should send the action back in a `applyAction` request.
* This allows the language service to have side effects (e.g. installing dependencies) upon a code fix.
*/
commands?: CodeActionCommand[];
}
export interface CodeFixAction extends CodeAction {
/** Short name to identify the fix, for use by telemetry. */
fixName: string;
/**
* If present, one may call 'getCombinedCodeFix' with this fixId.
* This may be omitted to indicate that the code fix can't be applied in a group.
*/
fixId?: {};
fixAllDescription?: string;
}
export interface CombinedCodeActions {
changes: readonly FileTextChanges[];
commands?: readonly CodeActionCommand[];
}
// Publicly, this type is just `{}`. Internally it is a union of all the actions we use.
// See `commands?: {}[]` in protocol.ts
export type CodeActionCommand = InstallPackageAction;
export interface InstallPackageAction {
/** @internal */ readonly type: "install package";
/** @internal */ readonly file: string;
/** @internal */ readonly packageName: string;
}
/**
* A set of one or more available refactoring actions, grouped under a parent refactoring.
*/
export interface ApplicableRefactorInfo {
/**
* The programmatic name of the refactoring
*/
name: string;
/**
* A description of this refactoring category to show to the user.
* If the refactoring gets inlined (see below), this text will not be visible.
*/
description: string;