Skip to content

Commit a48afe0

Browse files
clydinatscott
authored andcommitted
fix(language-service): avoid generating TS syntactic diagnostics for templates (#55091)
Angular's template files are not valid TypeScript. Attempting to get syntactic diagnostics from the underlying TypeScript language service will result in a large amount of false positive errors. Only actual TypeScript files should be analyzed by the underlying TypeScript language service for syntactic errors. PR Close #55091
1 parent d63706e commit a48afe0

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

packages/language-service/src/ts_plugin.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@ export function create(info: ts.server.PluginCreateInfo): NgLanguageService {
2222

2323
const ngLS = new LanguageService(project, tsLS, config);
2424

25+
function getSyntacticDiagnostics(fileName: string): ts.DiagnosticWithLocation[] {
26+
if (!angularOnly && isTypeScriptFile(fileName)) {
27+
return tsLS.getSyntacticDiagnostics(fileName);
28+
}
29+
30+
// Template files do not currently produce separate syntactic diagnostics and
31+
// are instead produced during the semantic diagnostic analysis.
32+
return [];
33+
}
34+
2535
function getSemanticDiagnostics(fileName: string): ts.Diagnostic[] {
2636
const diagnostics: ts.Diagnostic[] = [];
2737
if (!angularOnly && isTypeScriptFile(fileName)) {
@@ -212,6 +222,7 @@ export function create(info: ts.server.PluginCreateInfo): NgLanguageService {
212222

213223
return {
214224
...tsLS,
225+
getSyntacticDiagnostics,
215226
getSemanticDiagnostics,
216227
getTypeDefinitionAtPosition,
217228
getQuickInfoAtPosition,

0 commit comments

Comments
 (0)