Skip to content

Commit 38bf4ce

Browse files
authored
wait for extension activation in getChatSessionContributions() (microsoft#259126)
* wait for extension activation in getChatSessionContributions() * fix promises
1 parent 1208bca commit 38bf4ce

File tree

5 files changed

+16
-12
lines changed

5 files changed

+16
-12
lines changed

src/vs/workbench/contrib/chat/browser/actions/chatActions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ export function registerChatActions() {
567567
// Use the new Promise-based API to get chat sessions
568568
const cancellationToken = new CancellationTokenSource();
569569
try {
570-
const providers = chatSessionsService.getChatSessionContributions();
570+
const providers = await chatSessionsService.getChatSessionContributions();
571571
const providerNSessions: { providerType: string; session: IChatSessionItem }[] = [];
572572

573573
for (const provider of providers) {

src/vs/workbench/contrib/chat/browser/chatEditor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ export class ChatEditor extends EditorPane {
130130
if (input.resource.scheme === Schemas.vscodeChatSession) {
131131
const identifier = ChatSessionUri.parse(input.resource);
132132
if (identifier) {
133-
const contributions = this.chatSessionsService.getChatSessionContributions();
133+
const contributions = await this.chatSessionsService.getChatSessionContributions([input.resource.authority]);
134134
const contribution = contributions.find(c => c.type === identifier.chatSessionType);
135135
if (contribution) {
136136
this.widget.lockToCodingAgent(contribution.name, contribution.displayName);

src/vs/workbench/contrib/chat/browser/chatSessions.contribution.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,11 @@ export class ChatSessionsService extends Disposable implements IChatSessionsServ
295295
return disposable;
296296
}
297297

298-
getChatSessionContributions(): IChatSessionsExtensionPoint[] {
298+
async getChatSessionContributions(waitForActivation?: string[]): Promise<IChatSessionsExtensionPoint[]> {
299+
await this._extensionService.whenInstalledExtensionsRegistered();
300+
if (waitForActivation) {
301+
await Promise.all(waitForActivation.map(id => this._extensionService.activateByEvent(`onChatSession:${id}`)));
302+
}
299303
return Array.from(this._contributions.values()).filter(contribution =>
300304
this._isContributionAvailable(contribution)
301305
);

src/vs/workbench/contrib/chat/browser/chatSessions.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -715,16 +715,16 @@ class SessionsViewPane extends ViewPane {
715715
}
716716
}
717717

718-
private getProviderDisplayName(): string {
719-
const contributions = this.chatSessionsService.getChatSessionContributions();
718+
private async getProviderDisplayName(): Promise<string> {
719+
const contributions = await this.chatSessionsService.getChatSessionContributions();
720720
const contribution = contributions.find(c => c.type === this.provider.chatSessionType);
721721
if (contribution) {
722722
return contribution.displayName;
723723
}
724724
return '';
725725
}
726726

727-
private showEmptyMessage(): void {
727+
private async showEmptyMessage(): Promise<void> {
728728
if (!this.messageElement) {
729729
return;
730730
}
@@ -735,7 +735,7 @@ class SessionsViewPane extends ViewPane {
735735
return;
736736
}
737737

738-
const providerName = this.getProviderDisplayName();
738+
const providerName = await this.getProviderDisplayName();
739739
if (!providerName) {
740740
return;
741741
}
@@ -775,15 +775,15 @@ class SessionsViewPane extends ViewPane {
775775
* Updates the empty state message based on current tree data.
776776
* Uses the tree's existing data to avoid redundant provider calls.
777777
*/
778-
private updateEmptyStateMessage(): void {
778+
private async updateEmptyStateMessage(): Promise<void> {
779779
try {
780780
// Check if the tree has the provider node and get its children count
781781
if (this.tree?.hasNode(this.provider)) {
782782
const providerNode = this.tree.getNode(this.provider);
783783
const childCount = providerNode.children?.length || 0;
784784

785785
if (childCount === 0) {
786-
this.showEmptyMessage();
786+
await this.showEmptyMessage();
787787
} else {
788788
this.hideMessage();
789789
}
@@ -814,7 +814,7 @@ class SessionsViewPane extends ViewPane {
814814
);
815815

816816
// Check for empty state after refresh using tree data
817-
this.updateEmptyStateMessage();
817+
await this.updateEmptyStateMessage();
818818
} catch (error) {
819819
// Log error but don't throw to avoid breaking the UI
820820
this.logService.error('Error refreshing chat sessions tree:', error);
@@ -842,7 +842,7 @@ class SessionsViewPane extends ViewPane {
842842
);
843843

844844
// Check for empty state after loading using tree data
845-
this.updateEmptyStateMessage();
845+
await this.updateEmptyStateMessage();
846846
} catch (error) {
847847
// Log error but don't throw to avoid breaking the UI
848848
this.logService.error('Error loading chat sessions data:', error);

src/vs/workbench/contrib/chat/common/chatSessionsService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export interface IChatSessionsService {
6868
readonly onDidChangeSessionItems: Event<string>;
6969
readonly onDidChangeAvailability: Event<void>;
7070
registerContribution(contribution: IChatSessionsExtensionPoint): IDisposable;
71-
getChatSessionContributions(): IChatSessionsExtensionPoint[];
71+
getChatSessionContributions(waitForActivation?: string[]): Promise<IChatSessionsExtensionPoint[]>;
7272
canResolveItemProvider(chatSessionType: string): Promise<boolean>;
7373
canResolveContentProvider(chatSessionType: string): Promise<boolean>;
7474
getChatSessionItemProviders(): IChatSessionItemProvider[];

0 commit comments

Comments
 (0)