Skip to content

Commit 7ecfd89

Browse files
dylhunnpkozlowski-opensource
authored andcommitted
fix(language-service): The suppress diagnostics option should work for external templates (angular#57873)
Previously, due to a bug, this option only worked for inline templates. PR Close angular#57873
1 parent 6468a2b commit 7ecfd89

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

packages/language-service/src/language_service.ts

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,16 @@ import {ActiveRefactoring, allRefactorings} from './refactorings/refactoring';
5151

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

54+
// Whether the language service should suppress the below for google3.
55+
const enableG3Suppression = false;
56+
57+
// The Copybara config that syncs the language service into g3 will be patched to
58+
// always suppress any diagnostics in this list.
59+
// See `angular2/copy.bara.sky` for more information.
60+
const suppressDiagnosticsInG3: number[] = [
61+
parseInt(`-99${ErrorCode.COMPONENT_RESOURCE_NOT_FOUND}`),
62+
];
63+
5464
export class LanguageService {
5565
private options: CompilerOptions;
5666
readonly compilerFactory: CompilerFactory;
@@ -83,17 +93,12 @@ export class LanguageService {
8393

8494
getSemanticDiagnostics(fileName: string): ts.Diagnostic[] {
8595
return this.withCompilerAndPerfTracing(PerfPhase.LsDiagnostics, (compiler) => {
86-
const diagnostics: ts.Diagnostic[] = [];
96+
let diagnostics: ts.Diagnostic[] = [];
8797
if (isTypeScriptFile(fileName)) {
8898
const program = compiler.getCurrentProgram();
8999
const sourceFile = program.getSourceFile(fileName);
90100
if (sourceFile) {
91101
let ngDiagnostics = compiler.getDiagnosticsForFile(sourceFile, OptimizeFor.SingleFile);
92-
if (this.config.suppressAngularDiagnosticCodes) {
93-
ngDiagnostics = ngDiagnostics.filter(
94-
(diag) => !this.config.suppressAngularDiagnosticCodes!.includes(diag.code),
95-
);
96-
}
97102
// There are several kinds of diagnostics returned by `NgCompiler` for a source file:
98103
//
99104
// 1. Angular-related non-template diagnostics from decorated classes within that
@@ -130,6 +135,14 @@ export class LanguageService {
130135
}
131136
}
132137
}
138+
if (this.config.suppressAngularDiagnosticCodes) {
139+
diagnostics = diagnostics.filter(
140+
(diag) => !this.config.suppressAngularDiagnosticCodes!.includes(diag.code),
141+
);
142+
}
143+
if (enableG3Suppression) {
144+
diagnostics = diagnostics.filter((diag) => !suppressDiagnosticsInG3.includes(diag.code));
145+
}
133146
return diagnostics;
134147
});
135148
}

0 commit comments

Comments
 (0)