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