From 70caeb7ebcd2f0b7052163a5bdf939cba9bbe068 Mon Sep 17 00:00:00 2001 From: Dylan Hunn Date: Thu, 5 Sep 2024 10:16:15 -0700 Subject: [PATCH] refactor(language-service): Allow language service diagnostics to be ignored Add a check to the language service that ignores specified diagnostic codes. This can be patched in g3 as needed, to ignore codes that are not relevant for g3 (or otherwise not compatible). --- packages/language-service/src/language_service.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/language-service/src/language_service.ts b/packages/language-service/src/language_service.ts index 647d2de240d269..45af37cdbf8d0e 100644 --- a/packages/language-service/src/language_service.ts +++ b/packages/language-service/src/language_service.ts @@ -51,6 +51,11 @@ import {ActiveRefactoring, allRefactorings} from './refactorings/refactoring'; type LanguageServiceConfig = Omit; +const ignoredAngularDiagnostics: number[] = [ + // A list of diagnostic codes that are suppressed. + // This is especially useful for diagnostics that should be disabled in g3. +]; + export class LanguageService { private options: CompilerOptions; readonly compilerFactory: CompilerFactory; @@ -88,7 +93,10 @@ export class LanguageService { const program = compiler.getCurrentProgram(); const sourceFile = program.getSourceFile(fileName); if (sourceFile) { - const ngDiagnostics = compiler.getDiagnosticsForFile(sourceFile, OptimizeFor.SingleFile); + let ngDiagnostics = compiler.getDiagnosticsForFile(sourceFile, OptimizeFor.SingleFile); + ngDiagnostics = ngDiagnostics.filter( + (diag) => !ignoredAngularDiagnostics.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