Path: blob/main/src/vs/workbench/contrib/chat/browser/promptSyntax/chatModeActions.ts
3296 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { CHAT_CATEGORY, CHAT_CONFIG_MENU_ID } from '../actions/chatActions.js';6import { Codicon } from '../../../../../base/common/codicons.js';7import { ChatContextKeys } from '../../common/chatContextKeys.js';8import { localize, localize2 } from '../../../../../nls.js';9import { PromptsConfig } from '../../common/promptSyntax/config/config.js';10import { PromptFilePickers } from './pickers/promptFilePickers.js';11import { ServicesAccessor } from '../../../../../editor/browser/editorExtensions.js';12import { ContextKeyExpr } from '../../../../../platform/contextkey/common/contextkey.js';13import { Action2, MenuId, registerAction2 } from '../../../../../platform/actions/common/actions.js';14import { IInstantiationService } from '../../../../../platform/instantiation/common/instantiation.js';15import { PromptsType } from '../../common/promptSyntax/promptTypes.js';16import { IOpenerService } from '../../../../../platform/opener/common/opener.js';17import { ChatViewId } from '../chat.js';1819abstract class ConfigModeActionImpl extends Action2 {20public override async run(accessor: ServicesAccessor): Promise<void> {21const openerService = accessor.get(IOpenerService);22const instaService = accessor.get(IInstantiationService);2324const pickers = instaService.createInstance(PromptFilePickers);2526const placeholder = localize(27'commands.mode.select-dialog.placeholder',28'Select the chat mode file to open'29);3031const result = await pickers.selectPromptFile({ placeholder, type: PromptsType.mode, optionEdit: false });32if (result !== undefined) {33await openerService.open(result.promptFile);34}35}36}3738// Separate action `Configure Mode` link in the mode picker.3940const PICKER_CONFIGURE_MODES_ACTION_ID = 'workbench.action.chat.picker.configmode';4142class PickerConfigModeAction extends ConfigModeActionImpl {43constructor() {44super({45id: PICKER_CONFIGURE_MODES_ACTION_ID,46title: localize2('select-mode', "Configure Modes..."),47category: CHAT_CATEGORY,48f1: false,49menu: {50id: MenuId.ChatModePicker,51}52});53}54}5556/**57* Action ID for the `Configure Custom Chat Mode` action.58*/59const CONFIGURE_MODES_ACTION_ID = 'workbench.action.chat.manage.mode';6061class ManageModeAction extends ConfigModeActionImpl {62constructor() {63super({64id: CONFIGURE_MODES_ACTION_ID,65title: localize2('configure-modes', "Configure Chat Modes..."),66shortTitle: localize('configure-modes.short', "Modes"),67icon: Codicon.bookmark,68f1: true,69precondition: ContextKeyExpr.and(PromptsConfig.enabledCtx, ChatContextKeys.enabled),70category: CHAT_CATEGORY,71menu: [72{73id: CHAT_CONFIG_MENU_ID,74when: ContextKeyExpr.and(PromptsConfig.enabledCtx, ChatContextKeys.enabled, ContextKeyExpr.equals('view', ChatViewId)),75order: 12,76group: '0_level'77}78]79});80}81}828384/**85* Helper to register all the `Run Current Prompt` actions.86*/87export function registerChatModeActions(): void {88registerAction2(ManageModeAction);89registerAction2(PickerConfigModeAction);90}919293