refactor(language-service): Allow language service diagnostics to be ignored (#57675)

Add a check to the language service that ignores specified diagnostic codes. This will be useful in g3.

The codes to ignore are exposed as part of the PluginConfig.

Fixes github.com/angular/vscode-ng-language-service/issues/1243

PR Close #57675
This commit is contained in:
Dylan Hunn 2024-09-05 10:16:15 -07:00 committed by Jessica Janiuk
parent 6f0d05fac0
commit f063a75eae
2 changed files with 11 additions and 1 deletions

View file

@ -41,6 +41,11 @@ export interface PluginConfig {
* If false, disables parsing of `@let` declarations in the compiler.
*/
enableLetSyntax?: false;
/**
* A list of diagnostic codes that should be supressed in the language service.
*/
suppressAngularDiagnosticCodes?: number[];
}
export type GetTcbResponse = {

View file

@ -88,7 +88,12 @@ 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);
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