UNPKG

5.69 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.io/license
7 */
8/// <amd-module name="@angular/language-service/src/typescript_host" />
9import { HtmlParser, NgAnalyzedModules, ParseTreeResult, ResourceLoader } from '@angular/compiler';
10import * as tss from 'typescript/lib/tsserverlibrary';
11import { AstResult, Declaration, LanguageServiceHost, TemplateSource } from './types';
12/**
13 * The language service never needs the normalized versions of the metadata. To avoid parsing
14 * the content and resolving references, return an empty file. This also allows normalizing
15 * template that are syntatically incorrect which is required to provide completions in
16 * syntactically incorrect templates.
17 */
18export declare class DummyHtmlParser extends HtmlParser {
19 parse(): ParseTreeResult;
20}
21/**
22 * Avoid loading resources in the language servcie by using a dummy loader.
23 */
24export declare class DummyResourceLoader extends ResourceLoader {
25 get(_url: string): Promise<string>;
26}
27/**
28 * An implementation of a `LanguageServiceHost` for a TypeScript project.
29 *
30 * The `TypeScriptServiceHost` implements the Angular `LanguageServiceHost` using
31 * the TypeScript language services.
32 *
33 * @publicApi
34 */
35export declare class TypeScriptServiceHost implements LanguageServiceHost {
36 readonly tsLsHost: tss.LanguageServiceHost;
37 readonly tsLS: tss.LanguageService;
38 private readonly summaryResolver;
39 private readonly reflectorHost;
40 private readonly staticSymbolResolver;
41 private readonly staticSymbolCache;
42 /**
43 * Key of the `fileToComponent` map must be TS internal normalized path (path
44 * separator must be `/`), value of the map is the StaticSymbol for the
45 * Component class declaration.
46 */
47 private readonly fileToComponent;
48 private readonly collectedErrors;
49 private readonly fileVersions;
50 private readonly urlResolver;
51 private lastProgram;
52 private analyzedModules;
53 constructor(tsLsHost: tss.LanguageServiceHost, tsLS: tss.LanguageService);
54 private _resolver;
55 /**
56 * Return the singleton instance of the MetadataResolver.
57 */
58 private get resolver();
59 /**
60 * Return the singleton instance of the StaticReflector hosted in the
61 * MetadataResolver.
62 */
63 private get reflector();
64 /**
65 * Return all known external templates.
66 */
67 getExternalTemplates(): ts.server.NormalizedPath[];
68 /**
69 * Checks whether the program has changed and returns all analyzed modules.
70 * If program has changed, invalidate all caches and update fileToComponent
71 * and templateReferences.
72 * In addition to returning information about NgModules, this method plays the
73 * same role as 'synchronizeHostData' in tsserver.
74 */
75 getAnalyzedModules(): NgAnalyzedModules;
76 /**
77 * Checks whether the program has changed, and invalidate static symbols in
78 * the source files that have changed.
79 * Returns true if modules are up-to-date, false otherwise.
80 * This should only be called by getAnalyzedModules().
81 */
82 private upToDate;
83 /**
84 * Find all templates in the specified `file`.
85 * @param fileName TS or HTML file
86 */
87 getTemplates(fileName: string): TemplateSource[];
88 /**
89 * Return metadata about all class declarations in the file that are Angular
90 * directives. Potential matches are `@NgModule`, `@Component`, `@Directive`,
91 * `@Pipes`, etc. class declarations.
92 *
93 * @param fileName TS file
94 */
95 getDeclarations(fileName: string): Declaration[];
96 getSourceFile(fileName: string): tss.SourceFile | undefined;
97 get program(): tss.Program;
98 /**
99 * Return the TemplateSource if `node` is a template node.
100 *
101 * For example,
102 *
103 * @Component({
104 * template: '<div></div>' <-- template node
105 * })
106 * class AppComponent {}
107 * ^---- class declaration node
108 *
109 * @param node Potential template node
110 */
111 private getInternalTemplate;
112 /**
113 * Return the external template for `fileName`.
114 * @param fileName HTML file
115 */
116 private getExternalTemplate;
117 private collectError;
118 private getCollectedErrors;
119 /**
120 * Return the parsed template for the template at the specified `position`.
121 * @param fileName TS or HTML file
122 * @param position Position of the template in the TS file, otherwise ignored.
123 */
124 getTemplateAstAtPosition(fileName: string, position: number): AstResult | undefined;
125 /**
126 * Find the NgModule which the directive associated with the `classSymbol`
127 * belongs to, then return its schema and transitive directives and pipes.
128 * @param classSymbol Angular Symbol that defines a directive
129 */
130 private getModuleMetadataForDirective;
131 /**
132 * Parse the `template` and return its AST, if any.
133 * @param template template to be parsed
134 */
135 getTemplateAst(template: TemplateSource): AstResult | undefined;
136 /**
137 * Log the specified `msg` to file at INFO level. If logging is not enabled
138 * this method is a no-op.
139 * @param msg Log message
140 */
141 log(msg: string): void;
142 /**
143 * Log the specified `msg` to file at ERROR level. If logging is not enabled
144 * this method is a no-op.
145 * @param msg error message
146 */
147 error(msg: string): void;
148 /**
149 * Log debugging info to file at INFO level, only if verbose setting is turned
150 * on. Otherwise, this method is a no-op.
151 * @param msg debugging message
152 */
153 debug(msg: string): void;
154}