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