Skip to content

Commit 7c13306

Browse files
dylhunnatscott
authored andcommitted
feat(language-service): Allow specific diagnostics to be suppressed
Allow the language service plugin to pass diagnostic codes that should be ignored via the PluginConfig. This change corresponds to PR angular/angular#57675. Fixes #1243
1 parent 9d27669 commit 7c13306

File tree

9 files changed

+52
-16
lines changed

9 files changed

+52
-16
lines changed

.aspect/rules/external_repository_action_cache/npm_translate_lock_LTE4Nzc1MDcwNjU=

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Input hashes for repository rule npm_translate_lock(name = "npm", pnpm_lock = "//:pnpm-lock.yaml").
33
# This file should be checked into version control along with the pnpm-lock.yaml file.
44
.npmrc=974837034
5-
pnpm-lock.yaml=1398347878
6-
yarn.lock=-1005893296
7-
package.json=-657448584
5+
pnpm-lock.yaml=917719234
6+
yarn.lock=-619082575
7+
package.json=-1482224139
88
pnpm-workspace.yaml=1711114604

client/src/client.ts

+6
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,12 @@ export class AngularLanguageClient implements vscode.Disposable {
355355
args.push('--forceStrictTemplates');
356356
}
357357

358+
const suppressAngularDiagnosticCodes =
359+
config.get<string>('angular.suppressAngularDiagnosticCodes');
360+
if (suppressAngularDiagnosticCodes) {
361+
args.push('--suppressAngularDiagnosticCodes', suppressAngularDiagnosticCodes);
362+
}
363+
358364
const tsdk = config.get('typescript.tsdk', '');
359365
if (tsdk.trim().length > 0) {
360366
args.push('--tsdk', tsdk);

package.json

+18-4
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,11 @@
135135
"type": "boolean",
136136
"default": false,
137137
"markdownDescription": "Enabling this option will force the language service to use [strictTemplates](https://angular.io/guide/angular-compiler-options#stricttemplates) and ignore the user settings in the `tsconfig.json`."
138+
},
139+
"angular.suppressAngularDiagnosticCodes": {
140+
"type": "string",
141+
"default": "",
142+
"markdownDescription": "A comma-separated list of error codes in templates whose diagnostics should be ignored."
138143
}
139144
}
140145
},
@@ -164,7 +169,10 @@
164169
{
165170
"path": "./syntaxes/template.json",
166171
"scopeName": "template.ng",
167-
"injectTo": ["text.html.derivative", "source.ts"],
172+
"injectTo": [
173+
"text.html.derivative",
174+
"source.ts"
175+
],
168176
"embeddedLanguages": {
169177
"text.html": "html",
170178
"source.css": "css",
@@ -174,7 +182,10 @@
174182
{
175183
"path": "./syntaxes/template-blocks.json",
176184
"scopeName": "template.blocks.ng",
177-
"injectTo": ["text.html.derivative", "source.ts"],
185+
"injectTo": [
186+
"text.html.derivative",
187+
"source.ts"
188+
],
178189
"embeddedLanguages": {
179190
"text.html": "html",
180191
"control.block.expression.ng": "javascript",
@@ -184,7 +195,10 @@
184195
{
185196
"path": "./syntaxes/let-declaration.json",
186197
"scopeName": "template.let.ng",
187-
"injectTo": ["text.html.derivative", "source.ts"]
198+
"injectTo": [
199+
"text.html.derivative",
200+
"source.ts"
201+
]
188202
},
189203
{
190204
"path": "./syntaxes/template-tag.json",
@@ -231,7 +245,7 @@
231245
"test:legacy-syntaxes": "yarn compile:syntaxes-test && yarn build:syntaxes && jasmine dist/syntaxes/test/driver.js"
232246
},
233247
"dependencies": {
234-
"@angular/language-service": "~19.0.0-next.3",
248+
"@angular/language-service": "~19.0.0-next.4",
235249
"typescript": "5.6.1-rc",
236250
"vscode-html-languageservice": "^4.2.5",
237251
"vscode-jsonrpc": "6.0.0",

pnpm-lock.yaml

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"ngserver": "./bin/ngserver"
1616
},
1717
"dependencies": {
18-
"@angular/language-service": "19.0.0-next.3",
18+
"@angular/language-service": "19.0.0-next.4",
1919
"vscode-html-languageservice": "^4.2.5",
2020
"vscode-jsonrpc": "6.0.0",
2121
"vscode-languageserver": "7.0.0",

server/src/cmdline_utils.ts

+3
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ interface CommandLineOptions {
4040
disableBlockSyntax: boolean;
4141
disableLetSyntax: boolean;
4242
angularCoreVersion?: string;
43+
suppressAngularDiagnosticCodes?: string;
4344
}
4445

4546
export function parseCommandLine(argv: string[]): CommandLineOptions {
@@ -58,6 +59,7 @@ export function parseCommandLine(argv: string[]): CommandLineOptions {
5859
disableBlockSyntax: hasArgument(argv, '--disableBlockSyntax'),
5960
disableLetSyntax: hasArgument(argv, '--disableLetSyntax'),
6061
angularCoreVersion: findArgument(argv, '--angularCoreVersion'),
62+
suppressAngularDiagnosticCodes: findArgument(argv, '--suppressAngularDiagnosticCodes'),
6163
};
6264
}
6365

@@ -76,6 +78,7 @@ export function generateHelpMessage(argv: string[]) {
7678
--includeAutomaticOptionalChainCompletions: Shows completions on potentially undefined values that insert an optional chain call. Requires TS 3.7+ and strict null checks to be enabled.
7779
--includeCompletionsWithSnippetText: Enables snippet completions from Angular language server;
7880
--forceStrictTemplates: Forces the language service to use strictTemplates and ignore the user settings in the 'tsconfig.json'.
81+
--suppressAngularDiagnosticCodes: A comma-separated list of error codes in templates whose diagnostics should be ignored.
7982
8083
Additional options supported by vscode-languageserver:
8184
--clientProcessId=<number>: Automatically kills the server if the client process dies.

server/src/server.ts

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ function main() {
5151
disableBlockSyntax: options.disableBlockSyntax,
5252
disableLetSyntax: options.disableLetSyntax,
5353
angularCoreVersion: options.angularCoreVersion ?? null,
54+
suppressAngularDiagnosticCodes: options.suppressAngularDiagnosticCodes ?? null,
5455
});
5556

5657
// Log initialization info

server/src/session.ts

+12
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export interface SessionOptions {
3636
disableBlockSyntax: boolean;
3737
disableLetSyntax: boolean;
3838
angularCoreVersion: string|null;
39+
suppressAngularDiagnosticCodes: string|null;
3940
}
4041

4142
enum LanguageId {
@@ -52,6 +53,11 @@ const defaultPreferences: ts.UserPreferences = {};
5253

5354
const htmlLS = getHTMLLanguageService();
5455

56+
const alwaysSuppressDiagnostics: number[] = [
57+
// Diagnostics codes whose errors should always be suppressed, regardless of the options
58+
// configuration.
59+
];
60+
5561
/**
5662
* Session is a wrapper around lsp.IConnection, with all the necessary protocol
5763
* handlers installed for Angular language service.
@@ -165,6 +171,12 @@ export class Session {
165171
if (options.angularCoreVersion !== null) {
166172
pluginConfig.angularCoreVersion = options.angularCoreVersion;
167173
}
174+
if (options.suppressAngularDiagnosticCodes !== null) {
175+
const parsedDiagnosticCodes =
176+
options.suppressAngularDiagnosticCodes.split(',').map(c => parseInt(c));
177+
pluginConfig.suppressAngularDiagnosticCodes =
178+
[...alwaysSuppressDiagnostics, ...parsedDiagnosticCodes];
179+
}
168180
projSvc.configurePlugin({
169181
pluginName: options.ngPlugin,
170182
configuration: pluginConfig,

yarn.lock

+4-4
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,10 @@
173173
uuid "^8.3.2"
174174
yargs "^17.0.0"
175175

176-
"@angular/language-service@~19.0.0-next.3":
177-
version "19.0.0-next.3"
178-
resolved "https://registry.yarnpkg.com/@angular/language-service/-/language-service-19.0.0-next.3.tgz#d58460785969470ae0108d59c7c9d4030551b162"
179-
integrity sha512-9xu7dn6nEj9msJTS9TK9CJbmn4D26EMk3ONlVwqmzeNe/m98V5WKcYI/ouAchR9ZC5HKU6SOppPjb3RjK0HAEA==
176+
"@angular/language-service@~19.0.0-next.4":
177+
version "19.0.0-next.4"
178+
resolved "https://registry.yarnpkg.com/@angular/language-service/-/language-service-19.0.0-next.4.tgz#137b256262d50ef4d023254ab72d7a00e4bfde27"
179+
integrity sha512-LPNvgTeOe4icJSy2ryYdkqekxYmqPtjqbbPyo5HPH8jH7fcSDhXHKqMk5U/ho1quEvrBosGXE+sx+MO0u2mQqg==
180180

181181
"@assemblyscript/loader@^0.10.1":
182182
version "0.10.1"

0 commit comments

Comments
 (0)