Skip to content

Commit bf71412

Browse files
authored
change first checkpoint to something more friendly (#306178)
1 parent d7ebb2c commit bf71412

4 files changed

Lines changed: 40 additions & 1 deletion

File tree

src/vs/workbench/contrib/chat/browser/actions/chatForkActions.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export function registerChatForkActions() {
3939
order: 3,
4040
when: ContextKeyExpr.and(
4141
ChatContextKeys.isRequest,
42+
ChatContextKeys.isFirstRequest.negate(),
4243
ContextKeyExpr.or(
4344
ChatContextKeys.lockedToCodingAgent.negate(),
4445
ChatContextKeys.chatSessionSupportsFork

src/vs/workbench/contrib/chat/browser/chatEditing/chatEditingActions.ts

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ registerAction2(class RestoreCheckpointAction extends Action2 {
583583
id: MenuId.ChatMessageCheckpoint,
584584
group: 'navigation',
585585
order: 2,
586-
when: ContextKeyExpr.and(ChatContextKeys.isRequest, ChatContextKeys.lockedToCodingAgent.negate())
586+
when: ContextKeyExpr.and(ChatContextKeys.isRequest, ChatContextKeys.lockedToCodingAgent.negate(), ChatContextKeys.isFirstRequest.negate())
587587
}
588588
]
589589
});
@@ -617,6 +617,42 @@ registerAction2(class RestoreCheckpointAction extends Action2 {
617617
}
618618
});
619619

620+
registerAction2(class StartOverAction extends Action2 {
621+
constructor() {
622+
super({
623+
id: 'workbench.action.chat.startOver',
624+
title: localize2('chat.startOver.label', "Start Over"),
625+
tooltip: localize2('chat.startOver.tooltip', "Clears the chat and undoes all changes"),
626+
f1: false,
627+
category: CHAT_CATEGORY,
628+
menu: [
629+
{
630+
id: MenuId.ChatMessageCheckpoint,
631+
group: 'navigation',
632+
order: 2,
633+
when: ContextKeyExpr.and(ChatContextKeys.isRequest, ChatContextKeys.lockedToCodingAgent.negate(), ChatContextKeys.isFirstRequest)
634+
}
635+
]
636+
});
637+
}
638+
639+
async run(accessor: ServicesAccessor, ...args: unknown[]) {
640+
let item = args[0] as ChatTreeItem | undefined;
641+
const chatWidgetService = accessor.get(IChatWidgetService);
642+
const widget = (isChatTreeItem(item) && chatWidgetService.getWidgetBySessionResource(item.sessionResource)) || chatWidgetService.lastFocusedWidget;
643+
if (!isResponseVM(item) && !isRequestVM(item)) {
644+
item = widget?.getFocus();
645+
}
646+
647+
if (!item) {
648+
return;
649+
}
650+
651+
widget?.viewModel?.model.setCheckpoint(item.id);
652+
await restoreSnapshotWithConfirmation(accessor, item);
653+
}
654+
});
655+
620656
registerAction2(class RestoreLastCheckpoint extends Action2 {
621657
constructor() {
622658
super({

src/vs/workbench/contrib/chat/browser/widget/chatListRenderer.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,7 @@ export class ChatListItemRenderer extends Disposable implements ITreeRenderer<Ch
709709
ChatContextKeys.isResponse.bindTo(templateData.contextKeyService).set(isResponseVM(element));
710710
ChatContextKeys.itemId.bindTo(templateData.contextKeyService).set(element.id);
711711
ChatContextKeys.isRequest.bindTo(templateData.contextKeyService).set(isRequestVM(element));
712+
ChatContextKeys.isFirstRequest.bindTo(templateData.contextKeyService).set(isRequestVM(element) && this.viewModel?.model.getRequests()[0]?.id === element.id);
712713
ChatContextKeys.isPendingRequest.bindTo(templateData.contextKeyService).set(isRequestVM(element) && !!element.pendingKind);
713714
ChatContextKeys.responseDetectedAgentCommand.bindTo(templateData.contextKeyService).set(isResponseVM(element) && element.agentOrSlashCommandDetected);
714715
if (isResponseVM(element)) {

src/vs/workbench/contrib/chat/common/actions/chatContextKeys.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export namespace ChatContextKeys {
3030

3131
export const isResponse = new RawContextKey<boolean>('chatResponse', false, { type: 'boolean', description: localize('chatResponse', "The chat item is a response.") });
3232
export const isRequest = new RawContextKey<boolean>('chatRequest', false, { type: 'boolean', description: localize('chatRequest', "The chat item is a request") });
33+
export const isFirstRequest = new RawContextKey<boolean>('chatFirstRequest', false, { type: 'boolean', description: localize('chatFirstRequest', "The chat item is the first request in the session.") });
3334
export const isPendingRequest = new RawContextKey<boolean>('chatRequestIsPending', false, { type: 'boolean', description: localize('chatRequestIsPending', "True when the chat request item is pending in the queue.") });
3435
export const itemId = new RawContextKey<string>('chatItemId', '', { type: 'string', description: localize('chatItemId', "The id of the chat item.") });
3536
export const lastItemId = new RawContextKey<string[]>('chatLastItemId', [], { type: 'string', description: localize('chatLastItemId', "The id of the last chat item.") });

0 commit comments

Comments
 (0)