Skip to content

Commit

Permalink
feat(language-service): Allow specific diagnostics to be suppressed
Browse files Browse the repository at this point in the history
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
  • Loading branch information
dylhunn authored and atscott committed Sep 10, 2024
1 parent 9d27669 commit 7c13306
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Input hashes for repository rule npm_translate_lock(name = "npm", pnpm_lock = "//:pnpm-lock.yaml").
# This file should be checked into version control along with the pnpm-lock.yaml file.
.npmrc=974837034
pnpm-lock.yaml=1398347878
yarn.lock=-1005893296
package.json=-657448584
pnpm-lock.yaml=917719234
yarn.lock=-619082575
package.json=-1482224139
pnpm-workspace.yaml=1711114604
6 changes: 6 additions & 0 deletions client/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,12 @@ export class AngularLanguageClient implements vscode.Disposable {
args.push('--forceStrictTemplates');
}

const suppressAngularDiagnosticCodes =
config.get<string>('angular.suppressAngularDiagnosticCodes');
if (suppressAngularDiagnosticCodes) {
args.push('--suppressAngularDiagnosticCodes', suppressAngularDiagnosticCodes);
}

const tsdk = config.get('typescript.tsdk', '');
if (tsdk.trim().length > 0) {
args.push('--tsdk', tsdk);
Expand Down
22 changes: 18 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@
"type": "boolean",
"default": false,
"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`."
},
"angular.suppressAngularDiagnosticCodes": {
"type": "string",
"default": "",
"markdownDescription": "A comma-separated list of error codes in templates whose diagnostics should be ignored."
}
}
},
Expand Down Expand Up @@ -164,7 +169,10 @@
{
"path": "./syntaxes/template.json",
"scopeName": "template.ng",
"injectTo": ["text.html.derivative", "source.ts"],
"injectTo": [
"text.html.derivative",
"source.ts"
],
"embeddedLanguages": {
"text.html": "html",
"source.css": "css",
Expand All @@ -174,7 +182,10 @@
{
"path": "./syntaxes/template-blocks.json",
"scopeName": "template.blocks.ng",
"injectTo": ["text.html.derivative", "source.ts"],
"injectTo": [
"text.html.derivative",
"source.ts"
],
"embeddedLanguages": {
"text.html": "html",
"control.block.expression.ng": "javascript",
Expand All @@ -184,7 +195,10 @@
{
"path": "./syntaxes/let-declaration.json",
"scopeName": "template.let.ng",
"injectTo": ["text.html.derivative", "source.ts"]
"injectTo": [
"text.html.derivative",
"source.ts"
]
},
{
"path": "./syntaxes/template-tag.json",
Expand Down Expand Up @@ -231,7 +245,7 @@
"test:legacy-syntaxes": "yarn compile:syntaxes-test && yarn build:syntaxes && jasmine dist/syntaxes/test/driver.js"
},
"dependencies": {
"@angular/language-service": "~19.0.0-next.3",
"@angular/language-service": "~19.0.0-next.4",
"typescript": "5.6.1-rc",
"vscode-html-languageservice": "^4.2.5",
"vscode-jsonrpc": "6.0.0",
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"ngserver": "./bin/ngserver"
},
"dependencies": {
"@angular/language-service": "19.0.0-next.3",
"@angular/language-service": "19.0.0-next.4",
"vscode-html-languageservice": "^4.2.5",
"vscode-jsonrpc": "6.0.0",
"vscode-languageserver": "7.0.0",
Expand Down
3 changes: 3 additions & 0 deletions server/src/cmdline_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ interface CommandLineOptions {
disableBlockSyntax: boolean;
disableLetSyntax: boolean;
angularCoreVersion?: string;
suppressAngularDiagnosticCodes?: string;
}

export function parseCommandLine(argv: string[]): CommandLineOptions {
Expand All @@ -58,6 +59,7 @@ export function parseCommandLine(argv: string[]): CommandLineOptions {
disableBlockSyntax: hasArgument(argv, '--disableBlockSyntax'),
disableLetSyntax: hasArgument(argv, '--disableLetSyntax'),
angularCoreVersion: findArgument(argv, '--angularCoreVersion'),
suppressAngularDiagnosticCodes: findArgument(argv, '--suppressAngularDiagnosticCodes'),
};
}

Expand All @@ -76,6 +78,7 @@ export function generateHelpMessage(argv: string[]) {
--includeAutomaticOptionalChainCompletions: Shows completions on potentially undefined values that insert an optional chain call. Requires TS 3.7+ and strict null checks to be enabled.
--includeCompletionsWithSnippetText: Enables snippet completions from Angular language server;
--forceStrictTemplates: Forces the language service to use strictTemplates and ignore the user settings in the 'tsconfig.json'.
--suppressAngularDiagnosticCodes: A comma-separated list of error codes in templates whose diagnostics should be ignored.
Additional options supported by vscode-languageserver:
--clientProcessId=<number>: Automatically kills the server if the client process dies.
Expand Down
1 change: 1 addition & 0 deletions server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ function main() {
disableBlockSyntax: options.disableBlockSyntax,
disableLetSyntax: options.disableLetSyntax,
angularCoreVersion: options.angularCoreVersion ?? null,
suppressAngularDiagnosticCodes: options.suppressAngularDiagnosticCodes ?? null,
});

// Log initialization info
Expand Down
12 changes: 12 additions & 0 deletions server/src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export interface SessionOptions {
disableBlockSyntax: boolean;
disableLetSyntax: boolean;
angularCoreVersion: string|null;
suppressAngularDiagnosticCodes: string|null;
}

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

const htmlLS = getHTMLLanguageService();

const alwaysSuppressDiagnostics: number[] = [
// Diagnostics codes whose errors should always be suppressed, regardless of the options
// configuration.
];

/**
* Session is a wrapper around lsp.IConnection, with all the necessary protocol
* handlers installed for Angular language service.
Expand Down Expand Up @@ -165,6 +171,12 @@ export class Session {
if (options.angularCoreVersion !== null) {
pluginConfig.angularCoreVersion = options.angularCoreVersion;
}
if (options.suppressAngularDiagnosticCodes !== null) {
const parsedDiagnosticCodes =
options.suppressAngularDiagnosticCodes.split(',').map(c => parseInt(c));
pluginConfig.suppressAngularDiagnosticCodes =
[...alwaysSuppressDiagnostics, ...parsedDiagnosticCodes];
}
projSvc.configurePlugin({
pluginName: options.ngPlugin,
configuration: pluginConfig,
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,10 @@
uuid "^8.3.2"
yargs "^17.0.0"

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

"@assemblyscript/loader@^0.10.1":
version "0.10.1"
Expand Down

0 comments on commit 7c13306

Please sign in to comment.