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 "Open in Editor" button for chat history #213518

Merged
merged 1 commit into from
May 27, 2024
Merged
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
68 changes: 48 additions & 20 deletions src/vs/workbench/contrib/chat/browser/actions/chatActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import { Codicon } from 'vs/base/common/codicons';
import { KeyCode, KeyMod } from 'vs/base/common/keyCodes';
import { DisposableStore } from 'vs/base/common/lifecycle';
import { ThemeIcon } from 'vs/base/common/themables';
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
import { EditorAction2, ServicesAccessor } from 'vs/editor/browser/editorExtensions';
Expand All @@ -13,7 +14,7 @@ import { Action2, MenuId, registerAction2 } from 'vs/platform/actions/common/act
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
import { IsLinuxContext, IsWindowsContext } from 'vs/platform/contextkey/common/contextkeys';
import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
import { IQuickInputService, IQuickPickItem } from 'vs/platform/quickinput/common/quickInput';
import { IQuickInputButton, IQuickInputService, IQuickPickItem } from 'vs/platform/quickinput/common/quickInput';
import { ViewAction } from 'vs/workbench/browser/parts/views/viewPane';
import { CHAT_VIEW_ID, IChatWidgetService, showChatView } from 'vs/workbench/contrib/chat/browser/chat';
import { IChatEditorOptions } from 'vs/workbench/contrib/chat/browser/chatEditor';
Expand All @@ -24,7 +25,7 @@ import { CONTEXT_CHAT_INPUT_CURSOR_AT_TOP, CONTEXT_CHAT_LOCATION, CONTEXT_IN_CHA
import { IChatDetail, IChatService } from 'vs/workbench/contrib/chat/common/chatService';
import { IChatRequestViewModel, IChatResponseViewModel, isRequestVM } from 'vs/workbench/contrib/chat/common/chatViewModel';
import { IChatWidgetHistoryService } from 'vs/workbench/contrib/chat/common/chatWidgetHistoryService';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { ACTIVE_GROUP, IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IViewsService } from 'vs/workbench/services/views/common/viewsService';

export interface IChatViewTitleActionContext {
Expand Down Expand Up @@ -124,28 +125,55 @@ class ChatHistoryAction extends ViewAction<ChatViewPane> {
const chatService = accessor.get(IChatService);
const quickInputService = accessor.get(IQuickInputService);
const viewsService = accessor.get(IViewsService);
const editorService = accessor.get(IEditorService);
const items = chatService.getHistory();
const picks = items.map(i => (<IQuickPickItem & { chat: IChatDetail }>{

const openInEditorButton: IQuickInputButton = {
iconClass: ThemeIcon.asClassName(Codicon.file),
tooltip: localize('interactiveSession.history.editor', "Open in Editor"),
};
const deleteButton: IQuickInputButton = {
iconClass: ThemeIcon.asClassName(Codicon.x),
tooltip: localize('interactiveSession.history.delete', "Delete"),
};

interface IChatPickerItem extends IQuickPickItem {
chat: IChatDetail;
}
const picks: IChatPickerItem[] = items.map((i): IChatPickerItem => ({
label: i.title,
chat: i,
buttons: [{
iconClass: ThemeIcon.asClassName(Codicon.x),
tooltip: localize('interactiveSession.history.delete', "Delete"),
}]
buttons: [
openInEditorButton,
deleteButton
]
}));
const selection = await quickInputService.pick(picks,
{
placeHolder: localize('interactiveSession.history.pick', "Switch to chat"),
onDidTriggerItemButton: context => {
chatService.removeHistoryEntry(context.item.chat.sessionId);
context.removeItem();
}
});
if (selection) {
const sessionId = selection.chat.sessionId;
const view = await viewsService.openView(CHAT_VIEW_ID) as ChatViewPane;
view.loadSession(sessionId);
}
const store = new DisposableStore();
const picker = store.add(quickInputService.createQuickPick<IChatPickerItem>());
picker.placeholder = localize('interactiveSession.history.pick', "Switch to chat");
picker.items = picks;
store.add(picker.onDidTriggerItemButton(context => {
if (context.button === openInEditorButton) {
editorService.openEditor({ resource: ChatEditorInput.getNewEditorUri(), options: <IChatEditorOptions>{ target: { sessionId: context.item.chat.sessionId }, pinned: true } }, ACTIVE_GROUP);
picker.hide();
} else if (context.button === deleteButton) {
chatService.removeHistoryEntry(context.item.chat.sessionId);
picker.items = picks.filter(i => i !== context.item);
}
}));
store.add(picker.onDidAccept(async () => {
try {
const item = picker.selectedItems[0];
const sessionId = item.chat.sessionId;
const view = await viewsService.openView(CHAT_VIEW_ID) as ChatViewPane;
view.loadSession(sessionId);
} finally {
picker.hide();
}
}));
store.add(picker.onDidHide(() => store.dispose()));

picker.show();
}
}

Expand Down
Loading