Skip to content

Commit 0a03218

Browse files
authored
Fix two chat history bugs (microsoft#216848)
* Fix "show chats" before chat view is loaded Fix microsoft/vscode-copilot-release#1079 * Fix microsoft/vscode-copilot-release#1327
1 parent 7cee428 commit 0a03218

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

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

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,12 @@ import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
1515
import { IsLinuxContext, IsWindowsContext } from 'vs/platform/contextkey/common/contextkeys';
1616
import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
1717
import { IQuickInputButton, IQuickInputService, IQuickPickItem } from 'vs/platform/quickinput/common/quickInput';
18-
import { ViewAction } from 'vs/workbench/browser/parts/views/viewPane';
1918
import { CHAT_VIEW_ID, IChatWidgetService, showChatView } from 'vs/workbench/contrib/chat/browser/chat';
2019
import { IChatEditorOptions } from 'vs/workbench/contrib/chat/browser/chatEditor';
2120
import { ChatEditorInput } from 'vs/workbench/contrib/chat/browser/chatEditorInput';
2221
import { ChatViewPane } from 'vs/workbench/contrib/chat/browser/chatViewPane';
2322
import { ChatAgentLocation } from 'vs/workbench/contrib/chat/common/chatAgents';
24-
import { CONTEXT_CHAT_INPUT_CURSOR_AT_TOP, CONTEXT_CHAT_LOCATION, CONTEXT_IN_CHAT_INPUT, CONTEXT_IN_CHAT_SESSION, CONTEXT_CHAT_ENABLED } from 'vs/workbench/contrib/chat/common/chatContextKeys';
23+
import { CONTEXT_CHAT_ENABLED, CONTEXT_CHAT_INPUT_CURSOR_AT_TOP, CONTEXT_CHAT_LOCATION, CONTEXT_IN_CHAT_INPUT, CONTEXT_IN_CHAT_SESSION } from 'vs/workbench/contrib/chat/common/chatContextKeys';
2524
import { IChatDetail, IChatService } from 'vs/workbench/contrib/chat/common/chatService';
2625
import { IChatRequestViewModel, IChatResponseViewModel, isRequestVM } from 'vs/workbench/contrib/chat/common/chatViewModel';
2726
import { IChatWidgetHistoryService } from 'vs/workbench/contrib/chat/common/chatWidgetHistoryService';
@@ -102,10 +101,9 @@ class OpenChatGlobalAction extends Action2 {
102101
}
103102
}
104103

105-
class ChatHistoryAction extends ViewAction<ChatViewPane> {
104+
class ChatHistoryAction extends Action2 {
106105
constructor() {
107106
super({
108-
viewId: CHAT_VIEW_ID,
109107
id: `workbench.action.chat.history`,
110108
title: localize2('chat.history.label', "Show Chats..."),
111109
menu: {
@@ -121,12 +119,11 @@ class ChatHistoryAction extends ViewAction<ChatViewPane> {
121119
});
122120
}
123121

124-
async runInView(accessor: ServicesAccessor, view: ChatViewPane) {
122+
async run(accessor: ServicesAccessor) {
125123
const chatService = accessor.get(IChatService);
126124
const quickInputService = accessor.get(IQuickInputService);
127125
const viewsService = accessor.get(IViewsService);
128126
const editorService = accessor.get(IEditorService);
129-
const items = chatService.getHistory();
130127

131128
const openInEditorButton: IQuickInputButton = {
132129
iconClass: ThemeIcon.asClassName(Codicon.file),
@@ -140,25 +137,30 @@ class ChatHistoryAction extends ViewAction<ChatViewPane> {
140137
interface IChatPickerItem extends IQuickPickItem {
141138
chat: IChatDetail;
142139
}
143-
const picks: IChatPickerItem[] = items.map((i): IChatPickerItem => ({
144-
label: i.title,
145-
chat: i,
146-
buttons: [
147-
openInEditorButton,
148-
deleteButton
149-
]
150-
}));
140+
141+
const getPicks = () => {
142+
const items = chatService.getHistory();
143+
return items.map((i): IChatPickerItem => ({
144+
label: i.title,
145+
chat: i,
146+
buttons: [
147+
openInEditorButton,
148+
deleteButton
149+
]
150+
}));
151+
};
152+
151153
const store = new DisposableStore();
152154
const picker = store.add(quickInputService.createQuickPick<IChatPickerItem>());
153155
picker.placeholder = localize('interactiveSession.history.pick', "Switch to chat");
154-
picker.items = picks;
156+
picker.items = getPicks();
155157
store.add(picker.onDidTriggerItemButton(context => {
156158
if (context.button === openInEditorButton) {
157159
editorService.openEditor({ resource: ChatEditorInput.getNewEditorUri(), options: <IChatEditorOptions>{ target: { sessionId: context.item.chat.sessionId }, pinned: true } }, ACTIVE_GROUP);
158160
picker.hide();
159161
} else if (context.button === deleteButton) {
160162
chatService.removeHistoryEntry(context.item.chat.sessionId);
161-
picker.items = picks.filter(i => i !== context.item);
163+
picker.items = getPicks();
162164
}
163165
}));
164166
store.add(picker.onDidAccept(async () => {

0 commit comments

Comments
 (0)