From ca6af2f2577407697c147f976592ab127366a463 Mon Sep 17 00:00:00 2001 From: Alex Dima Date: Sat, 4 Nov 2023 13:25:35 +0100 Subject: [PATCH] Add IEditorAction.metadata --- build/monaco/monaco.d.ts.recipe | 7 ++++ src/vs/editor/browser/editorExtensions.ts | 6 ++-- .../editor/browser/widget/codeEditorWidget.ts | 1 + src/vs/editor/common/editorAction.ts | 33 ++++++------------- src/vs/editor/common/editorCommon.ts | 2 ++ .../browser/bracketMatching.ts | 2 +- .../browser/standaloneCodeEditor.ts | 1 + src/vs/monaco.d.ts | 8 +++++ 8 files changed, 33 insertions(+), 27 deletions(-) diff --git a/build/monaco/monaco.d.ts.recipe b/build/monaco/monaco.d.ts.recipe index 55efbe60085d5..a6eb3b7128f7c 100644 --- a/build/monaco/monaco.d.ts.recipe +++ b/build/monaco/monaco.d.ts.recipe @@ -97,6 +97,13 @@ declare namespace monaco.editor { export interface ICommandHandler { (...args: any[]): void; } +export interface ILocalizedString { + original: string; + value: string; +} +export interface ICommandMetadata { + readonly description: ILocalizedString | string; +} #include(vs/platform/contextkey/common/contextkey): IContextKey, ContextKeyValue #include(vs/editor/standalone/browser/standaloneServices): IEditorOverrideServices #include(vs/platform/markers/common/markers): IMarker, IMarkerData, IRelatedInformation diff --git a/src/vs/editor/browser/editorExtensions.ts b/src/vs/editor/browser/editorExtensions.ts index 961941f76dd83..d635dcc403675 100644 --- a/src/vs/editor/browser/editorExtensions.ts +++ b/src/vs/editor/browser/editorExtensions.ts @@ -104,14 +104,14 @@ export abstract class Command { public readonly precondition: ContextKeyExpression | undefined; private readonly _kbOpts: ICommandKeybindingsOptions | ICommandKeybindingsOptions[] | undefined; private readonly _menuOpts: ICommandMenuOptions | ICommandMenuOptions[] | undefined; - private readonly _metadata: ICommandMetadata | undefined; + public readonly metadata: ICommandMetadata | undefined; constructor(opts: ICommandOptions) { this.id = opts.id; this.precondition = opts.precondition; this._kbOpts = opts.kbOpts; this._menuOpts = opts.menuOpts; - this._metadata = opts.metadata; + this.metadata = opts.metadata; } public register(): void { @@ -153,7 +153,7 @@ export abstract class Command { CommandsRegistry.registerCommand({ id: this.id, handler: (accessor, args) => this.runCommand(accessor, args), - metadata: this._metadata + metadata: this.metadata }); } diff --git a/src/vs/editor/browser/widget/codeEditorWidget.ts b/src/vs/editor/browser/widget/codeEditorWidget.ts index 93407998bc0ea..414b6136d92fa 100644 --- a/src/vs/editor/browser/widget/codeEditorWidget.ts +++ b/src/vs/editor/browser/widget/codeEditorWidget.ts @@ -345,6 +345,7 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE action.id, action.label, action.alias, + action.metadata, action.precondition ?? undefined, (): Promise => { return this._instantiationService.invokeFunction((accessor) => { diff --git a/src/vs/editor/common/editorAction.ts b/src/vs/editor/common/editorAction.ts index 5cf40416a1ef2..90924e7895a6e 100644 --- a/src/vs/editor/common/editorAction.ts +++ b/src/vs/editor/common/editorAction.ts @@ -4,33 +4,20 @@ *--------------------------------------------------------------------------------------------*/ import { IEditorAction } from 'vs/editor/common/editorCommon'; -import { IContextKeyService, ContextKeyExpression } from 'vs/platform/contextkey/common/contextkey'; +import { ICommandMetadata } from 'vs/platform/commands/common/commands'; +import { ContextKeyExpression, IContextKeyService } 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; - private readonly _contextKeyService: IContextKeyService; - constructor( - id: string, - label: string, - alias: string, - precondition: ContextKeyExpression | undefined, - run: () => Promise, - 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, + private readonly _contextKeyService: IContextKeyService + ) { } public isSupported(): boolean { return this._contextKeyService.contextMatchesRules(this._precondition); diff --git a/src/vs/editor/common/editorCommon.ts b/src/vs/editor/common/editorCommon.ts index 6ce806ff1090d..f4485ae9a6d85 100644 --- a/src/vs/editor/common/editorCommon.ts +++ b/src/vs/editor/common/editorCommon.ts @@ -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. @@ -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; } diff --git a/src/vs/editor/contrib/bracketMatching/browser/bracketMatching.ts b/src/vs/editor/contrib/bracketMatching/browser/bracketMatching.ts index bfa675232e92a..ffd9e3240dd8f 100644 --- a/src/vs/editor/contrib/bracketMatching/browser/bracketMatching.ts +++ b/src/vs/editor/contrib/bracketMatching/browser/bracketMatching.ts @@ -53,7 +53,7 @@ class SelectToBracketAction extends EditorAction { alias: 'Select to Bracket', precondition: undefined, metadata: { - description: `Select to Bracket`, + description: nls.localize2('smartSelect.selectToBracketDescription', "Select the text inside and including the brackets or curly braces"), args: [{ name: 'args', schema: { diff --git a/src/vs/editor/standalone/browser/standaloneCodeEditor.ts b/src/vs/editor/standalone/browser/standaloneCodeEditor.ts index 02ff64c602bb3..4ed5acd6a1d02 100644 --- a/src/vs/editor/standalone/browser/standaloneCodeEditor.ts +++ b/src/vs/editor/standalone/browser/standaloneCodeEditor.ts @@ -367,6 +367,7 @@ export class StandaloneCodeEditor extends CodeEditorWidget implements IStandalon uniqueId, label, label, + undefined, precondition, (...args: unknown[]) => Promise.resolve(_descriptor.run(this, ...args)), this._contextKeyService diff --git a/src/vs/monaco.d.ts b/src/vs/monaco.d.ts index 26ac1e78e0362..e45bb5af78487 100644 --- a/src/vs/monaco.d.ts +++ b/src/vs/monaco.d.ts @@ -1434,6 +1434,13 @@ declare namespace monaco.editor { export interface ICommandHandler { (...args: any[]): void; } + export interface ILocalizedString { + original: string; + value: string; + } + export interface ICommandMetadata { + readonly description: ILocalizedString | string; + } export interface IContextKey { set(value: T): void; @@ -2469,6 +2476,7 @@ declare namespace monaco.editor { readonly id: string; readonly label: string; readonly alias: string; + readonly metadata: ICommandMetadata | undefined; isSupported(): boolean; run(args?: unknown): Promise; }