Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(language-service): Remove getTemplateReferences() from LanguageService API #33807

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions packages/language-service/src/language_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@ export function createLanguageService(host: TypeScriptServiceHost): LanguageServ
class LanguageServiceImpl implements LanguageService {
constructor(private readonly host: TypeScriptServiceHost) {}

getTemplateReferences(): string[] {
this.host.getAnalyzedModules(); // same role as 'synchronizeHostData'
return this.host.getTemplateReferences();
}

getDiagnostics(fileName: string): tss.Diagnostic[] {
const analyzedModules = this.host.getAnalyzedModules(); // same role as 'synchronizeHostData'
const results: Diagnostic[] = [];
Expand Down
1 change: 0 additions & 1 deletion packages/language-service/src/ts_plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ export function getExternalFiles(project: tss.server.Project): string[] {
// Without an Angular host there is no way to get template references.
return [];
}
ngLSHost.getAnalyzedModules();
const templates = ngLSHost.getTemplateReferences();
const logger = project.projectService.logger;
if (logger.hasLevel(tss.server.LogLevel.verbose)) {
Expand Down
5 changes: 0 additions & 5 deletions packages/language-service/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -393,11 +393,6 @@ export interface Hover {
* @publicApi
*/
export interface LanguageService {
/**
* Returns a list of all the external templates referenced by the project.
*/
getTemplateReferences(): string[];

/**
* Returns a list of all error for all templates in the given file.
*/
Expand Down
5 changes: 4 additions & 1 deletion packages/language-service/src/typescript_host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,10 @@ export class TypeScriptServiceHost implements LanguageServiceHost {
return this.resolver.getReflector() as StaticReflector;
}

getTemplateReferences(): string[] { return [...this.templateReferences]; }
getTemplateReferences(): string[] {
this.getAnalyzedModules();
return [...this.templateReferences];
}

/**
* Checks whether the program has changed and returns all analyzed modules.
Expand Down
4 changes: 1 addition & 3 deletions packages/language-service/test/language_service_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {TypeScriptServiceHost} from '../src/typescript_host';
import {MockTypescriptHost} from './test_utils';

describe('service without angular', () => {
const mockHost = new MockTypescriptHost(['/app/main.ts', '/app/parsing-cases.ts']);
const mockHost = new MockTypescriptHost(['/app/main.ts']);
const service = ts.createLanguageService(mockHost);
const ngHost = new TypeScriptServiceHost(mockHost, service);
const ngService = createLanguageService(ngHost);
Expand All @@ -23,8 +23,6 @@ describe('service without angular', () => {

beforeEach(() => { mockHost.reset(); });

it('should not crash a get template references',
() => { expect(() => ngService.getTemplateReferences()).not.toThrow(); });
it('should not crash a get diagnostics',
() => { expect(() => ngService.getDiagnostics(fileName)).not.toThrow(); });

Expand Down
15 changes: 6 additions & 9 deletions packages/language-service/test/template_references_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

import * as ts from 'typescript';

import {createLanguageService} from '../src/language_service';
import {LanguageService} from '../src/types';
import {TypeScriptServiceHost} from '../src/typescript_host';

import {MockTypescriptHost} from './test_utils';
Expand All @@ -18,15 +16,13 @@ describe('references', () => {
const mockHost = new MockTypescriptHost(['/app/main.ts']);
const service = ts.createLanguageService(mockHost);
const ngHost = new TypeScriptServiceHost(mockHost, service);
const ngService = createLanguageService(ngHost);

beforeEach(() => { mockHost.reset(); });

it('should be able to get template references',
() => { expect(() => ngService.getTemplateReferences()).not.toThrow(); });

it('should be able to determine that test.ng is a template reference',
() => { expect(ngService.getTemplateReferences()).toContain('/app/test.ng'); });
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 = `
Expand All @@ -42,7 +38,8 @@ describe('references', () => {
`;
mockHost.addScript('/app/test.module.ts', moduleCode);
mockHost.addScript('/app/test.component.ts', classCode);
expect(() => { ngService.getTemplateReferences(); }).not.toThrow();
const templates = ngHost.getTemplateReferences();
expect(templates).toEqual(['/app/test.ng']);
});

});