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

Initial attempt to support editor commands #194849

Closed
wants to merge 5 commits into from
Closed
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
24 changes: 12 additions & 12 deletions src/vs/editor/browser/coreCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { Range } from 'vs/editor/common/core/range';
import { Handler, ScrollType } from 'vs/editor/common/editorCommon';
import { EditorContextKeys } from 'vs/editor/common/editorContextKeys';
import { VerticalRevealType } from 'vs/editor/common/viewEvents';
import { ICommandHandlerDescription } from 'vs/platform/commands/common/commands';
import { ICommandMetadata } from 'vs/platform/commands/common/commands';
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
import { KeybindingWeight, KeybindingsRegistry } from 'vs/platform/keybinding/common/keybindingsRegistry';
Expand Down Expand Up @@ -74,7 +74,7 @@ export namespace EditorScroll_ {
return true;
};

export const description = <ICommandHandlerDescription>{
export const metadata = <ICommandMetadata>{
description: 'Scroll editor in the given direction',
args: [
{
Expand Down Expand Up @@ -252,7 +252,7 @@ export namespace RevealLine_ {
return true;
};

export const description = <ICommandHandlerDescription>{
export const metadata = <ICommandMetadata>{
description: 'Reveal the given line at the given logical position',
args: [
{
Expand Down Expand Up @@ -589,7 +589,7 @@ export namespace CoreNavigationCommands {
super({
id: 'cursorMove',
precondition: undefined,
description: CursorMove_.description
metadata: CursorMove_.metadata
});
}

Expand Down Expand Up @@ -1110,7 +1110,7 @@ export namespace CoreNavigationCommands {
primary: KeyCode.End,
mac: { primary: KeyCode.End, secondary: [KeyMod.CtrlCmd | KeyCode.RightArrow] }
},
description: {
metadata: {
description: `Go to End`,
args: [{
name: 'args',
Expand Down Expand Up @@ -1139,7 +1139,7 @@ export namespace CoreNavigationCommands {
primary: KeyMod.Shift | KeyCode.End,
mac: { primary: KeyMod.Shift | KeyCode.End, secondary: [KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.RightArrow] }
},
description: {
metadata: {
description: `Select to End`,
args: [{
name: 'args',
Expand Down Expand Up @@ -1307,7 +1307,7 @@ export namespace CoreNavigationCommands {
super({
id: 'editorScroll',
precondition: undefined,
description: EditorScroll_.description
metadata: EditorScroll_.metadata
});
}

Expand Down Expand Up @@ -1828,7 +1828,7 @@ export namespace CoreNavigationCommands {
super({
id: 'revealLine',
precondition: undefined,
description: RevealLine_.description
metadata: RevealLine_.metadata
});
}

Expand Down Expand Up @@ -2125,11 +2125,11 @@ class EditorHandlerCommand extends Command {

private readonly _handlerId: string;

constructor(id: string, handlerId: string, description?: ICommandHandlerDescription) {
constructor(id: string, handlerId: string, metadata?: ICommandMetadata) {
super({
id: id,
precondition: undefined,
description: description
metadata
});
this._handlerId = handlerId;
}
Expand All @@ -2144,9 +2144,9 @@ class EditorHandlerCommand extends Command {
}
}

function registerOverwritableCommand(handlerId: string, description?: ICommandHandlerDescription): void {
function registerOverwritableCommand(handlerId: string, metadata?: ICommandMetadata): void {
registerCommand(new EditorHandlerCommand('default:' + handlerId, handlerId));
registerCommand(new EditorHandlerCommand(handlerId, handlerId, description));
registerCommand(new EditorHandlerCommand(handlerId, handlerId, metadata));
}

registerOverwritableCommand(Handler.Type, {
Expand Down
12 changes: 7 additions & 5 deletions src/vs/editor/browser/editorExtensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { ITextModel } from 'vs/editor/common/model';
import { IModelService } from 'vs/editor/common/services/model';
import { ITextModelService } from 'vs/editor/common/services/resolverService';
import { MenuId, MenuRegistry, Action2 } from 'vs/platform/actions/common/actions';
import { CommandsRegistry, ICommandHandlerDescription } from 'vs/platform/commands/common/commands';
import { CommandsRegistry, ICommandMetadata } from 'vs/platform/commands/common/commands';
import { ContextKeyExpr, IContextKeyService, ContextKeyExpression } from 'vs/platform/contextkey/common/contextkey';
import { ServicesAccessor as InstantiationServicesAccessor, BrandedService, IInstantiationService, IConstructorSignature } from 'vs/platform/instantiation/common/instantiation';
import { IKeybindings, KeybindingsRegistry, KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
Expand Down Expand Up @@ -96,22 +96,22 @@ export interface ICommandOptions {
id: string;
precondition: ContextKeyExpression | undefined;
kbOpts?: ICommandKeybindingsOptions | ICommandKeybindingsOptions[];
description?: ICommandHandlerDescription;
metadata?: ICommandMetadata;
menuOpts?: ICommandMenuOptions | ICommandMenuOptions[];
}
export abstract class Command {
public readonly id: string;
public readonly precondition: ContextKeyExpression | undefined;
private readonly _kbOpts: ICommandKeybindingsOptions | ICommandKeybindingsOptions[] | undefined;
private readonly _menuOpts: ICommandMenuOptions | ICommandMenuOptions[] | undefined;
private readonly _description: ICommandHandlerDescription | undefined;
private readonly _metadata: ICommandMetadata | undefined;

constructor(opts: ICommandOptions) {
this.id = opts.id;
this.precondition = opts.precondition;
this._kbOpts = opts.kbOpts;
this._menuOpts = opts.menuOpts;
this._description = opts.description;
this._metadata = opts.metadata;
}

public register(): void {
Expand Down Expand Up @@ -153,7 +153,7 @@ export abstract class Command {
CommandsRegistry.registerCommand({
id: this.id,
handler: (accessor, args) => this.runCommand(accessor, args),
description: this._description
metadata: this._metadata
});
}

Expand Down Expand Up @@ -376,11 +376,13 @@ export abstract class EditorAction extends EditorCommand {

public readonly label: string;
public readonly alias: string;
public readonly metadata: ICommandMetadata | undefined;

constructor(opts: IActionOptions) {
super(EditorAction.convertOptions(opts));
this.label = opts.label;
this.alias = opts.alias;
this.metadata = opts.metadata;
}

public runEditorCommand(accessor: ServicesAccessor, editor: ICodeEditor, args: any): void | Promise<void> {
Expand Down
1 change: 1 addition & 0 deletions src/vs/editor/browser/widget/codeEditorWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE
action.id,
action.label,
action.alias,
action.metadata,
action.precondition ?? undefined,
(): Promise<void> => {
return this._instantiationService.invokeFunction((accessor) => {
Expand Down
4 changes: 2 additions & 2 deletions src/vs/editor/common/cursor/cursorMoveCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { MoveOperations } from 'vs/editor/common/cursor/cursorMoveOperations';
import { WordOperations } from 'vs/editor/common/cursor/cursorWordOperations';
import { IPosition, Position } from 'vs/editor/common/core/position';
import { Range } from 'vs/editor/common/core/range';
import { ICommandHandlerDescription } from 'vs/platform/commands/common/commands';
import { ICommandMetadata } from 'vs/platform/commands/common/commands';
import { IViewModel } from 'vs/editor/common/viewModel';

export class CursorMoveCommands {
Expand Down Expand Up @@ -596,7 +596,7 @@ export namespace CursorMove {
return true;
};

export const description = <ICommandHandlerDescription>{
export const metadata = <ICommandMetadata>{
description: 'Move cursor to a logical position in the view',
args: [
{
Expand Down
31 changes: 9 additions & 22 deletions src/vs/editor/common/editorAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,20 @@
*--------------------------------------------------------------------------------------------*/

import { IEditorAction } from 'vs/editor/common/editorCommon';
import { ICommandMetadata } from 'vs/platform/commands/common/commands';
import { IContextKeyService, ContextKeyExpression } from 'vs/platform/contextkey/common/contextkey';

export class InternalEditorAction implements IEditorAction {

public readonly id: string;
public readonly label: string;
public readonly alias: string;

private readonly _precondition: ContextKeyExpression | undefined;
private readonly _run: (args: unknown) => Promise<void>;
private readonly _contextKeyService: IContextKeyService;

constructor(
id: string,
label: string,
alias: string,
precondition: ContextKeyExpression | undefined,
run: () => Promise<void>,
contextKeyService: IContextKeyService
) {
this.id = id;
this.label = label;
this.alias = alias;
this._precondition = precondition;
this._run = run;
this._contextKeyService = contextKeyService;
}
public readonly id: string,
public readonly label: string,
public readonly alias: string,
public readonly metadata: ICommandMetadata | undefined,
private readonly _precondition: ContextKeyExpression | undefined,
private readonly _run: (args: unknown) => Promise<void>,
private readonly _contextKeyService: IContextKeyService
) { }

public isSupported(): boolean {
return this._contextKeyService.contextMatchesRules(this._precondition);
Expand Down
2 changes: 2 additions & 0 deletions src/vs/editor/common/editorCommon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { IRange, Range } from 'vs/editor/common/core/range';
import { ISelection, Selection } from 'vs/editor/common/core/selection';
import { IModelDecoration, IModelDecorationsChangeAccessor, IModelDeltaDecoration, ITextModel, IValidEditOperation, OverviewRulerLane, TrackedRangeStickiness } from 'vs/editor/common/model';
import { IModelDecorationsChangedEvent } from 'vs/editor/common/textModelEvents';
import { ICommandMetadata } from 'vs/platform/commands/common/commands';

/**
* A builder and helper for edit operations for a command.
Expand Down Expand Up @@ -155,6 +156,7 @@ export interface IEditorAction {
readonly id: string;
readonly label: string;
readonly alias: string;
readonly metadata: ICommandMetadata | undefined;
isSupported(): boolean;
run(args?: unknown): Promise<void>;
}
Expand Down
38 changes: 19 additions & 19 deletions src/vs/editor/common/standalone/standaloneEnums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -572,28 +572,28 @@ export enum KeyCode {
* Either the angle bracket key or the backslash key on the RT 102-key keyboard.
*/
IntlBackslash = 97,
Numpad0 = 98,
Numpad1 = 99,
Numpad2 = 100,
Numpad3 = 101,
Numpad4 = 102,
Numpad5 = 103,
Numpad6 = 104,
Numpad7 = 105,
Numpad8 = 106,
Numpad9 = 107,
NumpadMultiply = 108,
NumpadAdd = 109,
NUMPAD_SEPARATOR = 110,
NumpadSubtract = 111,
NumpadDecimal = 112,
NumpadDivide = 113,
Numpad0 = 98,// VK_NUMPAD0, 0x60, Numeric keypad 0 key
Numpad1 = 99,// VK_NUMPAD1, 0x61, Numeric keypad 1 key
Numpad2 = 100,// VK_NUMPAD2, 0x62, Numeric keypad 2 key
Numpad3 = 101,// VK_NUMPAD3, 0x63, Numeric keypad 3 key
Numpad4 = 102,// VK_NUMPAD4, 0x64, Numeric keypad 4 key
Numpad5 = 103,// VK_NUMPAD5, 0x65, Numeric keypad 5 key
Numpad6 = 104,// VK_NUMPAD6, 0x66, Numeric keypad 6 key
Numpad7 = 105,// VK_NUMPAD7, 0x67, Numeric keypad 7 key
Numpad8 = 106,// VK_NUMPAD8, 0x68, Numeric keypad 8 key
Numpad9 = 107,// VK_NUMPAD9, 0x69, Numeric keypad 9 key
NumpadMultiply = 108,// VK_MULTIPLY, 0x6A, Multiply key
NumpadAdd = 109,// VK_ADD, 0x6B, Add key
NUMPAD_SEPARATOR = 110,// VK_SEPARATOR, 0x6C, Separator key
NumpadSubtract = 111,// VK_SUBTRACT, 0x6D, Subtract key
NumpadDecimal = 112,// VK_DECIMAL, 0x6E, Decimal key
NumpadDivide = 113,// VK_DIVIDE, 0x6F,
/**
* Cover all key codes when IME is processing input.
*/
KEY_IN_COMPOSITION = 114,
ABNT_C1 = 115,
ABNT_C2 = 116,
ABNT_C1 = 115,// Brazilian (ABNT) Keyboard
ABNT_C2 = 116,// Brazilian (ABNT) Keyboard
AudioVolumeMute = 117,
AudioVolumeUp = 118,
AudioVolumeDown = 119,
Expand Down Expand Up @@ -924,4 +924,4 @@ export enum WrappingIndent {
* DeepIndent => wrapped lines get +2 indentation toward the parent.
*/
DeepIndent = 3
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ class SelectToBracketAction extends EditorAction {
label: nls.localize('smartSelect.selectToBracket', "Select to Bracket"),
alias: 'Select to Bracket',
precondition: undefined,
description: {
description: `Select to Bracket`,
metadata: {
description: nls.localize2('smartSelect.selectToBracketDescription', "Select the text inside and including the brackets or curly braces"),
Copy link
Member Author

Choose a reason for hiding this comment

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

This is an example

args: [{
name: 'args',
schema: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export class CodeActionCommand extends EditorCommand {
super({
id: codeActionCommandId,
precondition: ContextKeyExpr.and(EditorContextKeys.writable, EditorContextKeys.hasCodeActionsProvider),
description: {
metadata: {
description: 'Trigger a code action',
args: [{ name: 'args', schema: argsSchema, }]
}
Expand Down Expand Up @@ -143,7 +143,7 @@ export class RefactorAction extends EditorAction {
EditorContextKeys.writable,
contextKeyForSupportedActions(CodeActionKind.Refactor)),
},
description: {
metadata: {
description: 'Refactor...',
args: [{ name: 'args', schema: argsSchema }]
}
Expand Down Expand Up @@ -186,7 +186,7 @@ export class SourceAction extends EditorAction {
EditorContextKeys.writable,
contextKeyForSupportedActions(CodeActionKind.Source)),
},
description: {
metadata: {
description: 'Source Action...',
args: [{ name: 'args', schema: argsSchema }]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ registerEditorAction(class extends EditorAction {
label: nls.localize('pasteAs', "Paste As..."),
alias: 'Paste As...',
precondition: undefined,
description: {
metadata: {
description: 'Paste as',
args: [{
name: 'args',
Expand Down
2 changes: 1 addition & 1 deletion src/vs/editor/contrib/find/browser/findController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ export class StartFindWithArgsAction extends EditorAction {
primary: 0,
weight: KeybindingWeight.EditorContrib
},
description: findArgDescription
metadata: findArgDescription
});
}

Expand Down
4 changes: 2 additions & 2 deletions src/vs/editor/contrib/folding/browser/folding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ class UnfoldAction extends FoldingAction<FoldingArguments> {
},
weight: KeybindingWeight.EditorContrib
},
description: {
metadata: {
description: 'Unfold the content in the editor',
args: [
{
Expand Down Expand Up @@ -708,7 +708,7 @@ class FoldAction extends FoldingAction<FoldingArguments> {
},
weight: KeybindingWeight.EditorContrib
},
description: {
metadata: {
description: 'Fold the content in the editor',
args: [
{
Expand Down
4 changes: 2 additions & 2 deletions src/vs/editor/contrib/gotoSymbol/browser/goToCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,7 @@ class GenericGoToLocationAction extends SymbolNavigationAction {

CommandsRegistry.registerCommand({
id: 'editor.action.goToLocations',
description: {
metadata: {
description: 'Go to locations from a position in a file',
args: [
{ name: 'uri', description: 'The text document in which to start', constraint: URI },
Expand Down Expand Up @@ -841,7 +841,7 @@ CommandsRegistry.registerCommand({

CommandsRegistry.registerCommand({
id: 'editor.action.peekLocations',
description: {
metadata: {
description: 'Peek locations from a position in a file',
args: [
{ name: 'uri', description: 'The text document in which to start', constraint: URI },
Expand Down
2 changes: 1 addition & 1 deletion src/vs/editor/contrib/hover/browser/hover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ class ShowOrFocusHoverAction extends EditorAction {
'If the hover is already visible, it will take focus.'
]
}, "Show or Focus Hover"),
description: {
metadata: {
description: `Show or Focus Hover`,
args: [{
name: 'args',
Expand Down
Loading