Skip to content

Commit

Permalink
fix: don't show welcome view between reloads (microsoft#195928)
Browse files Browse the repository at this point in the history
* fix: rerender chat pane when provider is added

* fix: don't show welcome view between reloads
  • Loading branch information
joyceerhl committed Oct 18, 2023
1 parent 342a9e5 commit 23234ef
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
7 changes: 6 additions & 1 deletion src/vs/workbench/contrib/chat/browser/chatViewPane.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ export class ChatViewPane extends ViewPane implements IChatViewPane {
// View state for the ViewPane is currently global per-provider basically, but some other strictly per-model state will require a separate memento.
this.memento = new Memento('interactive-session-view-' + this.chatViewOptions.providerId, this.storageService);
this.viewState = this.memento.getMemento(StorageScope.WORKSPACE, StorageTarget.MACHINE) as IViewPaneState;
this._register(this.chatService.onDidRegisterProvider(({ providerId }) => {
if (providerId === this.chatViewOptions.providerId && !this._widget?.viewModel) {
this.updateModel();
}
}));
}

private updateModel(model?: IChatModel | undefined): void {
Expand All @@ -83,7 +88,7 @@ export class ChatViewPane extends ViewPane implements IChatViewPane {
}

override shouldShowWelcome(): boolean {
return !this.chatService.hasProviders();
return !this.chatService.hasSessions(this.chatViewOptions.providerId) && !this._widget?.viewModel;
}

protected override renderBody(parent: HTMLElement): void {
Expand Down
3 changes: 2 additions & 1 deletion src/vs/workbench/contrib/chat/common/chatService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,9 @@ export interface IChatService {
transferredSessionData: IChatTransferredSessionData | undefined;

onDidSubmitSlashCommand: Event<{ slashCommand: string; sessionId: string }>;
onDidRegisterProvider: Event<{ providerId: string }>;
registerProvider(provider: IChatProvider): IDisposable;
hasProviders(): boolean;
hasSessions(providerId: string): boolean;
getProviderInfos(): IChatProviderInfo[];
startSession(providerId: string, token: CancellationToken): ChatModel | undefined;
getSession(sessionId: string): IChatModel | undefined;
Expand Down
8 changes: 6 additions & 2 deletions src/vs/workbench/contrib/chat/common/chatServiceImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ export class ChatService extends Disposable implements IChatService {
private readonly _onDidDisposeSession = this._register(new Emitter<{ sessionId: string }>());
public readonly onDidDisposeSession = this._onDidDisposeSession.event;

private readonly _onDidRegisterProvider = this._register(new Emitter<{ providerId: string }>());
public readonly onDidRegisterProvider = this._onDidRegisterProvider.event;

constructor(
@IStorageService private readonly storageService: IStorageService,
@ILogService private readonly logService: ILogService,
Expand Down Expand Up @@ -742,6 +745,7 @@ export class ChatService extends Disposable implements IChatService {

this._providers.set(provider.id, provider);
this._hasProvider.set(true);
this._onDidRegisterProvider.fire({ providerId: provider.id });

Array.from(this._sessionModels.values())
.filter(model => model.providerId === provider.id)
Expand All @@ -759,8 +763,8 @@ export class ChatService extends Disposable implements IChatService {
});
}

hasProviders(): boolean {
return this._providers.size > 0;
public hasSessions(providerId: string): boolean {
return !!Object.values(this._persistedSessions).find((session) => session.providerId === providerId);
}

getProviderInfos(): IChatProviderInfo[] {
Expand Down

0 comments on commit 23234ef

Please sign in to comment.