UNPKG

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