fix(language-service): Remove getTemplateReferences() from LanguageService API (#33807)
The method `getTemplateReferences()` appears in both the LanguageService interface and LanguageServiceHost interface. It should belong in the latter and not the former, since the former deals with the semantics of the language and not the mechanics. PR Close #33807
This commit is contained in:
parent
7c64b1889f
commit
c365eded5b
|
@ -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[] = [];
|
||||
|
|
|
@ -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)) {
|
||||
|
|
|
@ -394,11 +394,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.
|
||||
*/
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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);
|
||||
|
@ -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(); });
|
||||
|
||||
|
|
|
@ -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';
|
||||
|
@ -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 = `
|
||||
|
@ -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']);
|
||||
});
|
||||
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue