diff --git a/packages/language-service/src/ts_plugin.ts b/packages/language-service/src/ts_plugin.ts index 34f416c983..71ac44c8f3 100644 --- a/packages/language-service/src/ts_plugin.ts +++ b/packages/language-service/src/ts_plugin.ts @@ -11,50 +11,8 @@ import * as tss from 'typescript/lib/tsserverlibrary'; import {createLanguageService} from './language_service'; import {TypeScriptServiceHost} from './typescript_host'; -/** - * A note about importing TypeScript module. - * The TypeScript module is supplied by tsserver at runtime to ensure version - * compatibility. In Angular language service, the rollup output is augmented - * with a "banner" shim that overwrites 'typescript' and - * 'typescript/lib/tsserverlibrary' imports with the value supplied by tsserver. - * This means import of either modules will not be "required", but they'll work - * just like regular imports. - */ - -const projectHostMap = new WeakMap(); - -/** - * Return the external templates discovered through processing all NgModules in - * the specified `project`. - * This function is called in a few situations: - * 1. When a ConfiguredProject is created - * https://github.com/microsoft/TypeScript/blob/c26c44d5fceb04ea14da20b6ed23449df777ff34/src/server/editorServices.ts#L1755 - * 2. When updateGraph() is called on a Project - * https://github.com/microsoft/TypeScript/blob/c26c44d5fceb04ea14da20b6ed23449df777ff34/src/server/project.ts#L915 - * @param project Most likely a ConfiguredProject - */ -export function getExternalFiles(project: tss.server.Project): string[] { - if (!project.hasRoots()) { - // During project initialization where there is no root files yet we should - // not do any work. - return []; - } - const ngLSHost = projectHostMap.get(project); - if (!ngLSHost) { - // Without an Angular host there is no way to get template references. - return []; - } - const templates = ngLSHost.getTemplateReferences(); - const logger = project.projectService.logger; - if (logger.hasLevel(tss.server.LogLevel.verbose)) { - // Log external files to help debugging. - logger.info(`External files in ${project.projectName}: ${JSON.stringify(templates)}`); - } - return templates; -} - export function create(info: tss.server.PluginCreateInfo): tss.LanguageService { - const {project, languageService: tsLS, languageServiceHost: tsLSHost, config} = info; + const {languageService: tsLS, languageServiceHost: tsLSHost, config} = info; // This plugin could operate under two different modes: // 1. TS + Angular // Plugin augments TS language service to provide additional Angular @@ -67,7 +25,6 @@ export function create(info: tss.server.PluginCreateInfo): tss.LanguageService { const angularOnly = config ? config.angularOnly === true : false; const ngLSHost = new TypeScriptServiceHost(tsLSHost, tsLS); const ngLS = createLanguageService(ngLSHost); - projectHostMap.set(project, ngLSHost); function getCompletionsAtPosition( fileName: string, position: number, diff --git a/packages/language-service/src/types.ts b/packages/language-service/src/types.ts index 97f7c90cc5..63f3d21ae6 100644 --- a/packages/language-service/src/types.ts +++ b/packages/language-service/src/types.ts @@ -185,11 +185,6 @@ export interface LanguageServiceHost { */ getAnalyzedModules(): NgAnalyzedModules; - /** - * Return a list all the template files referenced by the project. - */ - getTemplateReferences(): string[]; - /** * Return the AST for both HTML and template for the contextFile. */ diff --git a/packages/language-service/src/typescript_host.ts b/packages/language-service/src/typescript_host.ts index 327fb1d082..00698bb098 100644 --- a/packages/language-service/src/typescript_host.ts +++ b/packages/language-service/src/typescript_host.ts @@ -15,7 +15,7 @@ import {AstResult} from './common'; import {createLanguageService} from './language_service'; import {ReflectorHost} from './reflector_host'; import {ExternalTemplate, InlineTemplate, getClassDeclFromDecoratorProp, getPropertyAssignmentFromValue} from './template'; -import {Declaration, DeclarationError, Diagnostic, DiagnosticMessageChain, LanguageService, LanguageServiceHost, Span, TemplateSource} from './types'; +import {Declaration, DeclarationError, DiagnosticMessageChain, LanguageService, LanguageServiceHost, Span, TemplateSource} from './types'; import {findTightestNode, getDirectiveClassLike} from './utils'; @@ -65,7 +65,6 @@ export class TypeScriptServiceHost implements LanguageServiceHost { private readonly fileVersions = new Map(); private lastProgram: ts.Program|undefined = undefined; - private templateReferences: string[] = []; private analyzedModules: NgAnalyzedModules = { files: [], ngModuleByPipeOrDirective: new Map(), @@ -144,11 +143,6 @@ export class TypeScriptServiceHost implements LanguageServiceHost { return this.resolver.getReflector() as StaticReflector; } - getTemplateReferences(): string[] { - this.getAnalyzedModules(); - return [...this.templateReferences]; - } - /** * Checks whether the program has changed and returns all analyzed modules. * If program has changed, invalidate all caches and update fileToComponent @@ -166,7 +160,6 @@ export class TypeScriptServiceHost implements LanguageServiceHost { } // Invalidate caches - this.templateReferences = []; this.fileToComponent.clear(); this.collectedErrors.clear(); this.resolver.clearCache(); @@ -186,7 +179,6 @@ export class TypeScriptServiceHost implements LanguageServiceHost { this.reflector.componentModuleUrl(directive.reference), metadata.template.templateUrl); this.fileToComponent.set(templateName, directive.reference); - this.templateReferences.push(templateName); } } } diff --git a/packages/language-service/test/BUILD.bazel b/packages/language-service/test/BUILD.bazel index a9f4331c43..f23e62bf27 100644 --- a/packages/language-service/test/BUILD.bazel +++ b/packages/language-service/test/BUILD.bazel @@ -12,7 +12,6 @@ ts_library( "html_info_spec.ts", "language_service_spec.ts", "reflector_host_spec.ts", - "template_references_spec.ts", "template_spec.ts", "test_utils.ts", "ts_plugin_spec.ts", diff --git a/packages/language-service/test/template_references_spec.ts b/packages/language-service/test/template_references_spec.ts deleted file mode 100644 index 6e49ca44b4..0000000000 --- a/packages/language-service/test/template_references_spec.ts +++ /dev/null @@ -1,45 +0,0 @@ -/** - * @license - * Copyright Google Inc. All Rights Reserved. - * - * Use of this source code is governed by an MIT-style license that can be - * found in the LICENSE file at https://angular.io/license - */ - -import * as ts from 'typescript'; - -import {TypeScriptServiceHost} from '../src/typescript_host'; - -import {MockTypescriptHost} from './test_utils'; - -describe('references', () => { - const mockHost = new MockTypescriptHost(['/app/main.ts']); - const service = ts.createLanguageService(mockHost); - const ngHost = new TypeScriptServiceHost(mockHost, service); - - beforeEach(() => { mockHost.reset(); }); - - it('should be able to determine that test.ng is a template reference', () => { - const templates = ngHost.getTemplateReferences(); - expect(templates).toEqual(['/app/test.ng']); - }); - - it('should be able to get template references for an invalid project', () => { - const moduleCode = ` - import {NgModule} from '@angular/core'; - import {NewClass} from './test.component'; - - @NgModule({declarations: [NewClass]}) export class TestModule {}`; - const classCode = ` - export class NewClass {} - - @Component({}) - export class SomeComponent {} - `; - mockHost.addScript('/app/test.module.ts', moduleCode); - mockHost.addScript('/app/test.component.ts', classCode); - const templates = ngHost.getTemplateReferences(); - expect(templates).toEqual(['/app/test.ng']); - }); - -}); diff --git a/packages/language-service/test/ts_plugin_spec.ts b/packages/language-service/test/ts_plugin_spec.ts index dbd068940e..37c373d398 100644 --- a/packages/language-service/test/ts_plugin_spec.ts +++ b/packages/language-service/test/ts_plugin_spec.ts @@ -8,7 +8,7 @@ import * as ts from 'typescript'; -import {create, getExternalFiles} from '../src/ts_plugin'; +import {create} from '../src/ts_plugin'; import {CompletionKind} from '../src/types'; import {MockTypescriptHost} from './test_utils'; @@ -65,11 +65,6 @@ describe('plugin', () => { } }); - it('should return external templates as external files', () => { - const externalFiles = getExternalFiles(mockProject); - expect(externalFiles).toEqual(['/app/test.ng']); - }); - it('should not report template errors on tour of heroes', () => { const filesWithTemplates = [ // Ignore all '*-cases.ts' files as they intentionally contain errors.