Skip to content

Commit

Permalink
fix(language-service): avoid generating TS suggestion diagnostics for…
Browse files Browse the repository at this point in the history
… templates

Angular's template files are not valid TypeScript. Attempting to get suggestion
diagnostics from the underlying TypeScript language service will result in
a large amount of false positives. Only actual TypeScript files should
be analyzed by the underlying TypeScript language service for suggestions.
  • Loading branch information
clydin committed Jun 3, 2024
1 parent 9e21582 commit 921fac8
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions packages/language-service/src/ts_plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ export function create(info: ts.server.PluginCreateInfo): NgLanguageService {
return [];
}

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

// Template files do not currently produce separate suggestion diagnostics
return [];
}

function getSemanticDiagnostics(fileName: string): ts.Diagnostic[] {
const diagnostics: ts.Diagnostic[] = [];
if (!angularOnly && isTypeScriptFile(fileName)) {
Expand Down Expand Up @@ -311,6 +320,7 @@ export function create(info: ts.server.PluginCreateInfo): NgLanguageService {
...tsLS,
getSyntacticDiagnostics,
getSemanticDiagnostics,
getSuggestionDiagnostics,
getTypeDefinitionAtPosition,
getQuickInfoAtPosition,
getDefinitionAtPosition,
Expand Down

0 comments on commit 921fac8

Please sign in to comment.