mirror of
https://github.com/microsoft/vscode.git
synced 2026-06-06 15:45:54 +01:00
encapsulate options and ID of the attach prompt action
This commit is contained in:
+24
-2
@@ -26,7 +26,7 @@ import { ISelectPromptOptions, askToSelectPrompt } from './dialogs/askToSelectPr
|
||||
/**
|
||||
* Action ID for the `Attach Prompt` action.
|
||||
*/
|
||||
export const ATTACH_PROMPT_ACTION_ID = 'workbench.action.chat.attach.prompt';
|
||||
const ATTACH_PROMPT_ACTION_ID = 'workbench.action.chat.attach.prompt';
|
||||
|
||||
/**
|
||||
* Options for the {@link AttachPromptAction} action.
|
||||
@@ -94,7 +94,14 @@ class AttachPromptAction extends Action2 {
|
||||
const widget = await attachPrompts(
|
||||
[{ value: resource }],
|
||||
attachOptions,
|
||||
// TODO: @legomushroom - get real alt key mod
|
||||
/**
|
||||
* The `alt` option is always set to `false` here, but it should not
|
||||
* matter - it signifies usage of the `Edit` view which isn't enabled
|
||||
* in the `unified view` mode which is currently the only mode that
|
||||
* produces the `skipSelectionDialog: true` option. Furthermore,
|
||||
* the `unified view` mode will be the default and the only mode
|
||||
* supported in the next iteration and this option will be removed.
|
||||
*/
|
||||
false,
|
||||
);
|
||||
|
||||
@@ -120,6 +127,21 @@ class AttachPromptAction extends Action2 {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs the `Attach Prompt` action with provided options. We export this
|
||||
* function instead of {@link ATTACH_PROMPT_ACTION_ID} directly to
|
||||
* encapsulate/enforce the correct options to be passed to the action.
|
||||
*/
|
||||
export const runAttachPromptAction = async (
|
||||
options: IChatAttachPromptActionOptions,
|
||||
commandService: ICommandService,
|
||||
): Promise<void> => {
|
||||
return await commandService.executeCommand(
|
||||
ATTACH_PROMPT_ACTION_ID,
|
||||
options,
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Helper to register the `Attach Prompt` action.
|
||||
*/
|
||||
|
||||
+24
-8
@@ -6,6 +6,7 @@
|
||||
import { CHAT_CATEGORY } from '../chatActions.js';
|
||||
import { URI } from '../../../../../../base/common/uri.js';
|
||||
import { Codicon } from '../../../../../../base/common/codicons.js';
|
||||
import { runAttachPromptAction } from './chatAttachPromptAction.js';
|
||||
import { assertDefined } from '../../../../../../base/common/types.js';
|
||||
import { ILocalizedString, localize2 } from '../../../../../../nls.js';
|
||||
import { ThemeIcon } from '../../../../../../base/common/themables.js';
|
||||
@@ -20,7 +21,6 @@ import { ChatContextKeyExprs, ChatContextKeys } from '../../../common/chatContex
|
||||
import { getActivePromptUri } from '../../promptSyntax/contributions/usePromptCommand.js';
|
||||
import { ContextKeyExpr } from '../../../../../../platform/contextkey/common/contextkey.js';
|
||||
import { ActiveEditorContext, ResourceContextKey } from '../../../../../common/contextkeys.js';
|
||||
import { ATTACH_PROMPT_ACTION_ID, IChatAttachPromptActionOptions } from './chatAttachPromptAction.js';
|
||||
import { KeybindingWeight } from '../../../../../../platform/keybinding/common/keybindingsRegistry.js';
|
||||
import { Action2, MenuId, registerAction2 } from '../../../../../../platform/actions/common/actions.js';
|
||||
|
||||
@@ -28,10 +28,29 @@ import { Action2, MenuId, registerAction2 } from '../../../../../../platform/act
|
||||
* Constructor options for the `Run Prompt` base action.
|
||||
*/
|
||||
interface IRunPromptBaseActionConstructorOptions {
|
||||
/**
|
||||
* ID of the action to be registered.
|
||||
*/
|
||||
id: string;
|
||||
|
||||
/**
|
||||
* Title of the action.
|
||||
*/
|
||||
title: ILocalizedString;
|
||||
|
||||
/**
|
||||
* Icon of the action.
|
||||
*/
|
||||
icon: ThemeIcon;
|
||||
|
||||
/**
|
||||
* Keybinding of the action.
|
||||
*/
|
||||
keybinding: number;
|
||||
|
||||
/**
|
||||
* Alt action of the UI menu item.
|
||||
*/
|
||||
alt?: ICommandAction;
|
||||
}
|
||||
|
||||
@@ -82,14 +101,11 @@ abstract class RunPromptBaseAction extends Action2 {
|
||||
'Cannot find URI resource for an active text editor.',
|
||||
);
|
||||
|
||||
const attachOptions: IChatAttachPromptActionOptions = {
|
||||
return await runAttachPromptAction({
|
||||
resource,
|
||||
inNewChat,
|
||||
skipSelectionDialog: true,
|
||||
};
|
||||
|
||||
return await commandService
|
||||
.executeCommand(ATTACH_PROMPT_ACTION_ID, attachOptions);
|
||||
}, commandService);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,7 +131,7 @@ const COMMAND_KEY_BINDING = KeyMod.WinCtrl | KeyCode.Slash | KeyMod.Alt;
|
||||
/**
|
||||
* Action ID for the `Run Current Prompt` action.
|
||||
*/
|
||||
export const RUN_CURRENT_PROMPT_ACTION_ID = 'workbench.action.chat.run.prompt.current';
|
||||
const RUN_CURRENT_PROMPT_ACTION_ID = 'workbench.action.chat.run.prompt.current';
|
||||
|
||||
/**
|
||||
* The default `Run Current Prompt` action.
|
||||
@@ -152,7 +168,7 @@ class RunCurrentPromptAction extends RunPromptBaseAction {
|
||||
/**
|
||||
* Action ID for the `Run Current Prompt In New Chat` action.
|
||||
*/
|
||||
export const RUN_CURRENT_PROMPT_IN_NEW_CHAT_ACTION_ID = 'workbench.action.chat.run-in-new-chat.prompt.current';
|
||||
const RUN_CURRENT_PROMPT_IN_NEW_CHAT_ACTION_ID = 'workbench.action.chat.run-in-new-chat.prompt.current';
|
||||
|
||||
const RUN_IN_NEW_CHAT_ACTION_TITLE = localize2(
|
||||
'run-prompt-in-new-chat.capitalized',
|
||||
|
||||
@@ -13,3 +13,5 @@ export const registerReusablePromptActions = () => {
|
||||
registerRunPromptActions();
|
||||
registerAttachPromptActions();
|
||||
};
|
||||
|
||||
export { runAttachPromptAction } from './chatAttachPromptAction.js';
|
||||
|
||||
@@ -65,8 +65,7 @@ import { convertBufferToScreenshotVariable, ScreenshotVariableId } from '../cont
|
||||
import { resizeImage } from '../imageUtils.js';
|
||||
import { COMMAND_ID as USE_PROMPT_COMMAND_ID } from '../promptSyntax/contributions/usePromptCommand.js';
|
||||
import { CHAT_CATEGORY } from './chatActions.js';
|
||||
import { ATTACH_PROMPT_ACTION_ID, IChatAttachPromptActionOptions } from './chatAttachPromptAction/chatAttachPromptAction.js';
|
||||
import { registerReusablePromptActions } from './chatAttachPromptAction/index.js';
|
||||
import { runAttachPromptAction, registerReusablePromptActions } from './chatAttachPromptAction/index.js';
|
||||
|
||||
export function registerChatContextActions() {
|
||||
registerAction2(AttachContextAction);
|
||||
@@ -617,8 +616,7 @@ export class AttachContextAction extends Action2 {
|
||||
toAttach.push(convertBufferToScreenshotVariable(blob));
|
||||
}
|
||||
} else if (isPromptInstructionsQuickPickItem(pick)) {
|
||||
const options: IChatAttachPromptActionOptions = { widget };
|
||||
await commandService.executeCommand(ATTACH_PROMPT_ACTION_ID, options);
|
||||
await runAttachPromptAction({ widget }, commandService);
|
||||
} else {
|
||||
// Anything else is an attachment
|
||||
const attachmentPick = pick as IAttachmentQuickPickItem;
|
||||
|
||||
+3
-5
@@ -11,6 +11,7 @@ import { ChatContextKeys } from '../../../common/chatContextKeys.js';
|
||||
import { KeyMod, KeyCode } from '../../../../../../base/common/keyCodes.js';
|
||||
import { PromptsConfig } from '../../../../../../platform/prompts/common/config.js';
|
||||
import { isPromptFile } from '../../../../../../platform/prompts/common/constants.js';
|
||||
import { runAttachPromptAction } from '../../actions/chatAttachPromptAction/index.js';
|
||||
import { IEditorService } from '../../../../../services/editor/common/editorService.js';
|
||||
import { ICommandService } from '../../../../../../platform/commands/common/commands.js';
|
||||
import { ContextKeyExpr } from '../../../../../../platform/contextkey/common/contextkey.js';
|
||||
@@ -18,7 +19,6 @@ import { MenuId, MenuRegistry } from '../../../../../../platform/actions/common/
|
||||
import { ServicesAccessor } from '../../../../../../platform/instantiation/common/instantiation.js';
|
||||
import { IActiveCodeEditor, isCodeEditor, isDiffEditor } from '../../../../../../editor/browser/editorBrowser.js';
|
||||
import { KeybindingsRegistry, KeybindingWeight } from '../../../../../../platform/keybinding/common/keybindingsRegistry.js';
|
||||
import { IChatAttachPromptActionOptions, ATTACH_PROMPT_ACTION_ID } from '../../actions/chatAttachPromptAction/chatAttachPromptAction.js';
|
||||
|
||||
/**
|
||||
* Command ID of the "Use Prompt" command.
|
||||
@@ -55,12 +55,10 @@ const command = async (
|
||||
): Promise<void> => {
|
||||
const commandService = accessor.get(ICommandService);
|
||||
|
||||
const options: IChatAttachPromptActionOptions = {
|
||||
await runAttachPromptAction({
|
||||
resource: getActivePromptUri(accessor),
|
||||
widget: getFocusedChatWidget(accessor),
|
||||
};
|
||||
|
||||
await commandService.executeCommand(ATTACH_PROMPT_ACTION_ID, options);
|
||||
}, commandService);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user