Skip to content

feat: Add option to disable code actions #1849

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions client/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,10 @@ function constructArgs(
if (disableAutomaticNgcc) {
args.push('--disableAutomaticNgcc');
}
const disableCodeActions = config.get<boolean>('angular.disableCodeActions');
if (disableCodeActions) {
args.push('--disableCodeActions');
}

const forceStrictTemplates = config.get<boolean>('angular.forceStrictTemplates');
if (forceStrictTemplates) {
Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@
"default": false,
"markdownDescription": "Disable the step to automatically run ngcc. [ngcc](https://github.com/angular/angular/blob/main/packages/compiler/design/architecture.md#high-level-proposal) is required to run and gather metadata from libraries not published with Ivy instructions. This can be run outside of VSCode instead (for example, as part of the build/rebuild in the CLI). Note that ngcc needs to run not only at startup, but also whenever the dependencies change. Failing to run ngcc when required can result in incomplete information and spurious errors reported by the language service."
},
"angular.disableCodeActions": {
"type": "boolean",
"default": false,
"markdownDescription": "Disable code actions in Angular contexts, including quick fixes in template files which add missing imports. Some code actions require global project analysis, so it may be desirable to disable them for performance reasons."
},
"angular.forceStrictTemplates": {
"type": "boolean",
"default": false,
Expand Down
2 changes: 2 additions & 0 deletions server/src/cmdline_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ interface CommandLineOptions {
* If true, skips the running ngcc when using Ivy LS.
*/
disableAutomaticNgcc: boolean;
disableCodeActions: boolean;
logFile?: string;
logVerbosity?: string;
logToConsole: boolean;
Expand All @@ -52,6 +53,7 @@ export function parseCommandLine(argv: string[]): CommandLineOptions {
help: hasArgument(argv, '--help'),
ivy: !hasArgument(argv, '--viewEngine'),
disableAutomaticNgcc: hasArgument(argv, '--disableAutomaticNgcc'),
disableCodeActions: hasArgument(argv, '--disableCodeActions'),
logFile: findArgument(argv, '--logFile'),
logVerbosity: findArgument(argv, '--logVerbosity'),
logToConsole: hasArgument(argv, '--logToConsole'),
Expand Down
1 change: 1 addition & 0 deletions server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ function main() {
resolvedNgLsPath: ng.resolvedPath,
ivy: isG3 ? true : options.ivy,
disableAutomaticNgcc: options.disableAutomaticNgcc || options.untrustedWorkspace,
disableCodeActions: options.disableCodeActions,
logToConsole: options.logToConsole,
includeAutomaticOptionalChainCompletions: options.includeAutomaticOptionalChainCompletions,
includeCompletionsWithSnippetText: options.includeCompletionsWithSnippetText,
Expand Down
20 changes: 12 additions & 8 deletions server/src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export interface SessionOptions {
resolvedNgLsPath: string;
ivy: boolean;
disableAutomaticNgcc: boolean;
disableCodeActions: boolean;
logToConsole: boolean;
includeAutomaticOptionalChainCompletions: boolean;
includeCompletionsWithSnippetText: boolean;
Expand Down Expand Up @@ -115,7 +116,7 @@ export class Session {
}
});

this.addProtocolHandlers(this.connection);
this.addProtocolHandlers(this.connection, options);
this.projectService = this.createProjectService(options);
}

Expand Down Expand Up @@ -183,8 +184,8 @@ export class Session {
return projSvc;
}

private addProtocolHandlers(conn: lsp.Connection) {
conn.onInitialize(p => this.onInitialize(p));
private addProtocolHandlers(conn: lsp.Connection, options: SessionOptions) {
conn.onInitialize(p => this.onInitialize(p, options));
conn.onDidOpenTextDocument(p => this.onDidOpenTextDocument(p));
conn.onDidCloseTextDocument(p => this.onDidCloseTextDocument(p));
conn.onDidChangeTextDocument(p => this.onDidChangeTextDocument(p));
Expand All @@ -206,8 +207,10 @@ export class Session {
conn.onCodeLens(p => this.onCodeLens(p));
conn.onCodeLensResolve(p => this.onCodeLensResolve(p));
conn.onSignatureHelp(p => this.onSignatureHelp(p));
conn.onCodeAction(p => this.onCodeAction(p));
conn.onCodeActionResolve(p => this.onCodeActionResolve(p));
if (!options.disableCodeActions) {
conn.onCodeAction(p => this.onCodeAction(p));
conn.onCodeActionResolve(p => this.onCodeActionResolve(p));
}
}

private onCodeAction(params: lsp.CodeActionParams): lsp.CodeAction[]|null {
Expand Down Expand Up @@ -707,7 +710,8 @@ export class Session {
return project;
}

private onInitialize(params: lsp.InitializeParams): lsp.InitializeResult {
private onInitialize(params: lsp.InitializeParams, options: SessionOptions):
lsp.InitializeResult {
this.snippetSupport =
params.capabilities.textDocument?.completion?.completionItem?.snippetSupport;
const serverOptions: ServerOptions = {
Expand Down Expand Up @@ -741,7 +745,7 @@ export class Session {
workspace: {
workspaceFolders: {supported: true},
},
codeActionProvider: this.ivy ? {
codeActionProvider: (this.ivy && !options.disableCodeActions) ? {
resolveProvider: true,
// Now the Angular code action provider only supports `QuickFix`. If leave the
// `codeActionKinds` empty, all action requests will be sent to the Angular language
Expand All @@ -752,7 +756,7 @@ export class Session {
// [here](https://github.com/angular/vscode-ng-language-service/issues/1828)
codeActionKinds: [lsp.CodeActionKind.QuickFix],
} :
undefined,
undefined,
},
serverOptions,
};
Expand Down