Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/contrib/chat/browser/actions/chatFileTreeActions.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 { KeyCode, KeyMod } from '../../../../../base/common/keyCodes.js';
7
import { ServicesAccessor } from '../../../../../editor/browser/editorExtensions.js';
8
import { localize2 } from '../../../../../nls.js';
9
import { Action2, registerAction2 } from '../../../../../platform/actions/common/actions.js';
10
import { KeybindingWeight } from '../../../../../platform/keybinding/common/keybindingsRegistry.js';
11
import { CHAT_CATEGORY } from './chatActions.js';
12
import { IChatWidgetService } from '../chat.js';
13
import { ChatContextKeys } from '../../common/chatContextKeys.js';
14
import { IChatResponseViewModel, isResponseVM } from '../../common/chatViewModel.js';
15
16
export function registerChatFileTreeActions() {
17
registerAction2(class NextFileTreeAction extends Action2 {
18
constructor() {
19
super({
20
id: 'workbench.action.chat.nextFileTree',
21
title: localize2('interactive.nextFileTree.label', "Next File Tree"),
22
keybinding: {
23
primary: KeyMod.CtrlCmd | KeyCode.F9,
24
weight: KeybindingWeight.WorkbenchContrib,
25
when: ChatContextKeys.inChatSession,
26
},
27
precondition: ChatContextKeys.enabled,
28
f1: true,
29
category: CHAT_CATEGORY,
30
});
31
}
32
33
run(accessor: ServicesAccessor, ...args: any[]) {
34
navigateTrees(accessor, false);
35
}
36
});
37
38
registerAction2(class PreviousFileTreeAction extends Action2 {
39
constructor() {
40
super({
41
id: 'workbench.action.chat.previousFileTree',
42
title: localize2('interactive.previousFileTree.label', "Previous File Tree"),
43
keybinding: {
44
primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.F9,
45
weight: KeybindingWeight.WorkbenchContrib,
46
when: ChatContextKeys.inChatSession,
47
},
48
precondition: ChatContextKeys.enabled,
49
f1: true,
50
category: CHAT_CATEGORY,
51
});
52
}
53
54
run(accessor: ServicesAccessor, ...args: any[]) {
55
navigateTrees(accessor, true);
56
}
57
});
58
}
59
60
function navigateTrees(accessor: ServicesAccessor, reverse: boolean) {
61
const chatWidgetService = accessor.get(IChatWidgetService);
62
const widget = chatWidgetService.lastFocusedWidget;
63
if (!widget) {
64
return;
65
}
66
67
const focused = !widget.inputEditor.hasWidgetFocus() && widget.getFocus();
68
const focusedResponse = isResponseVM(focused) ? focused : undefined;
69
70
const currentResponse = focusedResponse ?? widget.viewModel?.getItems().reverse().find((item): item is IChatResponseViewModel => isResponseVM(item));
71
if (!currentResponse) {
72
return;
73
}
74
75
widget.reveal(currentResponse);
76
const responseFileTrees = widget.getFileTreeInfosForResponse(currentResponse);
77
const lastFocusedFileTree = widget.getLastFocusedFileTreeForResponse(currentResponse);
78
const focusIdx = lastFocusedFileTree ?
79
(lastFocusedFileTree.treeIndex + (reverse ? -1 : 1) + responseFileTrees.length) % responseFileTrees.length :
80
reverse ? responseFileTrees.length - 1 : 0;
81
82
responseFileTrees[focusIdx]?.focus();
83
}
84
85