From 4f7eb3ba4e57a737266023030968b933f456df51 Mon Sep 17 00:00:00 2001 From: Charles Lyding <19598772+clydin@users.noreply.github.com> Date: Mon, 3 Jun 2024 12:11:18 -0400 Subject: [PATCH] fix(language-service): avoid generating TS suggestion diagnostics for templates (#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 #56241 --- packages/language-service/src/ts_plugin.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/packages/language-service/src/ts_plugin.ts b/packages/language-service/src/ts_plugin.ts index c8b06555c5575d..a38e88b58150ab 100644 --- a/packages/language-service/src/ts_plugin.ts +++ b/packages/language-service/src/ts_plugin.ts @@ -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)) { @@ -334,6 +343,7 @@ export function create(info: ts.server.PluginCreateInfo): NgLanguageService { ...tsLS, getSyntacticDiagnostics, getSemanticDiagnostics, + getSuggestionDiagnostics, getTypeDefinitionAtPosition, getQuickInfoAtPosition, getDefinitionAtPosition,