Skip to content

Commit

Permalink
Fix shared input history between chat locations (#213111)
Browse files Browse the repository at this point in the history
  • Loading branch information
roblourens authored May 21, 2024
1 parent 2b3e929 commit 51591f8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/vs/workbench/contrib/chat/browser/chatInputPart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down Expand Up @@ -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);
}
}

Expand Down
21 changes: 15 additions & 6 deletions src/vs/workbench/contrib/chat/common/chatWidgetHistoryService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -21,8 +22,8 @@ export interface IChatWidgetHistoryService {
readonly onDidClearHistory: Event<void>;

clearHistory(): void;
getHistory(): IChatHistoryEntry[];
saveHistory(history: IChatHistoryEntry[]): void;
getHistory(location: ChatAgentLocation): IChatHistoryEntry[];
saveHistory(location: ChatAgentLocation, history: IChatHistoryEntry[]): void;
}

interface IChatHistory {
Expand Down Expand Up @@ -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();
}

Expand Down

0 comments on commit 51591f8

Please sign in to comment.