Skip to content

Commit

Permalink
refactor(compiler-cli): move getDiagnosticsForComponent to compiler (
Browse files Browse the repository at this point in the history
…#43134)

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

Refs #42966

PR Close #43134
  • Loading branch information
danieltre23 authored and alxhub committed Aug 25, 2021
1 parent e196311 commit b6ff762
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
9 changes: 9 additions & 0 deletions packages/compiler-cli/src/ngtsc/core/src/compiler.ts
Expand Up @@ -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.
*/
Expand Down
3 changes: 1 addition & 2 deletions packages/language-service/ivy/language_service.ts
Expand Up @@ -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();
Expand Down Expand Up @@ -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));
}
}
}
Expand Down

0 comments on commit b6ff762

Please sign in to comment.