Skip to content
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

Some code actions are de-prioritized in codeActionGroups #193355

Closed
yue4u opened this issue Sep 18, 2023 · 2 comments · May be fixed by #193356
Closed

Some code actions are de-prioritized in codeActionGroups #193355

yue4u opened this issue Sep 18, 2023 · 2 comments · May be fixed by #193356
Assignees
Labels
mitigated Issue has workaround in place

Comments

@yue4u
Copy link

yue4u commented Sep 18, 2023

Does this issue occur when all extensions are disabled?: Yes

  • VS Code Version: 1.82.0 8b617bd x64
  • OS Version: Linux home 6.5.2-arch1-1

Steps to Reproduce:

  1. Expand code action menu at any code which has both refactor and refactor.inline codeActions
  2. Since the order of codeActionGroups in codeActionMenu.ts is hard coded, it de-prioritizes the refactor code action and put it to uncategorizedCodeActionGroup i.e. More Actions...
    const codeActionGroups = Object.freeze<ActionGroup[]>([
    { kind: CodeActionKind.QuickFix, title: localize('codeAction.widget.id.quickfix', 'Quick Fix') },
    { kind: CodeActionKind.RefactorExtract, title: localize('codeAction.widget.id.extract', 'Extract'), icon: Codicon.wrench },
    { kind: CodeActionKind.RefactorInline, title: localize('codeAction.widget.id.inline', 'Inline'), icon: Codicon.wrench },
    { kind: CodeActionKind.RefactorRewrite, title: localize('codeAction.widget.id.convert', 'Rewrite'), icon: Codicon.wrench },
    { kind: CodeActionKind.RefactorMove, title: localize('codeAction.widget.id.move', 'Move'), icon: Codicon.wrench },
    { kind: CodeActionKind.SurroundWith, title: localize('codeAction.widget.id.surround', 'Surround With'), icon: Codicon.symbolSnippet },
    { kind: CodeActionKind.Source, title: localize('codeAction.widget.id.source', 'Source Action'), icon: Codicon.symbolFile },
    uncategorizedCodeActionGroup,
    ]);

Related:

rust-lang/rust-analyzer#15364

Although rust-lang/rust-analyzer#14362 has tried to fix the order but it does not work with grouping without changes on vscode's side.

image

Possible Fix:

Cover all CodeActionKind in order in codeActionGroups

https://code.visualstudio.com/api/references/vscode-api#CodeActionKind

image

@vscodenpa
Copy link

Thanks for creating this issue! It looks like you may be using an old version of VS Code, the latest stable release is 1.82.2. Please try upgrading to the latest version and checking whether this issue remains.

Happy Coding!

@justschen
Copy link
Contributor

This is intended since refactorings (and all code actions) in general are grouped into the categories - actions with just refactor as the CodeActionKind are too unspecific.

A workaround could be like this:

Screenshot 2023-12-06 at 3 26 58 PM

Here, we specify a refactor subset to be grouped, instead of the blanket CodeActionKind.Refactor type.

	context.subscriptions.push(vscode.languages.registerCodeActionsProvider(
		{ scheme: 'file' },
		{
			provideCodeActions(document, range, context, token) {
				const results = [
					new vscode.CodeAction("Foo", vscode.CodeActionKind.RefactorRewrite),
				];
				return results;
			},
		}
	));

Alternatively, in this specific case, since it's removing something, it could potentially be a Quick Fix and be contributed as such instead.

@justschen justschen added the mitigated Issue has workaround in place label Dec 6, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Jan 21, 2024
@aiday-mar aiday-mar added this to the December / January 2024 milestone Feb 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
mitigated Issue has workaround in place
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants