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

Fix shared input history between chat locations #213111

Merged
merged 1 commit into from
May 21, 2024
Merged
Show file tree
Hide file tree
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
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
Loading