mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 21:09:43 +00:00
Implement "delete" action for chat history (#183609)
This commit is contained in:
parent
78643b05d5
commit
5f37021eeb
|
@ -5,6 +5,7 @@
|
|||
|
||||
import { Codicon } from 'vs/base/common/codicons';
|
||||
import { KeyCode, KeyMod } from 'vs/base/common/keyCodes';
|
||||
import { ThemeIcon } from 'vs/base/common/themables';
|
||||
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
|
||||
import { EditorAction, EditorAction2, ServicesAccessor, registerEditorAction } from 'vs/editor/browser/editorExtensions';
|
||||
import { EditorContextKeys } from 'vs/editor/common/editorContextKeys';
|
||||
|
@ -185,9 +186,20 @@ export function getHistoryAction(viewId: string, providerId: string) {
|
|||
const items = chatService.getHistory();
|
||||
const picks = items.map(i => (<IQuickPickItem & { chat: IChatDetail }>{
|
||||
label: i.title,
|
||||
chat: i
|
||||
chat: i,
|
||||
buttons: [{
|
||||
iconClass: ThemeIcon.asClassName(Codicon.x),
|
||||
tooltip: localize('interactiveSession.history.delete', "Delete"),
|
||||
}]
|
||||
}));
|
||||
const selection = await quickInputService.pick(picks, { placeHolder: localize('interactiveSession.history.pick', "Select a chat session to restore") });
|
||||
const selection = await quickInputService.pick(picks,
|
||||
{
|
||||
placeHolder: localize('interactiveSession.history.pick', "Select a chat session to restore"),
|
||||
onDidTriggerItemButton: context => {
|
||||
chatService.removeHistoryEntry(context.item.chat.sessionId);
|
||||
context.removeItem();
|
||||
}
|
||||
});
|
||||
if (selection) {
|
||||
const sessionId = selection.chat.sessionId;
|
||||
await editorService.openEditor({
|
||||
|
|
|
@ -195,6 +195,7 @@ export interface IChatService {
|
|||
addCompleteRequest(sessionId: string, message: string, response: IChatCompleteResponse): void;
|
||||
sendRequestToProvider(sessionId: string, message: IChatDynamicRequest): void;
|
||||
getHistory(): IChatDetail[];
|
||||
removeHistoryEntry(sessionId: string): void;
|
||||
|
||||
onDidPerformUserAction: Event<IChatUserActionEvent>;
|
||||
notifyUserAction(event: IChatUserActionEvent): void;
|
||||
|
|
|
@ -103,7 +103,7 @@ type ChatTerminalClassification = {
|
|||
comment: 'Provides insight into the usage of Chat features.';
|
||||
};
|
||||
|
||||
const maxPersistedSessions = 20;
|
||||
const maxPersistedSessions = 25;
|
||||
|
||||
export class ChatService extends Disposable implements IChatService {
|
||||
declare _serviceBrand: undefined;
|
||||
|
@ -147,7 +147,9 @@ export class ChatService extends Disposable implements IChatService {
|
|||
let allSessions: (ChatModel | ISerializableChatData)[] = Array.from(this._sessionModels.values())
|
||||
.filter(session => session.getRequests().length > 0);
|
||||
allSessions = allSessions.concat(
|
||||
Object.values(this._persistedSessions).filter(session => session.requests.length));
|
||||
Object.values(this._persistedSessions)
|
||||
.filter(session => !this._sessionModels.has(session.sessionId))
|
||||
.filter(session => session.requests.length));
|
||||
allSessions.sort((a, b) => (b.creationDate ?? 0) - (a.creationDate ?? 0));
|
||||
allSessions = allSessions.slice(0, maxPersistedSessions);
|
||||
this.trace('onWillSaveState', `Persisting ${allSessions.length} sessions`);
|
||||
|
@ -219,12 +221,18 @@ export class ChatService extends Disposable implements IChatService {
|
|||
const sessions = Object.values(this._persistedSessions);
|
||||
sessions.sort((a, b) => (b.creationDate ?? 0) - (a.creationDate ?? 0));
|
||||
|
||||
return sessions.map(item => {
|
||||
return <IChatDetail>{
|
||||
sessionId: item.sessionId,
|
||||
title: item.requests[0]?.message || '',
|
||||
};
|
||||
});
|
||||
return sessions
|
||||
.filter(session => !this._sessionModels.has(session.sessionId))
|
||||
.map(item => {
|
||||
return <IChatDetail>{
|
||||
sessionId: item.sessionId,
|
||||
title: item.requests[0]?.message || '',
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
removeHistoryEntry(sessionId: string): void {
|
||||
delete this._persistedSessions[sessionId];
|
||||
}
|
||||
|
||||
startSession(providerId: string, token: CancellationToken): ChatModel {
|
||||
|
@ -267,11 +275,6 @@ export class ChatService extends Disposable implements IChatService {
|
|||
}
|
||||
|
||||
if (!session) {
|
||||
if (sessionHistory) {
|
||||
// sessionHistory was not used, so store it for later
|
||||
this._persistedSessions[sessionHistory.sessionId] = sessionHistory;
|
||||
}
|
||||
|
||||
this.trace('startSession', 'Provider returned no session');
|
||||
return undefined;
|
||||
}
|
||||
|
@ -301,7 +304,6 @@ export class ChatService extends Disposable implements IChatService {
|
|||
return undefined;
|
||||
}
|
||||
|
||||
delete this._persistedSessions[sessionId];
|
||||
return this._startSession(sessionData.providerId, sessionData, CancellationToken.None);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue