提交 8183db5b 编写于 作者: M Matt Bierner

Also include keybindings for organize imports and fixAll in the source menu

For #84101
上级 04f403bf
......@@ -20,6 +20,8 @@ import { DisposableStore, IDisposable, Disposable } from 'vs/base/common/lifecyc
export const codeActionCommandId = 'editor.action.codeAction';
export const refactorCommandId = 'editor.action.refactor';
export const sourceActionCommandId = 'editor.action.sourceAction';
export const organizeImportsCommandId = 'editor.action.organizeImports';
export const fixAllCommandId = 'editor.action.fixAll';
export interface CodeActionSet extends IDisposable {
readonly actions: readonly CodeAction[];
......
......@@ -16,7 +16,7 @@ import { IPosition } from 'vs/editor/common/core/position';
import { IEditorContribution } from 'vs/editor/common/editorCommon';
import { EditorContextKeys } from 'vs/editor/common/editorContextKeys';
import { CodeAction } from 'vs/editor/common/modes';
import { CodeActionSet, refactorCommandId, sourceActionCommandId, codeActionCommandId } from 'vs/editor/contrib/codeAction/codeAction';
import { CodeActionSet, refactorCommandId, sourceActionCommandId, codeActionCommandId, organizeImportsCommandId, fixAllCommandId } from 'vs/editor/contrib/codeAction/codeAction';
import { CodeActionUi } from 'vs/editor/contrib/codeAction/codeActionUi';
import { MessageController } from 'vs/editor/contrib/message/messageController';
import * as nls from 'vs/nls';
......@@ -306,7 +306,6 @@ export class RefactorAction extends EditorAction {
}
}
export class SourceAction extends EditorAction {
constructor() {
......@@ -356,11 +355,9 @@ export class SourceAction extends EditorAction {
export class OrganizeImportsAction extends EditorAction {
static readonly Id = 'editor.action.organizeImports';
constructor() {
super({
id: OrganizeImportsAction.Id,
id: organizeImportsCommandId,
label: nls.localize('organizeImports.label', "Organize Imports"),
alias: 'Organize Imports',
precondition: ContextKeyExpr.and(
......@@ -384,11 +381,9 @@ export class OrganizeImportsAction extends EditorAction {
export class FixAllAction extends EditorAction {
static readonly Id = 'editor.action.fixAll';
constructor() {
super({
id: FixAllAction.Id,
id: fixAllCommandId,
label: nls.localize('fixAll.label', "Fix All"),
alias: 'Fix All',
precondition: ContextKeyExpr.and(
......
......@@ -14,7 +14,7 @@ import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
import { IPosition, Position } from 'vs/editor/common/core/position';
import { ScrollType } from 'vs/editor/common/editorCommon';
import { CodeAction } from 'vs/editor/common/modes';
import { CodeActionSet, refactorCommandId, sourceActionCommandId, codeActionCommandId } from 'vs/editor/contrib/codeAction/codeAction';
import { CodeActionSet, refactorCommandId, sourceActionCommandId, codeActionCommandId, organizeImportsCommandId, fixAllCommandId } from 'vs/editor/contrib/codeAction/codeAction';
import { CodeActionAutoApply, CodeActionCommandArgs, CodeActionKind } from 'vs/editor/contrib/codeAction/codeActionTrigger';
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
......@@ -95,15 +95,31 @@ export class CodeActionWidget extends Disposable {
}
private resolveKeybindings(actions: readonly CodeActionAction[]): Map<CodeActionAction, ResolvedKeybinding> {
const codeActionCommands = new Set([
refactorCommandId,
codeActionCommandId,
sourceActionCommandId,
organizeImportsCommandId,
fixAllCommandId
]);
// Lazy since we may not actually ever read the value
const allCodeActionBindings = new Lazy<readonly ResolveCodeActionKeybinding[]>(() =>
this._keybindingService.getKeybindings()
.filter(item => new Set([refactorCommandId, codeActionCommandId, sourceActionCommandId]).has(item.command!))
.filter(item => codeActionCommands.has(item.command!))
.filter(item => item.resolvedKeybinding)
.map((item): ResolveCodeActionKeybinding => {
// Special case these commands since they come built-in with VS Code and don't use 'commandArgs'
let commandArgs = item.commandArgs;
if (item.command === organizeImportsCommandId) {
commandArgs = { kind: CodeActionKind.SourceOrganizeImports.value };
} else if (item.command === fixAllCommandId) {
commandArgs = { kind: CodeActionKind.SourceFixAll.value };
}
return {
resolvedKeybinding: item.resolvedKeybinding!,
...CodeActionCommandArgs.fromUser(item.commandArgs, {
...CodeActionCommandArgs.fromUser(commandArgs, {
kind: CodeActionKind.None,
apply: CodeActionAutoApply.Never
})
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册