Skip to content

Commit

Permalink
fix(language-service): avoid generating TS syntactic diagnostics for …
Browse files Browse the repository at this point in the history
…templates (angular#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 angular#55091
  • Loading branch information
clydin authored and ilirbeqirii committed Apr 6, 2024
1 parent 2b0f394 commit 34abe81
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/language-service/src/ts_plugin.ts
Expand Up @@ -22,6 +22,16 @@ export function create(info: ts.server.PluginCreateInfo): NgLanguageService {

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

function getSyntacticDiagnostics(fileName: string): ts.DiagnosticWithLocation[] {
if (!angularOnly && isTypeScriptFile(fileName)) {
return tsLS.getSyntacticDiagnostics(fileName);
}

// Template files do not currently produce separate syntactic diagnostics and
// are instead produced during the semantic diagnostic analysis.
return [];
}

function getSemanticDiagnostics(fileName: string): ts.Diagnostic[] {
const diagnostics: ts.Diagnostic[] = [];
if (!angularOnly && isTypeScriptFile(fileName)) {
Expand Down Expand Up @@ -212,6 +222,7 @@ export function create(info: ts.server.PluginCreateInfo): NgLanguageService {

return {
...tsLS,
getSyntacticDiagnostics,
getSemanticDiagnostics,
getTypeDefinitionAtPosition,
getQuickInfoAtPosition,
Expand Down

0 comments on commit 34abe81

Please sign in to comment.