add rerun action to terminal chat to align w editor (#236381)

This commit is contained in:
Megan Rogge
2024-12-17 12:57:14 -06:00
committed by GitHub
parent 625bae2375
commit d3b582676f
3 changed files with 48 additions and 0 deletions
@@ -17,6 +17,7 @@ export const enum TerminalChatCommandId {
InsertCommand = 'workbench.action.terminal.chat.insertCommand',
InsertFirstCommand = 'workbench.action.terminal.chat.insertFirstCommand',
ViewInChat = 'workbench.action.terminal.chat.viewInChat',
RerunRequest = 'workbench.action.terminal.chat.rerunRequest',
}
export const MENU_TERMINAL_CHAT_WIDGET_INPUT_SIDE_TOOLBAR = MenuId.for('terminalChatWidget');
@@ -8,6 +8,9 @@ import { KeyCode, KeyMod } from '../../../../../base/common/keyCodes.js';
import { localize2 } from '../../../../../nls.js';
import { ContextKeyExpr } from '../../../../../platform/contextkey/common/contextkey.js';
import { KeybindingWeight } from '../../../../../platform/keybinding/common/keybindingsRegistry.js';
import { IChatWidgetService } from '../../../chat/browser/chat.js';
import { ChatAgentLocation } from '../../../chat/common/chatAgents.js';
import { IChatService } from '../../../chat/common/chatService.js';
import { AbstractInlineChatAction } from '../../../inlineChat/browser/inlineChatActions.js';
import { isDetachedTerminalInstance } from '../../../terminal/browser/terminal.js';
import { registerActiveXtermAction } from '../../../terminal/browser/terminalActions.js';
@@ -209,6 +212,48 @@ registerActiveXtermAction({
}
});
registerActiveXtermAction({
id: TerminalChatCommandId.RerunRequest,
title: localize2('chat.rerun.label', "Rerun Request"),
f1: false,
icon: Codicon.refresh,
category: AbstractInlineChatAction.category,
precondition: ContextKeyExpr.and(
ContextKeyExpr.or(TerminalContextKeys.processSupported, TerminalContextKeys.terminalHasBeenCreated),
TerminalChatContextKeys.requestActive.negate(),
),
keybinding: {
weight: KeybindingWeight.WorkbenchContrib,
primary: KeyMod.CtrlCmd | KeyCode.KeyR
},
menu: {
id: MENU_TERMINAL_CHAT_WIDGET_STATUS,
group: '0_main',
order: 5,
when: ContextKeyExpr.and(TerminalChatContextKeys.inputHasText.toNegated(), TerminalChatContextKeys.requestActive.negate())
},
run: async (_xterm, _accessor, activeInstance) => {
const chatService = _accessor.get(IChatService);
const chatWidgetService = _accessor.get(IChatWidgetService);
const contr = TerminalChatController.activeChatController;
const model = contr?.terminalChatWidget?.inlineChatWidget.chatWidget.viewModel?.model;
if (!model) {
return;
}
const lastRequest = model.getRequests().at(-1);
if (lastRequest) {
const widget = chatWidgetService.getWidgetBySessionId(model.sessionId);
await chatService.resendRequest(lastRequest, {
noCommandDetection: false,
attempt: lastRequest.attempt + 1,
location: ChatAgentLocation.Terminal,
userSelectedModelId: widget?.input.currentLanguageModel
});
}
}
});
registerActiveXtermAction({
id: TerminalChatCommandId.ViewInChat,
title: localize2('viewInChat', 'View in Chat'),
@@ -127,6 +127,8 @@ export class TerminalChatWidget extends Disposable {
menu: MENU_TERMINAL_CHAT_WIDGET_STATUS,
options: {
buttonConfigProvider: action => ({
showLabel: action.id !== TerminalChatCommandId.RerunRequest,
showIcon: action.id === TerminalChatCommandId.RerunRequest,
isSecondary: action.id !== TerminalChatCommandId.RunCommand && action.id !== TerminalChatCommandId.RunFirstCommand
})
}