refactor(compiler-cli): move getDiagnosticsForComponent to compiler (#43134)

Change the language service to call `getDiagnosticsForComponent` from
the compiler instead of the `TemplateTypeChecker`.

Refs #42966

PR Close #43134
This commit is contained in:
Daniel Trevino 2021-08-23 21:21:37 +00:00 committed by Alex Rickabaugh
parent 6af6de7328
commit 68bb13ea0f
2 changed files with 10 additions and 2 deletions

View file

@ -459,6 +459,15 @@ export class NgCompiler {
return this.addMessageTextDetails(diagnostics);
}
/**
* Get all `ts.Diagnostic`s currently available that pertain to the given component.
*/
getDiagnosticsForComponent(component: ts.ClassDeclaration): ts.Diagnostic[] {
const compilation = this.ensureAnalyzed();
const ttc = compilation.templateTypeChecker;
return this.addMessageTextDetails(ttc.getDiagnosticsForComponent(component));
}
/**
* Add Angular.io error guide links to diagnostics for this compilation.
*/

View file

@ -68,7 +68,6 @@ export class LanguageService {
getSemanticDiagnostics(fileName: string): ts.Diagnostic[] {
return this.withCompilerAndPerfTracing(PerfPhase.LsDiagnostics, (compiler) => {
const ttc = compiler.getTemplateTypeChecker();
const diagnostics: ts.Diagnostic[] = [];
if (isTypeScriptFile(fileName)) {
const program = compiler.getCurrentProgram();
@ -104,7 +103,7 @@ export class LanguageService {
const components = compiler.getComponentsWithTemplateFile(fileName);
for (const component of components) {
if (ts.isClassDeclaration(component)) {
diagnostics.push(...ttc.getDiagnosticsForComponent(component));
diagnostics.push(...compiler.getDiagnosticsForComponent(component));
}
}
}