Skip to content

Commit

Permalink
fix: rerender welcome view when chat provider is disposed (microsoft#…
Browse files Browse the repository at this point in the history
  • Loading branch information
joyceerhl committed Jan 30, 2024
1 parent 7fd1edb commit c9f0aa5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/vs/workbench/contrib/chat/browser/chatViewPane.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export class ChatViewPane extends ViewPane implements IChatViewPane {
private memento: Memento;
private readonly viewState: IViewPaneState;
private didProviderRegistrationFail = false;
private didUnregisterProvider = false;

constructor(
private readonly chatViewOptions: IChatViewOptions,
Expand Down Expand Up @@ -78,12 +79,20 @@ export class ChatViewPane extends ViewPane implements IChatViewPane {
try {
this._widget.setVisible(false);
this.updateModel(model);
this.didProviderRegistrationFail = false;
this.didUnregisterProvider = false;
this._onDidChangeViewWelcomeState.fire();
} finally {
this.widget.setVisible(true);
}
}
}));
this._register(this.chatService.onDidUnregisterProvider(({ providerId }) => {
if (providerId === this.chatViewOptions.providerId) {
this.didUnregisterProvider = true;
this._onDidChangeViewWelcomeState.fire();
}
}));
}

private updateModel(model?: IChatModel | undefined, viewState?: IViewPaneState): void {
Expand All @@ -102,7 +111,7 @@ export class ChatViewPane extends ViewPane implements IChatViewPane {

override shouldShowWelcome(): boolean {
const noPersistedSessions = !this.chatService.hasSessions(this.chatViewOptions.providerId);
return !this._widget?.viewModel && (noPersistedSessions || this.didProviderRegistrationFail);
return this.didUnregisterProvider || !this._widget?.viewModel && (noPersistedSessions || this.didProviderRegistrationFail);
}

private getSessionId() {
Expand Down
1 change: 1 addition & 0 deletions src/vs/workbench/contrib/chat/common/chatService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ export interface IChatService {

onDidSubmitAgent: Event<{ agent: IChatAgentData; slashCommand: IChatAgentCommand; sessionId: string }>;
onDidRegisterProvider: Event<{ providerId: string }>;
onDidUnregisterProvider: Event<{ providerId: string }>;
registerProvider(provider: IChatProvider): IDisposable;
hasSessions(providerId: string): boolean;
getProviderInfos(): IChatProviderInfo[];
Expand Down
4 changes: 4 additions & 0 deletions src/vs/workbench/contrib/chat/common/chatServiceImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ export class ChatService extends Disposable implements IChatService {
private readonly _onDidRegisterProvider = this._register(new Emitter<{ providerId: string }>());
public readonly onDidRegisterProvider = this._onDidRegisterProvider.event;

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

constructor(
@IStorageService private readonly storageService: IStorageService,
@ILogService private readonly logService: ILogService,
Expand Down Expand Up @@ -718,6 +721,7 @@ export class ChatService extends Disposable implements IChatService {
Array.from(this._sessionModels.values())
.filter(model => model.providerId === provider.id)
.forEach(model => model.deinitialize());
this._onDidUnregisterProvider.fire({ providerId: provider.id });
});
}

Expand Down

0 comments on commit c9f0aa5

Please sign in to comment.