UNPKG

3.56 kBTypeScriptView Raw
1/**
2 * @license
3 * Copyright Google LLC All Rights Reserved.
4 *
5 * Use of this source code is governed by an MIT-style license that can be
6 * found in the LICENSE file at https://angular.dev/license
7 */
8/**
9 * @module
10 * @description
11 * Entry point for all public APIs of the language service package.
12 */
13import ts from 'typescript';
14export interface PluginConfig {
15 /**
16 * If true, return only Angular results. Otherwise, return Angular + TypeScript
17 * results.
18 */
19 angularOnly: boolean;
20 /**
21 * If true, enable `strictTemplates` in Angular compiler options regardless
22 * of its value in tsconfig.json.
23 */
24 forceStrictTemplates?: true;
25 /**
26 * If false, disables parsing control flow blocks in the compiler. Should be used only when older
27 * versions of Angular that do not support blocks (pre-v17) used with the language service.
28 */
29 enableBlockSyntax?: false;
30 /**
31 * Version of `@angular/core` that was detected in the user's workspace.
32 */
33 angularCoreVersion?: string;
34 /**
35 * If false, disables parsing of `@let` declarations in the compiler.
36 */
37 enableLetSyntax?: false;
38 /**
39 * A list of diagnostic codes that should be supressed in the language service.
40 */
41 suppressAngularDiagnosticCodes?: number[];
42}
43export type GetTcbResponse = {
44 /**
45 * The filename of the SourceFile this typecheck block belongs to.
46 * The filename is entirely opaque and unstable, useful only for debugging
47 * purposes.
48 */
49 fileName: string;
50 /** The content of the SourceFile this typecheck block belongs to. */
51 content: string;
52 /**
53 * Spans over node(s) in the typecheck block corresponding to the
54 * TS code generated for template node under the current cursor position.
55 *
56 * When the cursor position is over a source for which there is no generated
57 * code, `selections` is empty.
58 */
59 selections: ts.TextSpan[];
60};
61export type GetComponentLocationsForTemplateResponse = ts.DocumentSpan[];
62export type GetTemplateLocationForComponentResponse = ts.DocumentSpan | undefined;
63/**
64 * Function that can be invoked to show progress when computing
65 * refactoring edits.
66 *
67 * Useful for refactorings which take a long time to compute edits for.
68 */
69export type ApplyRefactoringProgressFn = (percentage: number, updateMessage: string) => void;
70/** Interface describing the result for computing edits of a refactoring. */
71export interface ApplyRefactoringResult extends Omit<ts.RefactorEditInfo, 'notApplicableReason'> {
72 errorMessage?: string;
73 warningMessage?: string;
74}
75/**
76 * `NgLanguageService` describes an instance of an Angular language service,
77 * whose API surface is a strict superset of TypeScript's language service.
78 */
79export interface NgLanguageService extends ts.LanguageService {
80 getTcb(fileName: string, position: number): GetTcbResponse | undefined;
81 getComponentLocationsForTemplate(fileName: string): GetComponentLocationsForTemplateResponse;
82 getTemplateLocationForComponent(fileName: string, position: number): GetTemplateLocationForComponentResponse;
83 getTypescriptLanguageService(): ts.LanguageService;
84 applyRefactoring(fileName: string, positionOrRange: number | ts.TextRange, refactorName: string, reportProgress: ApplyRefactoringProgressFn): Promise<ApplyRefactoringResult | undefined>;
85 hasCodeFixesForErrorCode(errorCode: number): boolean;
86}
87export declare function isNgLanguageService(ls: ts.LanguageService | NgLanguageService): ls is NgLanguageService;