2021-01-28 14:43:37 -06:00
|
|
|
/**
|
|
|
|
|
* @license
|
|
|
|
|
* Copyright Google LLC All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
2024-09-20 09:23:15 -06:00
|
|
|
* found in the LICENSE file at https://angular.dev/license
|
2021-01-28 14:43:37 -06:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @module
|
|
|
|
|
* @description
|
|
|
|
|
* Entry point for all public APIs of the language service package.
|
|
|
|
|
*/
|
|
|
|
|
|
2021-09-25 15:10:26 +02:00
|
|
|
import ts from 'typescript';
|
2021-01-28 14:43:37 -06:00
|
|
|
|
2021-03-02 15:46:11 -08:00
|
|
|
export interface PluginConfig {
|
2021-02-23 10:51:23 -08:00
|
|
|
/**
|
|
|
|
|
* If true, return only Angular results. Otherwise, return Angular + TypeScript
|
|
|
|
|
* results.
|
|
|
|
|
*/
|
|
|
|
|
angularOnly: boolean;
|
2021-03-02 15:46:11 -08:00
|
|
|
/**
|
|
|
|
|
* If true, enable `strictTemplates` in Angular compiler options regardless
|
|
|
|
|
* of its value in tsconfig.json.
|
|
|
|
|
*/
|
|
|
|
|
forceStrictTemplates?: true;
|
2023-11-08 09:33:53 -08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* If false, disables parsing control flow blocks in the compiler. Should be used only when older
|
|
|
|
|
* versions of Angular that do not support blocks (pre-v17) used with the language service.
|
|
|
|
|
*/
|
|
|
|
|
enableBlockSyntax?: false;
|
2024-02-13 20:33:27 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Version of `@angular/core` that was detected in the user's workspace.
|
|
|
|
|
*/
|
|
|
|
|
angularCoreVersion?: string;
|
2024-06-05 09:07:40 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* If false, disables parsing of `@let` declarations in the compiler.
|
|
|
|
|
*/
|
2024-06-26 18:30:56 +02:00
|
|
|
enableLetSyntax?: false;
|
2024-09-05 10:16:15 -07:00
|
|
|
|
2025-04-23 11:29:21 +02:00
|
|
|
/**
|
|
|
|
|
* Whether selectorless is enabled.
|
|
|
|
|
*/
|
|
|
|
|
enableSelectorless?: true;
|
|
|
|
|
|
2024-09-05 10:16:15 -07:00
|
|
|
/**
|
|
|
|
|
* A list of diagnostic codes that should be supressed in the language service.
|
|
|
|
|
*/
|
|
|
|
|
suppressAngularDiagnosticCodes?: number[];
|
2021-02-23 10:51:23 -08:00
|
|
|
}
|
|
|
|
|
|
2021-01-28 14:43:37 -06:00
|
|
|
export type GetTcbResponse = {
|
|
|
|
|
/**
|
|
|
|
|
* The filename of the SourceFile this typecheck block belongs to.
|
|
|
|
|
* The filename is entirely opaque and unstable, useful only for debugging
|
|
|
|
|
* purposes.
|
|
|
|
|
*/
|
|
|
|
|
fileName: string;
|
|
|
|
|
/** The content of the SourceFile this typecheck block belongs to. */
|
|
|
|
|
content: string;
|
|
|
|
|
/**
|
|
|
|
|
* Spans over node(s) in the typecheck block corresponding to the
|
|
|
|
|
* TS code generated for template node under the current cursor position.
|
|
|
|
|
*
|
|
|
|
|
* When the cursor position is over a source for which there is no generated
|
|
|
|
|
* code, `selections` is empty.
|
|
|
|
|
*/
|
|
|
|
|
selections: ts.TextSpan[];
|
2021-02-22 14:13:43 -08:00
|
|
|
};
|
2021-01-28 14:43:37 -06:00
|
|
|
|
2021-01-28 10:31:04 -08:00
|
|
|
export type GetComponentLocationsForTemplateResponse = ts.DocumentSpan[];
|
2021-08-19 17:42:53 -07:00
|
|
|
export type GetTemplateLocationForComponentResponse = ts.DocumentSpan | undefined;
|
2021-01-28 10:31:04 -08:00
|
|
|
|
2024-07-08 15:10:01 +00:00
|
|
|
/**
|
|
|
|
|
* Function that can be invoked to show progress when computing
|
|
|
|
|
* refactoring edits.
|
|
|
|
|
*
|
|
|
|
|
* Useful for refactorings which take a long time to compute edits for.
|
|
|
|
|
*/
|
|
|
|
|
export type ApplyRefactoringProgressFn = (percentage: number, updateMessage: string) => void;
|
|
|
|
|
|
2024-09-26 13:13:58 +00:00
|
|
|
/** Interface describing the result for computing edits of a refactoring. */
|
|
|
|
|
export interface ApplyRefactoringResult extends Omit<ts.RefactorEditInfo, 'notApplicableReason'> {
|
|
|
|
|
errorMessage?: string;
|
|
|
|
|
warningMessage?: string;
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-28 14:43:37 -06:00
|
|
|
/**
|
|
|
|
|
* `NgLanguageService` describes an instance of an Angular language service,
|
|
|
|
|
* whose API surface is a strict superset of TypeScript's language service.
|
|
|
|
|
*/
|
|
|
|
|
export interface NgLanguageService extends ts.LanguageService {
|
2021-02-22 14:13:43 -08:00
|
|
|
getTcb(fileName: string, position: number): GetTcbResponse | undefined;
|
2021-01-28 10:31:04 -08:00
|
|
|
getComponentLocationsForTemplate(fileName: string): GetComponentLocationsForTemplateResponse;
|
2021-08-19 17:42:53 -07:00
|
|
|
getTemplateLocationForComponent(
|
|
|
|
|
fileName: string,
|
|
|
|
|
position: number,
|
|
|
|
|
): GetTemplateLocationForComponentResponse;
|
2023-09-26 10:31:27 -07:00
|
|
|
getTypescriptLanguageService(): ts.LanguageService;
|
2024-07-08 15:10:01 +00:00
|
|
|
|
|
|
|
|
applyRefactoring(
|
|
|
|
|
fileName: string,
|
|
|
|
|
positionOrRange: number | ts.TextRange,
|
|
|
|
|
refactorName: string,
|
|
|
|
|
reportProgress: ApplyRefactoringProgressFn,
|
2024-09-26 13:13:58 +00:00
|
|
|
): Promise<ApplyRefactoringResult | undefined>;
|
2024-07-16 12:17:57 +00:00
|
|
|
|
|
|
|
|
hasCodeFixesForErrorCode(errorCode: number): boolean;
|
2021-01-28 14:43:37 -06:00
|
|
|
}
|
2021-02-22 14:14:31 -08:00
|
|
|
|
|
|
|
|
export function isNgLanguageService(
|
|
|
|
|
ls: ts.LanguageService | NgLanguageService,
|
|
|
|
|
): ls is NgLanguageService {
|
|
|
|
|
return 'getTcb' in ls;
|
|
|
|
|
}
|