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#56241)

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.

PR Close angular#56241
  • Loading branch information
clydin authored and and-oli committed Sep 27, 2024
1 parent 4e76910 commit 4f7eb3b
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 @@ -39,6 +39,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 @@ -334,6 +343,7 @@ export function create(info: ts.server.PluginCreateInfo): NgLanguageService {
...tsLS,
getSyntacticDiagnostics,
getSemanticDiagnostics,
getSuggestionDiagnostics,
getTypeDefinitionAtPosition,
getQuickInfoAtPosition,
getDefinitionAtPosition,
Expand Down

0 comments on commit 4f7eb3b

Please sign in to comment.