Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 4 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
}
Expand Down
Loading