1namespace ts { 2 export interface Node { 3 getSourceFile(): SourceFile; 4 getChildCount(sourceFile?: SourceFile): number; 5 getChildAt(index: number, sourceFile?: SourceFile): Node; 6 getChildren(sourceFile?: SourceFile): Node[]; 7 /* @internal */ 8 getChildren(sourceFile?: SourceFileLike): Node[]; // eslint-disable-line @typescript-eslint/unified-signatures 9 getStart(sourceFile?: SourceFile, includeJsDocComment?: boolean): number; 10 /* @internal */ 11 getStart(sourceFile?: SourceFileLike, includeJsDocComment?: boolean): number; // eslint-disable-line @typescript-eslint/unified-signatures 12 getFullStart(): number; 13 getEnd(): number; 14 getWidth(sourceFile?: SourceFileLike): number; 15 getFullWidth(): number; 16 getLeadingTriviaWidth(sourceFile?: SourceFile): number; 17 getFullText(sourceFile?: SourceFile): string; 18 getText(sourceFile?: SourceFile): string; 19 getFirstToken(sourceFile?: SourceFile): Node | undefined; 20 /* @internal */ 21 getFirstToken(sourceFile?: SourceFileLike): Node | undefined; // eslint-disable-line @typescript-eslint/unified-signatures 22 getLastToken(sourceFile?: SourceFile): Node | undefined; 23 /* @internal */ 24 getLastToken(sourceFile?: SourceFileLike): Node | undefined; // eslint-disable-line @typescript-eslint/unified-signatures 25 // See ts.forEachChild for documentation. 26 forEachChild<T>(cbNode: (node: Node) => T | undefined, cbNodeArray?: (nodes: NodeArray<Node>) => T | undefined): T | undefined; 27 } 28 29 export interface Identifier { 30 readonly text: string; 31 } 32 33 export interface PrivateIdentifier { 34 readonly text: string; 35 } 36 37 export interface Symbol { 38 readonly name: string; 39 getFlags(): SymbolFlags; 40 getEscapedName(): __String; 41 getName(): string; 42 getDeclarations(): Declaration[] | undefined; 43 getDocumentationComment(typeChecker: TypeChecker | undefined): SymbolDisplayPart[]; 44 /* @internal */ 45 getContextualDocumentationComment(context: Node | undefined, checker: TypeChecker | undefined): SymbolDisplayPart[] 46 getJsDocTags(): JSDocTagInfo[]; 47 } 48 49 export interface Type { 50 getFlags(): TypeFlags; 51 getSymbol(): Symbol | undefined; 52 getProperties(): Symbol[]; 53 getProperty(propertyName: string): Symbol | undefined; 54 getApparentProperties(): Symbol[]; 55 getCallSignatures(): readonly Signature[]; 56 getConstructSignatures(): readonly Signature[]; 57 getStringIndexType(): Type | undefined; 58 getNumberIndexType(): Type | undefined; 59 getBaseTypes(): BaseType[] | undefined; 60 getNonNullableType(): Type; 61 /*@internal*/ getNonOptionalType(): Type; 62 /*@internal*/ isNullableType(): boolean; 63 getConstraint(): Type | undefined; 64 getDefault(): Type | undefined; 65 66 isUnion(): this is UnionType; 67 isIntersection(): this is IntersectionType; 68 isUnionOrIntersection(): this is UnionOrIntersectionType; 69 isLiteral(): this is LiteralType; 70 isStringLiteral(): this is StringLiteralType; 71 isNumberLiteral(): this is NumberLiteralType; 72 isTypeParameter(): this is TypeParameter; 73 isClassOrInterface(): this is InterfaceType; 74 isClass(): this is InterfaceType; 75 } 76 77 export interface TypeReference { 78 typeArguments?: readonly Type[]; 79 } 80 81 export interface Signature { 82 getDeclaration(): SignatureDeclaration; 83 getTypeParameters(): TypeParameter[] | undefined; 84 getParameters(): Symbol[]; 85 getReturnType(): Type; 86 getDocumentationComment(typeChecker: TypeChecker | undefined): SymbolDisplayPart[]; 87 getJsDocTags(): JSDocTagInfo[]; 88 } 89 90 export interface SourceFile { 91 /* @internal */ version: string; 92 /* @internal */ scriptSnapshot: IScriptSnapshot | undefined; 93 /* @internal */ nameTable: UnderscoreEscapedMap<number> | undefined; 94 95 /* @internal */ getNamedDeclarations(): ESMap<string, readonly Declaration[]>; 96 97 getLineAndCharacterOfPosition(pos: number): LineAndCharacter; 98 getLineEndOfPosition(pos: number): number; 99 getLineStarts(): readonly number[]; 100 getPositionOfLineAndCharacter(line: number, character: number): number; 101 update(newText: string, textChangeRange: TextChangeRange): SourceFile; 102 103 /* @internal */ sourceMapper?: DocumentPositionMapper; 104 } 105 106 export interface SourceFileLike { 107 getLineAndCharacterOfPosition(pos: number): LineAndCharacter; 108 } 109 110 export interface SourceMapSource { 111 getLineAndCharacterOfPosition(pos: number): LineAndCharacter; 112 } 113 114 /** 115 * Represents an immutable snapshot of a script at a specified time.Once acquired, the 116 * snapshot is observably immutable. i.e. the same calls with the same parameters will return 117 * the same values. 118 */ 119 // eslint-disable-next-line @typescript-eslint/naming-convention 120 export interface IScriptSnapshot { 121 /** Gets a portion of the script snapshot specified by [start, end). */ 122 getText(start: number, end: number): string; 123 124 /** Gets the length of this script snapshot. */ 125 getLength(): number; 126 127 /** 128 * Gets the TextChangeRange that describe how the text changed between this text and 129 * an older version. This information is used by the incremental parser to determine 130 * what sections of the script need to be re-parsed. 'undefined' can be returned if the 131 * change range cannot be determined. However, in that case, incremental parsing will 132 * not happen and the entire document will be re - parsed. 133 */ 134 getChangeRange(oldSnapshot: IScriptSnapshot): TextChangeRange | undefined; 135 136 /** Releases all resources held by this script snapshot */ 137 dispose?(): void; 138 } 139 140 export namespace ScriptSnapshot { 141 class StringScriptSnapshot implements IScriptSnapshot { 142 143 constructor(private text: string) { 144 } 145 146 public getText(start: number, end: number): string { 147 return start === 0 && end === this.text.length 148 ? this.text 149 : this.text.substring(start, end); 150 } 151 152 public getLength(): number { 153 return this.text.length; 154 } 155 156 public getChangeRange(): TextChangeRange | undefined { 157 // Text-based snapshots do not support incremental parsing. Return undefined 158 // to signal that to the caller. 159 return undefined; 160 } 161 } 162 163 export function fromString(text: string): IScriptSnapshot { 164 return new StringScriptSnapshot(text); 165 } 166 } 167 168 export interface PreProcessedFileInfo { 169 referencedFiles: FileReference[]; 170 typeReferenceDirectives: FileReference[]; 171 libReferenceDirectives: FileReference[]; 172 importedFiles: FileReference[]; 173 ambientExternalModules?: string[]; 174 isLibFile: boolean; 175 } 176 177 export interface HostCancellationToken { 178 isCancellationRequested(): boolean; 179 } 180 181 export interface InstallPackageOptions { 182 fileName: Path; 183 packageName: string; 184 } 185 186 /* @internal */ 187 export const enum PackageJsonDependencyGroup { 188 Dependencies = 1 << 0, 189 DevDependencies = 1 << 1, 190 PeerDependencies = 1 << 2, 191 OptionalDependencies = 1 << 3, 192 All = Dependencies | DevDependencies | PeerDependencies | OptionalDependencies, 193 } 194 195 /* @internal */ 196 export interface PackageJsonInfo { 197 fileName: string; 198 parseable: boolean; 199 dependencies?: ESMap<string, string>; 200 devDependencies?: ESMap<string, string>; 201 peerDependencies?: ESMap<string, string>; 202 optionalDependencies?: ESMap<string, string>; 203 get(dependencyName: string, inGroups?: PackageJsonDependencyGroup): string | undefined; 204 has(dependencyName: string, inGroups?: PackageJsonDependencyGroup): boolean; 205 } 206 207 /* @internal */ 208 export interface FormattingHost { 209 getNewLine?(): string; 210 } 211 212 /* @internal */ 213 export const enum PackageJsonAutoImportPreference { 214 Off, 215 On, 216 Auto, 217 } 218 219 export interface PerformanceEvent { 220 kind: "UpdateGraph" | "CreatePackageJsonAutoImportProvider"; 221 durationMs: number; 222 } 223 224 export enum LanguageServiceMode { 225 Semantic, 226 PartialSemantic, 227 Syntactic, 228 } 229 230 // 231 // Public interface of the host of a language service instance. 232 // 233 export interface LanguageServiceHost extends GetEffectiveTypeRootsHost { 234 getCompilationSettings(): CompilerOptions; 235 getNewLine?(): string; 236 getProjectVersion?(): string; 237 getScriptFileNames(): string[]; 238 getScriptKind?(fileName: string): ScriptKind; 239 getScriptVersion(fileName: string): string; 240 getScriptSnapshot(fileName: string): IScriptSnapshot | undefined; 241 getProjectReferences?(): readonly ProjectReference[] | undefined; 242 getLocalizedDiagnosticMessages?(): any; 243 getCancellationToken?(): HostCancellationToken; 244 getCurrentDirectory(): string; 245 getDefaultLibFileName(options: CompilerOptions): string; 246 log?(s: string): void; 247 trace?(s: string): void; 248 error?(s: string): void; 249 useCaseSensitiveFileNames?(): boolean; 250 251 /* 252 * LS host can optionally implement these methods to support completions for module specifiers. 253 * Without these methods, only completions for ambient modules will be provided. 254 */ 255 readDirectory?(path: string, extensions?: readonly string[], exclude?: readonly string[], include?: readonly string[], depth?: number): string[]; 256 readFile?(path: string, encoding?: string): string | undefined; 257 realpath?(path: string): string; 258 fileExists?(path: string): boolean; 259 260 /* 261 * LS host can optionally implement these methods to support automatic updating when new type libraries are installed 262 */ 263 getTypeRootsVersion?(): number; 264 265 /* 266 * LS host can optionally implement this method if it wants to be completely in charge of module name resolution. 267 * if implementation is omitted then language service will use built-in module resolution logic and get answers to 268 * host specific questions using 'getScriptSnapshot'. 269 * 270 * If this is implemented, `getResolvedModuleWithFailedLookupLocationsFromCache` should be too. 271 */ 272 resolveModuleNames?(moduleNames: string[], containingFile: string, reusedNames: string[] | undefined, redirectedReference: ResolvedProjectReference | undefined, options: CompilerOptions): (ResolvedModule | undefined)[]; 273 getResolvedModuleWithFailedLookupLocationsFromCache?(modulename: string, containingFile: string): ResolvedModuleWithFailedLookupLocations | undefined; 274 resolveTypeReferenceDirectives?(typeDirectiveNames: string[], containingFile: string, redirectedReference: ResolvedProjectReference | undefined, options: CompilerOptions): (ResolvedTypeReferenceDirective | undefined)[]; 275 /* @internal */ hasInvalidatedResolution?: HasInvalidatedResolution; 276 /* @internal */ hasChangedAutomaticTypeDirectiveNames?: HasChangedAutomaticTypeDirectiveNames; 277 /* @internal */ 278 getGlobalTypingsCacheLocation?(): string | undefined; 279 /* @internal */ 280 getSymlinkCache?(files?: readonly SourceFile[]): SymlinkCache; 281 282 /* 283 * Required for full import and type reference completions. 284 * These should be unprefixed names. E.g. `getDirectories("/foo/bar")` should return `["a", "b"]`, not `["/foo/bar/a", "/foo/bar/b"]`. 285 */ 286 getDirectories?(directoryName: string): string[]; 287 288 /** 289 * Gets a set of custom transformers to use during emit. 290 */ 291 getCustomTransformers?(): CustomTransformers | undefined; 292 293 isKnownTypesPackageName?(name: string): boolean; 294 installPackage?(options: InstallPackageOptions): Promise<ApplyCodeActionCommandResult>; 295 writeFile?(fileName: string, content: string): void; 296 297 /* @internal */ 298 getDocumentPositionMapper?(generatedFileName: string, sourceFileName?: string): DocumentPositionMapper | undefined; 299 /* @internal */ 300 getSourceFileLike?(fileName: string): SourceFileLike | undefined; 301 /* @internal */ 302 getPackageJsonsVisibleToFile?(fileName: string, rootDir?: string): readonly PackageJsonInfo[]; 303 /* @internal */ 304 getNearestAncestorDirectoryWithPackageJson?(fileName: string): string | undefined; 305 /* @internal */ 306 getPackageJsonsForAutoImport?(rootDir?: string): readonly PackageJsonInfo[]; 307 /* @internal */ 308 getImportSuggestionsCache?(): Completions.ImportSuggestionsForFileCache; 309 /* @internal */ 310 setCompilerHost?(host: CompilerHost): void; 311 /* @internal */ 312 useSourceOfProjectReferenceRedirect?(): boolean; 313 /* @internal */ 314 getPackageJsonAutoImportProvider?(): Program | undefined; 315 /* @internal */ 316 sendPerformanceEvent?(kind: PerformanceEvent["kind"], durationMs: number): void; 317 getTagNameNeededCheckByFile?(containFilePath: string, sourceFilePath: string): TagCheckParam; 318 getExpressionCheckedResultsByFile?(filePath: string, jsDocs: JSDocTagInfo[]): ConditionCheckResult; 319 } 320 321 /* @internal */ 322 export const emptyOptions = {}; 323 324 export type WithMetadata<T> = T & { metadata?: unknown; }; 325 326 export const enum SemanticClassificationFormat { 327 Original = "original", 328 TwentyTwenty = "2020" 329 } 330 331 // 332 // Public services of a language service instance associated 333 // with a language service host instance 334 // 335 export interface LanguageService { 336 /** This is used as a part of restarting the language service. */ 337 cleanupSemanticCache(): void; 338 339 /** 340 * Gets errors indicating invalid syntax in a file. 341 * 342 * In English, "this cdeo have, erorrs" is syntactically invalid because it has typos, 343 * grammatical errors, and misplaced punctuation. Likewise, examples of syntax 344 * errors in TypeScript are missing parentheses in an `if` statement, mismatched 345 * curly braces, and using a reserved keyword as a variable name. 346 * 347 * These diagnostics are inexpensive to compute and don't require knowledge of 348 * other files. Note that a non-empty result increases the likelihood of false positives 349 * from `getSemanticDiagnostics`. 350 * 351 * While these represent the majority of syntax-related diagnostics, there are some 352 * that require the type system, which will be present in `getSemanticDiagnostics`. 353 * 354 * @param fileName A path to the file you want syntactic diagnostics for 355 */ 356 getSyntacticDiagnostics(fileName: string): DiagnosticWithLocation[]; 357 358 /** 359 * Gets warnings or errors indicating type system issues in a given file. 360 * Requesting semantic diagnostics may start up the type system and 361 * run deferred work, so the first call may take longer than subsequent calls. 362 * 363 * Unlike the other get*Diagnostics functions, these diagnostics can potentially not 364 * include a reference to a source file. Specifically, the first time this is called, 365 * it will return global diagnostics with no associated location. 366 * 367 * To contrast the differences between semantic and syntactic diagnostics, consider the 368 * sentence: "The sun is green." is syntactically correct; those are real English words with 369 * correct sentence structure. However, it is semantically invalid, because it is not true. 370 * 371 * @param fileName A path to the file you want semantic diagnostics for 372 */ 373 getSemanticDiagnostics(fileName: string): Diagnostic[]; 374 375 /** 376 * Gets suggestion diagnostics for a specific file. These diagnostics tend to 377 * proactively suggest refactors, as opposed to diagnostics that indicate 378 * potentially incorrect runtime behavior. 379 * 380 * @param fileName A path to the file you want semantic diagnostics for 381 */ 382 getSuggestionDiagnostics(fileName: string): DiagnosticWithLocation[]; 383 384 // TODO: Rename this to getProgramDiagnostics to better indicate that these are any 385 // diagnostics present for the program level, and not just 'options' diagnostics. 386 387 /** 388 * Gets global diagnostics related to the program configuration and compiler options. 389 */ 390 getCompilerOptionsDiagnostics(): Diagnostic[]; 391 392 /** @deprecated Use getEncodedSyntacticClassifications instead. */ 393 getSyntacticClassifications(fileName: string, span: TextSpan): ClassifiedSpan[]; 394 getSyntacticClassifications(fileName: string, span: TextSpan, format: SemanticClassificationFormat): ClassifiedSpan[] | ClassifiedSpan2020[]; 395 396 /** @deprecated Use getEncodedSemanticClassifications instead. */ 397 getSemanticClassifications(fileName: string, span: TextSpan): ClassifiedSpan[]; 398 getSemanticClassifications(fileName: string, span: TextSpan, format: SemanticClassificationFormat): ClassifiedSpan[] | ClassifiedSpan2020[]; 399 400 /** Encoded as triples of [start, length, ClassificationType]. */ 401 getEncodedSyntacticClassifications(fileName: string, span: TextSpan): Classifications; 402 403 /** 404 * Gets semantic highlights information for a particular file. Has two formats, an older 405 * version used by VS and a format used by VS Code. 406 * 407 * @param fileName The path to the file 408 * @param position A text span to return results within 409 * @param format Which format to use, defaults to "original" 410 * @returns a number array encoded as triples of [start, length, ClassificationType, ...]. 411 */ 412 getEncodedSemanticClassifications(fileName: string, span: TextSpan, format?: SemanticClassificationFormat): Classifications; 413 414 /** 415 * Gets completion entries at a particular position in a file. 416 * 417 * @param fileName The path to the file 418 * @param position A zero-based index of the character where you want the entries 419 * @param options An object describing how the request was triggered and what kinds 420 * of code actions can be returned with the completions. 421 */ 422 getCompletionsAtPosition(fileName: string, position: number, options: GetCompletionsAtPositionOptions | undefined): WithMetadata<CompletionInfo> | undefined; 423 424 /** 425 * Gets the extended details for a completion entry retrieved from `getCompletionsAtPosition`. 426 * 427 * @param fileName The path to the file 428 * @param position A zero based index of the character where you want the entries 429 * @param entryName The name from an existing completion which came from `getCompletionsAtPosition` 430 * @param formatOptions How should code samples in the completions be formatted, can be undefined for backwards compatibility 431 * @param source Source code for the current file, can be undefined for backwards compatibility 432 * @param preferences User settings, can be undefined for backwards compatibility 433 */ 434 getCompletionEntryDetails( 435 fileName: string, 436 position: number, 437 entryName: string, 438 formatOptions: FormatCodeOptions | FormatCodeSettings | undefined, 439 source: string | undefined, 440 preferences: UserPreferences | undefined, 441 ): CompletionEntryDetails | undefined; 442 443 getCompletionEntrySymbol(fileName: string, position: number, name: string, source: string | undefined): Symbol | undefined; 444 445 /** 446 * Gets semantic information about the identifier at a particular position in a 447 * file. Quick info is what you typically see when you hover in an editor. 448 * 449 * @param fileName The path to the file 450 * @param position A zero-based index of the character where you want the quick info 451 */ 452 getQuickInfoAtPosition(fileName: string, position: number): QuickInfo | undefined; 453 454 getNameOrDottedNameSpan(fileName: string, startPos: number, endPos: number): TextSpan | undefined; 455 456 getBreakpointStatementAtPosition(fileName: string, position: number): TextSpan | undefined; 457 458 getSignatureHelpItems(fileName: string, position: number, options: SignatureHelpItemsOptions | undefined): SignatureHelpItems | undefined; 459 460 getRenameInfo(fileName: string, position: number, options?: RenameInfoOptions): RenameInfo; 461 findRenameLocations(fileName: string, position: number, findInStrings: boolean, findInComments: boolean, providePrefixAndSuffixTextForRename?: boolean): readonly RenameLocation[] | undefined; 462 463 getSmartSelectionRange(fileName: string, position: number): SelectionRange; 464 465 getDefinitionAtPosition(fileName: string, position: number): readonly DefinitionInfo[] | undefined; 466 getDefinitionAndBoundSpan(fileName: string, position: number): DefinitionInfoAndBoundSpan | undefined; 467 getTypeDefinitionAtPosition(fileName: string, position: number): readonly DefinitionInfo[] | undefined; 468 getImplementationAtPosition(fileName: string, position: number): readonly ImplementationLocation[] | undefined; 469 470 getReferencesAtPosition(fileName: string, position: number): ReferenceEntry[] | undefined; 471 findReferences(fileName: string, position: number): ReferencedSymbol[] | undefined; 472 getDocumentHighlights(fileName: string, position: number, filesToSearch: string[]): DocumentHighlights[] | undefined; 473 getFileReferences(fileName: string): ReferenceEntry[]; 474 475 /** @deprecated */ 476 getOccurrencesAtPosition(fileName: string, position: number): readonly ReferenceEntry[] | undefined; 477 478 getNavigateToItems(searchValue: string, maxResultCount?: number, fileName?: string, excludeDtsFiles?: boolean): NavigateToItem[]; 479 getNavigationBarItems(fileName: string): NavigationBarItem[]; 480 getNavigationTree(fileName: string): NavigationTree; 481 482 prepareCallHierarchy(fileName: string, position: number): CallHierarchyItem | CallHierarchyItem[] | undefined; 483 provideCallHierarchyIncomingCalls(fileName: string, position: number): CallHierarchyIncomingCall[]; 484 provideCallHierarchyOutgoingCalls(fileName: string, position: number): CallHierarchyOutgoingCall[]; 485 486 getOutliningSpans(fileName: string): OutliningSpan[]; 487 getTodoComments(fileName: string, descriptors: TodoCommentDescriptor[]): TodoComment[]; 488 getBraceMatchingAtPosition(fileName: string, position: number): TextSpan[]; 489 getIndentationAtPosition(fileName: string, position: number, options: EditorOptions | EditorSettings): number; 490 491 getFormattingEditsForRange(fileName: string, start: number, end: number, options: FormatCodeOptions | FormatCodeSettings): TextChange[]; 492 getFormattingEditsForDocument(fileName: string, options: FormatCodeOptions | FormatCodeSettings): TextChange[]; 493 getFormattingEditsAfterKeystroke(fileName: string, position: number, key: string, options: FormatCodeOptions | FormatCodeSettings): TextChange[]; 494 495 getDocCommentTemplateAtPosition(fileName: string, position: number, options?: DocCommentTemplateOptions): TextInsertion | undefined; 496 497 isValidBraceCompletionAtPosition(fileName: string, position: number, openingBrace: number): boolean; 498 /** 499 * 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. 500 * Editors should call this after `>` is typed. 501 */ 502 getJsxClosingTagAtPosition(fileName: string, position: number): JsxClosingTagInfo | undefined; 503 504 getSpanOfEnclosingComment(fileName: string, position: number, onlyMultiLine: boolean): TextSpan | undefined; 505 506 toLineColumnOffset?(fileName: string, position: number): LineAndCharacter; 507 /** @internal */ 508 getSourceMapper(): SourceMapper; 509 /** @internal */ 510 clearSourceMapperCache(): void; 511 512 getCodeFixesAtPosition(fileName: string, start: number, end: number, errorCodes: readonly number[], formatOptions: FormatCodeSettings, preferences: UserPreferences): readonly CodeFixAction[]; 513 getCombinedCodeFix(scope: CombinedCodeFixScope, fixId: {}, formatOptions: FormatCodeSettings, preferences: UserPreferences): CombinedCodeActions; 514 515 applyCodeActionCommand(action: CodeActionCommand, formatSettings?: FormatCodeSettings): Promise<ApplyCodeActionCommandResult>; 516 applyCodeActionCommand(action: CodeActionCommand[], formatSettings?: FormatCodeSettings): Promise<ApplyCodeActionCommandResult[]>; 517 applyCodeActionCommand(action: CodeActionCommand | CodeActionCommand[], formatSettings?: FormatCodeSettings): Promise<ApplyCodeActionCommandResult | ApplyCodeActionCommandResult[]>; 518 /** @deprecated `fileName` will be ignored */ 519 applyCodeActionCommand(fileName: string, action: CodeActionCommand): Promise<ApplyCodeActionCommandResult>; 520 /** @deprecated `fileName` will be ignored */ 521 applyCodeActionCommand(fileName: string, action: CodeActionCommand[]): Promise<ApplyCodeActionCommandResult[]>; 522 /** @deprecated `fileName` will be ignored */ 523 applyCodeActionCommand(fileName: string, action: CodeActionCommand | CodeActionCommand[]): Promise<ApplyCodeActionCommandResult | ApplyCodeActionCommandResult[]>; 524 525 getApplicableRefactors(fileName: string, positionOrRange: number | TextRange, preferences: UserPreferences | undefined, triggerReason?: RefactorTriggerReason, kind?: string): ApplicableRefactorInfo[]; 526 getEditsForRefactor(fileName: string, formatOptions: FormatCodeSettings, positionOrRange: number | TextRange, refactorName: string, actionName: string, preferences: UserPreferences | undefined): RefactorEditInfo | undefined; 527 organizeImports(scope: OrganizeImportsScope, formatOptions: FormatCodeSettings, preferences: UserPreferences | undefined): readonly FileTextChanges[]; 528 getEditsForFileRename(oldFilePath: string, newFilePath: string, formatOptions: FormatCodeSettings, preferences: UserPreferences | undefined): readonly FileTextChanges[]; 529 530 getEmitOutput(fileName: string, emitOnlyDtsFiles?: boolean, forceDtsEmit?: boolean): EmitOutput; 531 532 getProgram(): Program | undefined; 533 534 /* @internal */ getNonBoundSourceFile(fileName: string): SourceFile; 535 /* @internal */ getAutoImportProvider(): Program | undefined; 536 537 toggleLineComment(fileName: string, textRange: TextRange): TextChange[]; 538 toggleMultilineComment(fileName: string, textRange: TextRange): TextChange[]; 539 commentSelection(fileName: string, textRange: TextRange): TextChange[]; 540 uncommentSelection(fileName: string, textRange: TextRange): TextChange[]; 541 542 dispose(): void; 543 } 544 545 export interface JsxClosingTagInfo { 546 readonly newText: string; 547 } 548 549 export interface CombinedCodeFixScope { type: "file"; fileName: string; } 550 551 export type OrganizeImportsScope = CombinedCodeFixScope; 552 553 export type CompletionsTriggerCharacter = "." | '"' | "'" | "`" | "/" | "@" | "<" | "#"; 554 555 export interface GetCompletionsAtPositionOptions extends UserPreferences { 556 /** 557 * If the editor is asking for completions because a certain character was typed 558 * (as opposed to when the user explicitly requested them) this should be set. 559 */ 560 triggerCharacter?: CompletionsTriggerCharacter; 561 /** @deprecated Use includeCompletionsForModuleExports */ 562 includeExternalModuleExports?: boolean; 563 /** @deprecated Use includeCompletionsWithInsertText */ 564 includeInsertTextCompletions?: boolean; 565 } 566 567 export type SignatureHelpTriggerCharacter = "," | "(" | "<"; 568 export type SignatureHelpRetriggerCharacter = SignatureHelpTriggerCharacter | ")"; 569 570 export interface SignatureHelpItemsOptions { 571 triggerReason?: SignatureHelpTriggerReason; 572 } 573 574 export type SignatureHelpTriggerReason = 575 | SignatureHelpInvokedReason 576 | SignatureHelpCharacterTypedReason 577 | SignatureHelpRetriggeredReason; 578 579 /** 580 * Signals that the user manually requested signature help. 581 * The language service will unconditionally attempt to provide a result. 582 */ 583 export interface SignatureHelpInvokedReason { 584 kind: "invoked"; 585 triggerCharacter?: undefined; 586 } 587 588 /** 589 * Signals that the signature help request came from a user typing a character. 590 * Depending on the character and the syntactic context, the request may or may not be served a result. 591 */ 592 export interface SignatureHelpCharacterTypedReason { 593 kind: "characterTyped"; 594 /** 595 * Character that was responsible for triggering signature help. 596 */ 597 triggerCharacter: SignatureHelpTriggerCharacter; 598 } 599 600 /** 601 * Signals that this signature help request came from typing a character or moving the cursor. 602 * This should only occur if a signature help session was already active and the editor needs to see if it should adjust. 603 * The language service will unconditionally attempt to provide a result. 604 * `triggerCharacter` can be `undefined` for a retrigger caused by a cursor move. 605 */ 606 export interface SignatureHelpRetriggeredReason { 607 kind: "retrigger"; 608 /** 609 * Character that was responsible for triggering signature help. 610 */ 611 triggerCharacter?: SignatureHelpRetriggerCharacter; 612 } 613 614 export interface ApplyCodeActionCommandResult { 615 successMessage: string; 616 } 617 618 export interface Classifications { 619 spans: number[]; 620 endOfLineState: EndOfLineState; 621 } 622 623 export interface ClassifiedSpan { 624 textSpan: TextSpan; 625 classificationType: ClassificationTypeNames; 626 } 627 628 export interface ClassifiedSpan2020 { 629 textSpan: TextSpan; 630 classificationType: number; 631 } 632 633 /** 634 * Navigation bar interface designed for visual studio's dual-column layout. 635 * This does not form a proper tree. 636 * The navbar is returned as a list of top-level items, each of which has a list of child items. 637 * Child items always have an empty array for their `childItems`. 638 */ 639 export interface NavigationBarItem { 640 text: string; 641 kind: ScriptElementKind; 642 kindModifiers: string; 643 spans: TextSpan[]; 644 childItems: NavigationBarItem[]; 645 indent: number; 646 bolded: boolean; 647 grayed: boolean; 648 } 649 650 /** 651 * Node in a tree of nested declarations in a file. 652 * The top node is always a script or module node. 653 */ 654 export interface NavigationTree { 655 /** Name of the declaration, or a short description, e.g. "<class>". */ 656 text: string; 657 kind: ScriptElementKind; 658 /** ScriptElementKindModifier separated by commas, e.g. "public,abstract" */ 659 kindModifiers: string; 660 /** 661 * Spans of the nodes that generated this declaration. 662 * There will be more than one if this is the result of merging. 663 */ 664 spans: TextSpan[]; 665 nameSpan: TextSpan | undefined; 666 /** Present if non-empty */ 667 childItems?: NavigationTree[]; 668 } 669 670 export interface CallHierarchyItem { 671 name: string; 672 kind: ScriptElementKind; 673 kindModifiers?: string; 674 file: string; 675 span: TextSpan; 676 selectionSpan: TextSpan; 677 containerName?: string; 678 } 679 680 export interface CallHierarchyIncomingCall { 681 from: CallHierarchyItem; 682 fromSpans: TextSpan[]; 683 } 684 685 export interface CallHierarchyOutgoingCall { 686 to: CallHierarchyItem; 687 fromSpans: TextSpan[]; 688 } 689 690 export interface TodoCommentDescriptor { 691 text: string; 692 priority: number; 693 } 694 695 export interface TodoComment { 696 descriptor: TodoCommentDescriptor; 697 message: string; 698 position: number; 699 } 700 701 export interface TextChange { 702 span: TextSpan; 703 newText: string; 704 } 705 706 export interface FileTextChanges { 707 fileName: string; 708 textChanges: readonly TextChange[]; 709 isNewFile?: boolean; 710 } 711 712 export interface CodeAction { 713 /** Description of the code action to display in the UI of the editor */ 714 description: string; 715 /** Text changes to apply to each file as part of the code action */ 716 changes: FileTextChanges[]; 717 /** 718 * If the user accepts the code fix, the editor should send the action back in a `applyAction` request. 719 * This allows the language service to have side effects (e.g. installing dependencies) upon a code fix. 720 */ 721 commands?: CodeActionCommand[]; 722 } 723 724 export interface CodeFixAction extends CodeAction { 725 /** Short name to identify the fix, for use by telemetry. */ 726 fixName: string; 727 /** 728 * If present, one may call 'getCombinedCodeFix' with this fixId. 729 * This may be omitted to indicate that the code fix can't be applied in a group. 730 */ 731 fixId?: {}; 732 fixAllDescription?: string; 733 } 734 735 export interface CombinedCodeActions { 736 changes: readonly FileTextChanges[]; 737 commands?: readonly CodeActionCommand[]; 738 } 739 740 // Publicly, this type is just `{}`. Internally it is a union of all the actions we use. 741 // See `commands?: {}[]` in protocol.ts 742 export type CodeActionCommand = InstallPackageAction; 743 744 export interface InstallPackageAction { 745 /* @internal */ readonly type: "install package"; 746 /* @internal */ readonly file: string; 747 /* @internal */ readonly packageName: string; 748 } 749 750 /** 751 * A set of one or more available refactoring actions, grouped under a parent refactoring. 752 */ 753 export interface ApplicableRefactorInfo { 754 /** 755 * The programmatic name of the refactoring 756 */ 757 name: string; 758 /** 759 * A description of this refactoring category to show to the user. 760 * If the refactoring gets inlined (see below), this text will not be visible. 761 */ 762 description: string; 763 /** 764 * Inlineable refactorings can have their actions hoisted out to the top level 765 * of a context menu. Non-inlineanable refactorings should always be shown inside 766 * their parent grouping. 767 * 768 * If not specified, this value is assumed to be 'true' 769 */ 770 inlineable?: boolean; 771 772 actions: RefactorActionInfo[]; 773 } 774 775 /** 776 * Represents a single refactoring action - for example, the "Extract Method..." refactor might 777 * offer several actions, each corresponding to a surround class or closure to extract into. 778 */ 779 export interface RefactorActionInfo { 780 /** 781 * The programmatic name of the refactoring action 782 */ 783 name: string; 784 785 /** 786 * A description of this refactoring action to show to the user. 787 * If the parent refactoring is inlined away, this will be the only text shown, 788 * so this description should make sense by itself if the parent is inlineable=true 789 */ 790 description: string; 791 792 /** 793 * A message to show to the user if the refactoring cannot be applied in 794 * the current context. 795 */ 796 notApplicableReason?: string; 797 798 /** 799 * The hierarchical dotted name of the refactor action. 800 */ 801 kind?: string; 802 } 803 804 /** 805 * A set of edits to make in response to a refactor action, plus an optional 806 * location where renaming should be invoked from 807 */ 808 export interface RefactorEditInfo { 809 edits: FileTextChanges[]; 810 renameFilename?: string ; 811 renameLocation?: number; 812 commands?: CodeActionCommand[]; 813 } 814 815 export type RefactorTriggerReason = "implicit" | "invoked"; 816 817 export interface TextInsertion { 818 newText: string; 819 /** The position in newText the caret should point to after the insertion. */ 820 caretOffset: number; 821 } 822 823 export interface DocumentSpan { 824 textSpan: TextSpan; 825 fileName: string; 826 827 /** 828 * If the span represents a location that was remapped (e.g. via a .d.ts.map file), 829 * then the original filename and span will be specified here 830 */ 831 originalTextSpan?: TextSpan; 832 originalFileName?: string; 833 834 /** 835 * If DocumentSpan.textSpan is the span for name of the declaration, 836 * then this is the span for relevant declaration 837 */ 838 contextSpan?: TextSpan; 839 originalContextSpan?: TextSpan; 840 } 841 842 export interface RenameLocation extends DocumentSpan { 843 readonly prefixText?: string; 844 readonly suffixText?: string; 845 } 846 847 export interface ReferenceEntry extends DocumentSpan { 848 isWriteAccess: boolean; 849 isDefinition: boolean; 850 isInString?: true; 851 } 852 853 export interface ImplementationLocation extends DocumentSpan { 854 kind: ScriptElementKind; 855 displayParts: SymbolDisplayPart[]; 856 } 857 858 export const enum HighlightSpanKind { 859 none = "none", 860 definition = "definition", 861 reference = "reference", 862 writtenReference = "writtenReference", 863 } 864 865 export interface HighlightSpan { 866 fileName?: string; 867 isInString?: true; 868 textSpan: TextSpan; 869 contextSpan?: TextSpan; 870 kind: HighlightSpanKind; 871 } 872 873 export interface NavigateToItem { 874 name: string; 875 kind: ScriptElementKind; 876 kindModifiers: string; 877 matchKind: "exact" | "prefix" | "substring" | "camelCase"; 878 isCaseSensitive: boolean; 879 fileName: string; 880 textSpan: TextSpan; 881 containerName: string; 882 containerKind: ScriptElementKind; 883 } 884 885 export enum IndentStyle { 886 None = 0, 887 Block = 1, 888 Smart = 2, 889 } 890 891 export enum SemicolonPreference { 892 Ignore = "ignore", 893 Insert = "insert", 894 Remove = "remove", 895 } 896 897 /* @deprecated - consider using EditorSettings instead */ 898 export interface EditorOptions { 899 BaseIndentSize?: number; 900 IndentSize: number; 901 TabSize: number; 902 NewLineCharacter: string; 903 ConvertTabsToSpaces: boolean; 904 IndentStyle: IndentStyle; 905 } 906 907 // TODO: GH#18217 These are frequently asserted as defined 908 export interface EditorSettings { 909 baseIndentSize?: number; 910 indentSize?: number; 911 tabSize?: number; 912 newLineCharacter?: string; 913 convertTabsToSpaces?: boolean; 914 indentStyle?: IndentStyle; 915 trimTrailingWhitespace?: boolean; 916 } 917 918 /* @deprecated - consider using FormatCodeSettings instead */ 919 export interface FormatCodeOptions extends EditorOptions { 920 InsertSpaceAfterCommaDelimiter: boolean; 921 InsertSpaceAfterSemicolonInForStatements: boolean; 922 InsertSpaceBeforeAndAfterBinaryOperators: boolean; 923 InsertSpaceAfterConstructor?: boolean; 924 InsertSpaceAfterKeywordsInControlFlowStatements: boolean; 925 InsertSpaceAfterFunctionKeywordForAnonymousFunctions: boolean; 926 InsertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis: boolean; 927 InsertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets: boolean; 928 InsertSpaceAfterOpeningAndBeforeClosingNonemptyBraces?: boolean; 929 InsertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces: boolean; 930 InsertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces?: boolean; 931 InsertSpaceAfterTypeAssertion?: boolean; 932 InsertSpaceBeforeFunctionParenthesis?: boolean; 933 PlaceOpenBraceOnNewLineForFunctions: boolean; 934 PlaceOpenBraceOnNewLineForControlBlocks: boolean; 935 insertSpaceBeforeTypeAnnotation?: boolean; 936 } 937 938 export interface FormatCodeSettings extends EditorSettings { 939 readonly insertSpaceAfterCommaDelimiter?: boolean; 940 readonly insertSpaceAfterSemicolonInForStatements?: boolean; 941 readonly insertSpaceBeforeAndAfterBinaryOperators?: boolean; 942 readonly insertSpaceAfterConstructor?: boolean; 943 readonly insertSpaceAfterKeywordsInControlFlowStatements?: boolean; 944 readonly insertSpaceAfterFunctionKeywordForAnonymousFunctions?: boolean; 945 readonly insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis?: boolean; 946 readonly insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets?: boolean; 947 readonly insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces?: boolean; 948 readonly insertSpaceAfterOpeningAndBeforeClosingEmptyBraces?: boolean; 949 readonly insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces?: boolean; 950 readonly insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces?: boolean; 951 readonly insertSpaceAfterTypeAssertion?: boolean; 952 readonly insertSpaceBeforeFunctionParenthesis?: boolean; 953 readonly placeOpenBraceOnNewLineForFunctions?: boolean; 954 readonly placeOpenBraceOnNewLineForControlBlocks?: boolean; 955 readonly insertSpaceBeforeTypeAnnotation?: boolean; 956 readonly indentMultiLineObjectLiteralBeginningOnBlankLine?: boolean; 957 readonly semicolons?: SemicolonPreference; 958 } 959 960 export function getDefaultFormatCodeSettings(newLineCharacter?: string): FormatCodeSettings { 961 return { 962 indentSize: 4, 963 tabSize: 4, 964 newLineCharacter: newLineCharacter || "\n", 965 convertTabsToSpaces: true, 966 indentStyle: IndentStyle.Smart, 967 insertSpaceAfterConstructor: false, 968 insertSpaceAfterCommaDelimiter: true, 969 insertSpaceAfterSemicolonInForStatements: true, 970 insertSpaceBeforeAndAfterBinaryOperators: true, 971 insertSpaceAfterKeywordsInControlFlowStatements: true, 972 insertSpaceAfterFunctionKeywordForAnonymousFunctions: false, 973 insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis: false, 974 insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets: false, 975 insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces: true, 976 insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces: false, 977 insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces: false, 978 insertSpaceBeforeFunctionParenthesis: false, 979 placeOpenBraceOnNewLineForFunctions: false, 980 placeOpenBraceOnNewLineForControlBlocks: false, 981 semicolons: SemicolonPreference.Ignore, 982 trimTrailingWhitespace: true 983 }; 984 } 985 986 /* @internal */ 987 export const testFormatSettings = getDefaultFormatCodeSettings("\n"); 988 989 export interface DefinitionInfo extends DocumentSpan { 990 kind: ScriptElementKind; 991 name: string; 992 containerKind: ScriptElementKind; 993 containerName: string; 994 /* @internal */ isLocal?: boolean; 995 } 996 997 export interface DefinitionInfoAndBoundSpan { 998 definitions?: readonly DefinitionInfo[]; 999 textSpan: TextSpan; 1000 } 1001 1002 export interface ReferencedSymbolDefinitionInfo extends DefinitionInfo { 1003 displayParts: SymbolDisplayPart[]; 1004 } 1005 1006 export interface ReferencedSymbol { 1007 definition: ReferencedSymbolDefinitionInfo; 1008 references: ReferenceEntry[]; 1009 } 1010 1011 export enum SymbolDisplayPartKind { 1012 aliasName, 1013 className, 1014 enumName, 1015 fieldName, 1016 interfaceName, 1017 keyword, 1018 lineBreak, 1019 numericLiteral, 1020 stringLiteral, 1021 localName, 1022 methodName, 1023 moduleName, 1024 operator, 1025 parameterName, 1026 propertyName, 1027 punctuation, 1028 space, 1029 text, 1030 typeParameterName, 1031 enumMemberName, 1032 functionName, 1033 regularExpressionLiteral, 1034 } 1035 1036 export interface SymbolDisplayPart { 1037 text: string; 1038 kind: string; 1039 } 1040 1041 export interface JSDocTagInfo { 1042 name: string; 1043 text?: string; 1044 } 1045 1046 export interface QuickInfo { 1047 kind: ScriptElementKind; 1048 kindModifiers: string; 1049 textSpan: TextSpan; 1050 displayParts?: SymbolDisplayPart[]; 1051 documentation?: SymbolDisplayPart[]; 1052 tags?: JSDocTagInfo[]; 1053 } 1054 1055 export type RenameInfo = RenameInfoSuccess | RenameInfoFailure; 1056 export interface RenameInfoSuccess { 1057 canRename: true; 1058 /** 1059 * File or directory to rename. 1060 * If set, `getEditsForFileRename` should be called instead of `findRenameLocations`. 1061 */ 1062 fileToRename?: string; 1063 displayName: string; 1064 fullDisplayName: string; 1065 kind: ScriptElementKind; 1066 kindModifiers: string; 1067 triggerSpan: TextSpan; 1068 } 1069 export interface RenameInfoFailure { 1070 canRename: false; 1071 localizedErrorMessage: string; 1072 } 1073 1074 export interface RenameInfoOptions { 1075 readonly allowRenameOfImportPath?: boolean; 1076 } 1077 1078 export interface DocCommentTemplateOptions { 1079 readonly generateReturnInDocTemplate?: boolean; 1080 } 1081 1082 export interface SignatureHelpParameter { 1083 name: string; 1084 documentation: SymbolDisplayPart[]; 1085 displayParts: SymbolDisplayPart[]; 1086 isOptional: boolean; 1087 isRest?: boolean; 1088 } 1089 1090 export interface SelectionRange { 1091 textSpan: TextSpan; 1092 parent?: SelectionRange; 1093 } 1094 1095 /** 1096 * Represents a single signature to show in signature help. 1097 * The id is used for subsequent calls into the language service to ask questions about the 1098 * signature help item in the context of any documents that have been updated. i.e. after 1099 * an edit has happened, while signature help is still active, the host can ask important 1100 * questions like 'what parameter is the user currently contained within?'. 1101 */ 1102 export interface SignatureHelpItem { 1103 isVariadic: boolean; 1104 prefixDisplayParts: SymbolDisplayPart[]; 1105 suffixDisplayParts: SymbolDisplayPart[]; 1106 separatorDisplayParts: SymbolDisplayPart[]; 1107 parameters: SignatureHelpParameter[]; 1108 documentation: SymbolDisplayPart[]; 1109 tags: JSDocTagInfo[]; 1110 } 1111 1112 /** 1113 * Represents a set of signature help items, and the preferred item that should be selected. 1114 */ 1115 export interface SignatureHelpItems { 1116 items: SignatureHelpItem[]; 1117 applicableSpan: TextSpan; 1118 selectedItemIndex: number; 1119 argumentIndex: number; 1120 argumentCount: number; 1121 } 1122 1123 export interface CompletionInfo { 1124 /** Not true for all global completions. This will be true if the enclosing scope matches a few syntax kinds. See `isSnippetScope`. */ 1125 isGlobalCompletion: boolean; 1126 isMemberCompletion: boolean; 1127 /** 1128 * In the absence of `CompletionEntry["replacementSpan"], the editor may choose whether to use 1129 * this span or its default one. If `CompletionEntry["replacementSpan"]` is defined, that span 1130 * must be used to commit that completion entry. 1131 */ 1132 optionalReplacementSpan?: TextSpan; 1133 1134 /** 1135 * true when the current location also allows for a new identifier 1136 */ 1137 isNewIdentifierLocation: boolean; 1138 entries: CompletionEntry[]; 1139 } 1140 1141 // see comments in protocol.ts 1142 export interface CompletionEntry { 1143 name: string; 1144 kind: ScriptElementKind; 1145 kindModifiers?: string; // see ScriptElementKindModifier, comma separated 1146 sortText: string; 1147 insertText?: string; 1148 /** 1149 * An optional span that indicates the text to be replaced by this completion item. 1150 * If present, this span should be used instead of the default one. 1151 * It will be set if the required span differs from the one generated by the default replacement behavior. 1152 */ 1153 replacementSpan?: TextSpan; 1154 hasAction?: true; 1155 source?: string; 1156 isRecommended?: true; 1157 isFromUncheckedFile?: true; 1158 isPackageJsonImport?: true; 1159 jsDoc?: JSDocTagInfo[]; 1160 displayParts?: SymbolDisplayPart[]; 1161 } 1162 1163 export interface CompletionEntryDetails { 1164 name: string; 1165 kind: ScriptElementKind; 1166 kindModifiers: string; // see ScriptElementKindModifier, comma separated 1167 displayParts: SymbolDisplayPart[]; 1168 documentation?: SymbolDisplayPart[]; 1169 tags?: JSDocTagInfo[]; 1170 codeActions?: CodeAction[]; 1171 source?: SymbolDisplayPart[]; 1172 } 1173 1174 export interface OutliningSpan { 1175 /** The span of the document to actually collapse. */ 1176 textSpan: TextSpan; 1177 1178 /** The span of the document to display when the user hovers over the collapsed span. */ 1179 hintSpan: TextSpan; 1180 1181 /** The text to display in the editor for the collapsed region. */ 1182 bannerText: string; 1183 1184 /** 1185 * Whether or not this region should be automatically collapsed when 1186 * the 'Collapse to Definitions' command is invoked. 1187 */ 1188 autoCollapse: boolean; 1189 1190 /** 1191 * Classification of the contents of the span 1192 */ 1193 kind: OutliningSpanKind; 1194 } 1195 1196 export const enum OutliningSpanKind { 1197 /** Single or multi-line comments */ 1198 Comment = "comment", 1199 1200 /** Sections marked by '// #region' and '// #endregion' comments */ 1201 Region = "region", 1202 1203 /** Declarations and expressions */ 1204 Code = "code", 1205 1206 /** Contiguous blocks of import declarations */ 1207 Imports = "imports" 1208 } 1209 1210 export const enum OutputFileType { 1211 JavaScript, 1212 SourceMap, 1213 Declaration 1214 } 1215 1216 export const enum EndOfLineState { 1217 None, 1218 InMultiLineCommentTrivia, 1219 InSingleQuoteStringLiteral, 1220 InDoubleQuoteStringLiteral, 1221 InTemplateHeadOrNoSubstitutionTemplate, 1222 InTemplateMiddleOrTail, 1223 InTemplateSubstitutionPosition, 1224 } 1225 1226 export enum TokenClass { 1227 Punctuation, 1228 Keyword, 1229 Operator, 1230 Comment, 1231 Whitespace, 1232 Identifier, 1233 NumberLiteral, 1234 BigIntLiteral, 1235 StringLiteral, 1236 RegExpLiteral, 1237 } 1238 1239 export interface ClassificationResult { 1240 finalLexState: EndOfLineState; 1241 entries: ClassificationInfo[]; 1242 } 1243 1244 export interface ClassificationInfo { 1245 length: number; 1246 classification: TokenClass; 1247 } 1248 1249 export interface Classifier { 1250 /** 1251 * Gives lexical classifications of tokens on a line without any syntactic context. 1252 * For instance, a token consisting of the text 'string' can be either an identifier 1253 * named 'string' or the keyword 'string', however, because this classifier is not aware, 1254 * it relies on certain heuristics to give acceptable results. For classifications where 1255 * speed trumps accuracy, this function is preferable; however, for true accuracy, the 1256 * syntactic classifier is ideal. In fact, in certain editing scenarios, combining the 1257 * lexical, syntactic, and semantic classifiers may issue the best user experience. 1258 * 1259 * @param text The text of a line to classify. 1260 * @param lexState The state of the lexical classifier at the end of the previous line. 1261 * @param syntacticClassifierAbsent Whether the client is *not* using a syntactic classifier. 1262 * If there is no syntactic classifier (syntacticClassifierAbsent=true), 1263 * certain heuristics may be used in its place; however, if there is a 1264 * syntactic classifier (syntacticClassifierAbsent=false), certain 1265 * classifications which may be incorrectly categorized will be given 1266 * back as Identifiers in order to allow the syntactic classifier to 1267 * subsume the classification. 1268 * @deprecated Use getLexicalClassifications instead. 1269 */ 1270 getClassificationsForLine(text: string, lexState: EndOfLineState, syntacticClassifierAbsent: boolean): ClassificationResult; 1271 getEncodedLexicalClassifications(text: string, endOfLineState: EndOfLineState, syntacticClassifierAbsent: boolean): Classifications; 1272 } 1273 1274 export const enum ScriptElementKind { 1275 unknown = "", 1276 warning = "warning", 1277 1278 /** predefined type (void) or keyword (class) */ 1279 keyword = "keyword", 1280 1281 /** top level script node */ 1282 scriptElement = "script", 1283 1284 /** module foo {} */ 1285 moduleElement = "module", 1286 1287 /** class X {} */ 1288 classElement = "class", 1289 1290 /** var x = class X {} */ 1291 localClassElement = "local class", 1292 1293 /** struct X {} */ 1294 structElement = "struct", 1295 1296 /** interface Y {} */ 1297 interfaceElement = "interface", 1298 1299 /** type T = ... */ 1300 typeElement = "type", 1301 1302 /** enum E */ 1303 enumElement = "enum", 1304 enumMemberElement = "enum member", 1305 1306 /** 1307 * Inside module and script only 1308 * const v = .. 1309 */ 1310 variableElement = "var", 1311 1312 /** Inside function */ 1313 localVariableElement = "local var", 1314 1315 /** 1316 * Inside module and script only 1317 * function f() { } 1318 */ 1319 functionElement = "function", 1320 1321 /** Inside function */ 1322 localFunctionElement = "local function", 1323 1324 /** class X { [public|private]* foo() {} } */ 1325 memberFunctionElement = "method", 1326 1327 /** class X { [public|private]* [get|set] foo:number; } */ 1328 memberGetAccessorElement = "getter", 1329 memberSetAccessorElement = "setter", 1330 1331 /** 1332 * class X { [public|private]* foo:number; } 1333 * interface Y { foo:number; } 1334 */ 1335 memberVariableElement = "property", 1336 1337 /** class X { constructor() { } } */ 1338 constructorImplementationElement = "constructor", 1339 1340 /** interface Y { ():number; } */ 1341 callSignatureElement = "call", 1342 1343 /** interface Y { []:number; } */ 1344 indexSignatureElement = "index", 1345 1346 /** interface Y { new():Y; } */ 1347 constructSignatureElement = "construct", 1348 1349 /** function foo(*Y*: string) */ 1350 parameterElement = "parameter", 1351 1352 typeParameterElement = "type parameter", 1353 1354 primitiveType = "primitive type", 1355 1356 label = "label", 1357 1358 alias = "alias", 1359 1360 constElement = "const", 1361 1362 letElement = "let", 1363 1364 directory = "directory", 1365 1366 externalModuleName = "external module name", 1367 1368 /** 1369 * <JsxTagName attribute1 attribute2={0} /> 1370 */ 1371 jsxAttribute = "JSX attribute", 1372 1373 /** String literal */ 1374 string = "string", 1375 } 1376 1377 export const enum ScriptElementKindModifier { 1378 none = "", 1379 publicMemberModifier = "public", 1380 privateMemberModifier = "private", 1381 protectedMemberModifier = "protected", 1382 exportedModifier = "export", 1383 ambientModifier = "declare", 1384 staticModifier = "static", 1385 abstractModifier = "abstract", 1386 optionalModifier = "optional", 1387 1388 deprecatedModifier = "deprecated", 1389 1390 dtsModifier = ".d.ts", 1391 tsModifier = ".ts", 1392 tsxModifier = ".tsx", 1393 jsModifier = ".js", 1394 jsxModifier = ".jsx", 1395 jsonModifier = ".json", 1396 etsModifier = ".ets", 1397 detsModifier = ".d.ets", 1398 } 1399 1400 export const enum ClassificationTypeNames { 1401 comment = "comment", 1402 identifier = "identifier", 1403 keyword = "keyword", 1404 numericLiteral = "number", 1405 bigintLiteral = "bigint", 1406 operator = "operator", 1407 stringLiteral = "string", 1408 whiteSpace = "whitespace", 1409 text = "text", 1410 1411 punctuation = "punctuation", 1412 1413 className = "class name", 1414 enumName = "enum name", 1415 interfaceName = "interface name", 1416 moduleName = "module name", 1417 typeParameterName = "type parameter name", 1418 typeAliasName = "type alias name", 1419 parameterName = "parameter name", 1420 docCommentTagName = "doc comment tag name", 1421 jsxOpenTagName = "jsx open tag name", 1422 jsxCloseTagName = "jsx close tag name", 1423 jsxSelfClosingTagName = "jsx self closing tag name", 1424 jsxAttribute = "jsx attribute", 1425 jsxText = "jsx text", 1426 jsxAttributeStringLiteralValue = "jsx attribute string literal value", 1427 } 1428 1429 export const enum ClassificationType { 1430 comment = 1, 1431 identifier = 2, 1432 keyword = 3, 1433 numericLiteral = 4, 1434 operator = 5, 1435 stringLiteral = 6, 1436 regularExpressionLiteral = 7, 1437 whiteSpace = 8, 1438 text = 9, 1439 punctuation = 10, 1440 className = 11, 1441 enumName = 12, 1442 interfaceName = 13, 1443 moduleName = 14, 1444 typeParameterName = 15, 1445 typeAliasName = 16, 1446 parameterName = 17, 1447 docCommentTagName = 18, 1448 jsxOpenTagName = 19, 1449 jsxCloseTagName = 20, 1450 jsxSelfClosingTagName = 21, 1451 jsxAttribute = 22, 1452 jsxText = 23, 1453 jsxAttributeStringLiteralValue = 24, 1454 bigintLiteral = 25, 1455 } 1456 1457 /** @internal */ 1458 export interface CodeFixRegistration { 1459 errorCodes: readonly number[]; 1460 getCodeActions(context: CodeFixContext): CodeFixAction[] | undefined; 1461 fixIds?: readonly string[]; 1462 getAllCodeActions?(context: CodeFixAllContext): CombinedCodeActions; 1463 } 1464 1465 /** @internal */ 1466 export interface CodeFixContextBase extends textChanges.TextChangesContext { 1467 sourceFile: SourceFile; 1468 program: Program; 1469 cancellationToken: CancellationToken; 1470 preferences: UserPreferences; 1471 } 1472 1473 /** @internal */ 1474 export interface CodeFixAllContext extends CodeFixContextBase { 1475 fixId: {}; 1476 } 1477 1478 /** @internal */ 1479 export interface CodeFixContext extends CodeFixContextBase { 1480 errorCode: number; 1481 span: TextSpan; 1482 } 1483 1484 /** @internal */ 1485 export interface Refactor { 1486 /** List of action kinds a refactor can provide. 1487 * Used to skip unnecessary calculation when specific refactors are requested. */ 1488 kinds?: string[]; 1489 1490 /** Compute the associated code actions */ 1491 getEditsForAction(context: RefactorContext, actionName: string): RefactorEditInfo | undefined; 1492 1493 /** Compute (quickly) which actions are available here */ 1494 getAvailableActions(context: RefactorContext): readonly ApplicableRefactorInfo[]; 1495 } 1496 1497 /** @internal */ 1498 export interface RefactorContext extends textChanges.TextChangesContext { 1499 file: SourceFile; 1500 startPosition: number; 1501 endPosition?: number; 1502 program: Program; 1503 cancellationToken?: CancellationToken; 1504 preferences: UserPreferences; 1505 triggerReason?: RefactorTriggerReason; 1506 kind?: string; 1507 } 1508} 1509