Skip to content

Commit

Permalink
fix(language-service): The suppress diagnostics option should work fo…
Browse files Browse the repository at this point in the history
…r external templates

Previously, due to a bug, this option only worked for inline templates.
  • Loading branch information
dylhunn committed Sep 23, 2024
1 parent 4231e8f commit 36d7635
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions packages/language-service/src/language_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ import {ActiveRefactoring, allRefactorings} from './refactorings/refactoring';

type LanguageServiceConfig = Omit<PluginConfig, 'angularOnly'>;

// Whether the language service should suppress the below for google3.
const enableG3Suppression = false;

// The Copybara config that syncs the language service into g3 will be patched to
// always suppress any diagnostics in this list.
// See `angular2/copy.bara.sky` for more information.
const suppressDiagnosticsInG3: number[] = [
parseInt(`-99${ErrorCode.COMPONENT_RESOURCE_NOT_FOUND}`),
];

export class LanguageService {
private options: CompilerOptions;
readonly compilerFactory: CompilerFactory;
Expand Down Expand Up @@ -83,17 +93,12 @@ export class LanguageService {

getSemanticDiagnostics(fileName: string): ts.Diagnostic[] {
return this.withCompilerAndPerfTracing(PerfPhase.LsDiagnostics, (compiler) => {
const diagnostics: ts.Diagnostic[] = [];
let diagnostics: ts.Diagnostic[] = [];
if (isTypeScriptFile(fileName)) {
const program = compiler.getCurrentProgram();
const sourceFile = program.getSourceFile(fileName);
if (sourceFile) {
let ngDiagnostics = compiler.getDiagnosticsForFile(sourceFile, OptimizeFor.SingleFile);
if (this.config.suppressAngularDiagnosticCodes) {
ngDiagnostics = ngDiagnostics.filter(
(diag) => !this.config.suppressAngularDiagnosticCodes!.includes(diag.code),
);
}
// There are several kinds of diagnostics returned by `NgCompiler` for a source file:
//
// 1. Angular-related non-template diagnostics from decorated classes within that
Expand Down Expand Up @@ -130,6 +135,14 @@ export class LanguageService {
}
}
}
if (this.config.suppressAngularDiagnosticCodes) {
diagnostics = diagnostics.filter(
(diag) => !this.config.suppressAngularDiagnosticCodes!.includes(diag.code),
);
}
if (enableG3Suppression) {
diagnostics = diagnostics.filter((diag) => !suppressDiagnosticsInG3.includes(diag.code));
}
return diagnostics;
});
}
Expand Down

0 comments on commit 36d7635

Please sign in to comment.