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

fix: cover more code action kind in codeActionGroups #193356

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
8 changes: 6 additions & 2 deletions src/vs/editor/contrib/codeAction/browser/codeActionMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,22 @@ interface ActionGroup {
readonly kind: CodeActionKind;
readonly title: string;
readonly icon?: ThemeIcon;
readonly exact?: boolean;
}

const uncategorizedCodeActionGroup = Object.freeze<ActionGroup>({ kind: CodeActionKind.Empty, title: localize('codeAction.widget.id.more', 'More Actions...') });

const codeActionGroups = Object.freeze<ActionGroup[]>([
{ kind: CodeActionKind.QuickFix, title: localize('codeAction.widget.id.quickfix', 'Quick Fix') },
{ kind: CodeActionKind.Refactor, title: localize('codeAction.widget.id.refactor', 'Refactor'), icon: Codicon.wrench, exact: true },
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not very sure where these localize keys are

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without setting this to exact match it'll catch all following sub action kinds

{ 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 },
{ kind: CodeActionKind.Source, title: localize('codeAction.widget.id.source', 'Source Action'), icon: Codicon.symbolFile, exact: true },
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will change existing behavior so might need discussion

{ kind: CodeActionKind.SourceFixAll, title: localize('codeAction.widget.id.source.fixAll', 'Source Action Fix All'), icon: Codicon.symbolFile },
{ kind: CodeActionKind.SourceOrganizeImports, title: localize('codeAction.widget.id.source.organizeImports', 'Source Action Organize Imports'), icon: Codicon.symbolFile },
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Question]: Is it better to keep the order as same as the documentation? It's doable via typecheck but I couldn't find any existing types to reuse https://code.visualstudio.com/api/references/vscode-api#CodeActionKind

uncategorizedCodeActionGroup,
]);

Expand Down Expand Up @@ -56,7 +60,7 @@ export function toMenuItems(
for (const action of inputCodeActions) {
const kind = action.action.kind ? new CodeActionKind(action.action.kind) : CodeActionKind.None;
for (const menuEntry of menuEntries) {
if (menuEntry.group.kind.contains(kind)) {
if (menuEntry.group.exact ? menuEntry.group.kind.equals(kind) : menuEntry.group.kind.contains(kind)) {
menuEntry.actions.push(action);
break;
}
Expand Down