diff --git a/src/vs/workbench/contrib/chat/browser/chatInputPart.ts b/src/vs/workbench/contrib/chat/browser/chatInputPart.ts index 17d6f47866aba..ce0e53fa4ee3b 100644 --- a/src/vs/workbench/contrib/chat/browser/chatInputPart.ts +++ b/src/vs/workbench/contrib/chat/browser/chatInputPart.ts @@ -174,7 +174,7 @@ export class ChatInputPart extends Disposable implements IHistoryNavigationWidge } setState(inputValue: string | undefined): void { - const history = this.historyService.getHistory(); + const history = this.historyService.getHistory(this.location); this.history = new HistoryNavigator(history, 50); if (typeof inputValue === 'string') { @@ -523,7 +523,7 @@ export class ChatInputPart extends Disposable implements IHistoryNavigationWidge saveState(): void { const inputHistory = this.history.getHistory(); - this.historyService.saveHistory(inputHistory); + this.historyService.saveHistory(this.location, inputHistory); } } diff --git a/src/vs/workbench/contrib/chat/common/chatWidgetHistoryService.ts b/src/vs/workbench/contrib/chat/common/chatWidgetHistoryService.ts index f9431569db7ac..01716421e7bdf 100644 --- a/src/vs/workbench/contrib/chat/common/chatWidgetHistoryService.ts +++ b/src/vs/workbench/contrib/chat/common/chatWidgetHistoryService.ts @@ -7,6 +7,7 @@ import { Emitter, Event } from 'vs/base/common/event'; import { createDecorator } from 'vs/platform/instantiation/common/instantiation'; import { IStorageService, StorageScope, StorageTarget } from 'vs/platform/storage/common/storage'; import { Memento } from 'vs/workbench/common/memento'; +import { ChatAgentLocation } from 'vs/workbench/contrib/chat/common/chatAgents'; import { CHAT_PROVIDER_ID } from 'vs/workbench/contrib/chat/common/chatParticipantContribTypes'; export interface IChatHistoryEntry { @@ -21,8 +22,8 @@ export interface IChatWidgetHistoryService { readonly onDidClearHistory: Event; clearHistory(): void; - getHistory(): IChatHistoryEntry[]; - saveHistory(history: IChatHistoryEntry[]): void; + getHistory(location: ChatAgentLocation): IChatHistoryEntry[]; + saveHistory(location: ChatAgentLocation, history: IChatHistoryEntry[]): void; } interface IChatHistory { @@ -51,15 +52,23 @@ export class ChatWidgetHistoryService implements IChatWidgetHistoryService { this.viewState = loadedState; } - getHistory(): IChatHistoryEntry[] { - return this.viewState.history?.[CHAT_PROVIDER_ID] ?? []; + getHistory(location: ChatAgentLocation): IChatHistoryEntry[] { + const key = this.getKey(location); + return this.viewState.history?.[key] ?? []; } - saveHistory(history: IChatHistoryEntry[]): void { + private getKey(location: ChatAgentLocation): string { + // Preserve history for panel by continuing to use the same old provider id. Use the location as a key for other chat locations. + return location === ChatAgentLocation.Panel ? CHAT_PROVIDER_ID : location; + } + + saveHistory(location: ChatAgentLocation, history: IChatHistoryEntry[]): void { if (!this.viewState.history) { this.viewState.history = {}; } - this.viewState.history[CHAT_PROVIDER_ID] = history; + + const key = this.getKey(location); + this.viewState.history[key] = history; this.memento.saveMemento(); }