Skip to content

Commit f05e171

Browse files
Keen Yee LiauAndrewKushnir
authored andcommitted
fix(language-service): Remove getExternalFiles() (angular#34260)
This commit removes the `getExternalFiles()` from the tsserver plugin. This API is no longer needed now that we do not intend to support external templates under the plugin mode. Instead, the external files are added to the project only when they are opened by the user. For complete discussion, see angular/vscode-ng-language-service#473 PR closes angular/vscode-ng-language-service#469 PR closes angular/vscode-ng-language-service#473 PR Close angular#34260
1 parent a91ca99 commit f05e171

File tree

6 files changed

+3
-110
lines changed

6 files changed

+3
-110
lines changed

packages/language-service/src/ts_plugin.ts

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -11,50 +11,8 @@ import * as tss from 'typescript/lib/tsserverlibrary';
1111
import {createLanguageService} from './language_service';
1212
import {TypeScriptServiceHost} from './typescript_host';
1313

14-
/**
15-
* A note about importing TypeScript module.
16-
* The TypeScript module is supplied by tsserver at runtime to ensure version
17-
* compatibility. In Angular language service, the rollup output is augmented
18-
* with a "banner" shim that overwrites 'typescript' and
19-
* 'typescript/lib/tsserverlibrary' imports with the value supplied by tsserver.
20-
* This means import of either modules will not be "required", but they'll work
21-
* just like regular imports.
22-
*/
23-
24-
const projectHostMap = new WeakMap<tss.server.Project, TypeScriptServiceHost>();
25-
26-
/**
27-
* Return the external templates discovered through processing all NgModules in
28-
* the specified `project`.
29-
* This function is called in a few situations:
30-
* 1. When a ConfiguredProject is created
31-
* https://github.com/microsoft/TypeScript/blob/c26c44d5fceb04ea14da20b6ed23449df777ff34/src/server/editorServices.ts#L1755
32-
* 2. When updateGraph() is called on a Project
33-
* https://github.com/microsoft/TypeScript/blob/c26c44d5fceb04ea14da20b6ed23449df777ff34/src/server/project.ts#L915
34-
* @param project Most likely a ConfiguredProject
35-
*/
36-
export function getExternalFiles(project: tss.server.Project): string[] {
37-
if (!project.hasRoots()) {
38-
// During project initialization where there is no root files yet we should
39-
// not do any work.
40-
return [];
41-
}
42-
const ngLSHost = projectHostMap.get(project);
43-
if (!ngLSHost) {
44-
// Without an Angular host there is no way to get template references.
45-
return [];
46-
}
47-
const templates = ngLSHost.getTemplateReferences();
48-
const logger = project.projectService.logger;
49-
if (logger.hasLevel(tss.server.LogLevel.verbose)) {
50-
// Log external files to help debugging.
51-
logger.info(`External files in ${project.projectName}: ${JSON.stringify(templates)}`);
52-
}
53-
return templates;
54-
}
55-
5614
export function create(info: tss.server.PluginCreateInfo): tss.LanguageService {
57-
const {project, languageService: tsLS, languageServiceHost: tsLSHost, config} = info;
15+
const {languageService: tsLS, languageServiceHost: tsLSHost, config} = info;
5816
// This plugin could operate under two different modes:
5917
// 1. TS + Angular
6018
// Plugin augments TS language service to provide additional Angular
@@ -67,7 +25,6 @@ export function create(info: tss.server.PluginCreateInfo): tss.LanguageService {
6725
const angularOnly = config ? config.angularOnly === true : false;
6826
const ngLSHost = new TypeScriptServiceHost(tsLSHost, tsLS);
6927
const ngLS = createLanguageService(ngLSHost);
70-
projectHostMap.set(project, ngLSHost);
7128

7229
function getCompletionsAtPosition(
7330
fileName: string, position: number,

packages/language-service/src/types.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,6 @@ export interface LanguageServiceHost {
185185
*/
186186
getAnalyzedModules(): NgAnalyzedModules;
187187

188-
/**
189-
* Return a list all the template files referenced by the project.
190-
*/
191-
getTemplateReferences(): string[];
192-
193188
/**
194189
* Return the AST for both HTML and template for the contextFile.
195190
*/

packages/language-service/src/typescript_host.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {AstResult} from './common';
1515
import {createLanguageService} from './language_service';
1616
import {ReflectorHost} from './reflector_host';
1717
import {ExternalTemplate, InlineTemplate, getClassDeclFromDecoratorProp, getPropertyAssignmentFromValue} from './template';
18-
import {Declaration, DeclarationError, Diagnostic, DiagnosticMessageChain, LanguageService, LanguageServiceHost, Span, TemplateSource} from './types';
18+
import {Declaration, DeclarationError, DiagnosticMessageChain, LanguageService, LanguageServiceHost, Span, TemplateSource} from './types';
1919
import {findTightestNode, getDirectiveClassLike} from './utils';
2020

2121

@@ -65,7 +65,6 @@ export class TypeScriptServiceHost implements LanguageServiceHost {
6565
private readonly fileVersions = new Map<string, string>();
6666

6767
private lastProgram: ts.Program|undefined = undefined;
68-
private templateReferences: string[] = [];
6968
private analyzedModules: NgAnalyzedModules = {
7069
files: [],
7170
ngModuleByPipeOrDirective: new Map(),
@@ -144,11 +143,6 @@ export class TypeScriptServiceHost implements LanguageServiceHost {
144143
return this.resolver.getReflector() as StaticReflector;
145144
}
146145

147-
getTemplateReferences(): string[] {
148-
this.getAnalyzedModules();
149-
return [...this.templateReferences];
150-
}
151-
152146
/**
153147
* Checks whether the program has changed and returns all analyzed modules.
154148
* If program has changed, invalidate all caches and update fileToComponent
@@ -166,7 +160,6 @@ export class TypeScriptServiceHost implements LanguageServiceHost {
166160
}
167161

168162
// Invalidate caches
169-
this.templateReferences = [];
170163
this.fileToComponent.clear();
171164
this.collectedErrors.clear();
172165
this.resolver.clearCache();
@@ -186,7 +179,6 @@ export class TypeScriptServiceHost implements LanguageServiceHost {
186179
this.reflector.componentModuleUrl(directive.reference),
187180
metadata.template.templateUrl);
188181
this.fileToComponent.set(templateName, directive.reference);
189-
this.templateReferences.push(templateName);
190182
}
191183
}
192184
}

packages/language-service/test/BUILD.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ ts_library(
1212
"html_info_spec.ts",
1313
"language_service_spec.ts",
1414
"reflector_host_spec.ts",
15-
"template_references_spec.ts",
1615
"template_spec.ts",
1716
"test_utils.ts",
1817
"ts_plugin_spec.ts",

packages/language-service/test/template_references_spec.ts

Lines changed: 0 additions & 45 deletions
This file was deleted.

packages/language-service/test/ts_plugin_spec.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import * as ts from 'typescript';
1010

11-
import {create, getExternalFiles} from '../src/ts_plugin';
11+
import {create} from '../src/ts_plugin';
1212
import {CompletionKind} from '../src/types';
1313

1414
import {MockTypescriptHost} from './test_utils';
@@ -65,11 +65,6 @@ describe('plugin', () => {
6565
}
6666
});
6767

68-
it('should return external templates as external files', () => {
69-
const externalFiles = getExternalFiles(mockProject);
70-
expect(externalFiles).toEqual(['/app/test.ng']);
71-
});
72-
7368
it('should not report template errors on tour of heroes', () => {
7469
const filesWithTemplates = [
7570
// Ignore all '*-cases.ts' files as they intentionally contain errors.

0 commit comments

Comments
 (0)