Skip to content

Commit 4c63eb1

Browse files
committed
Simplified implementation
1 parent cf85805 commit 4c63eb1

File tree

1 file changed

+51
-64
lines changed

1 file changed

+51
-64
lines changed

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

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

718-
private async getProviderDisplayName(): Promise<string> {
719-
// For local provider, return default name
720-
if (this.provider.chatSessionType === 'local') {
721-
return 'Local';
718+
private getProviderDisplayName(): string {
719+
const contributions = this.chatSessionsService.getChatSessionContributions();
720+
const contribution = contributions.find(c => c.type === this.provider.chatSessionType);
721+
if (contribution) {
722+
return contribution.displayName;
722723
}
723-
724-
// For other providers, try to get a friendly name from the extension contributions
725-
try {
726-
const contributions = await this.chatSessionsService.getChatSessionContributions();
727-
const contribution = contributions.find(c => c.type === this.provider.chatSessionType);
728-
if (contribution) {
729-
return contribution.displayName;
730-
}
731-
} catch (error) {
732-
// Fall back to the provider type if we can't get the display name
733-
}
734-
return this.provider.chatSessionType;
724+
return '';
735725
}
736726

737727
private showEmptyMessage(): void {
@@ -745,30 +735,29 @@ class SessionsViewPane extends ViewPane {
745735
return;
746736
}
747737

748-
this.getProviderDisplayName().then(providerName => {
749-
if (!this.messageElement) {
750-
return;
751-
}
738+
const providerName = this.getProviderDisplayName();
739+
if (!providerName) {
740+
return;
741+
}
752742

753-
const messageText = nls.localize('chatSessions.noResults', "No sessions found from {0}", providerName);
743+
const messageText = nls.localize('chatSessions.noResults', "No sessions found from {0}", providerName);
754744

755-
// Clear the message element using DOM utility
756-
clearNode(this.messageElement);
745+
// Clear the message element using DOM utility
746+
clearNode(this.messageElement);
757747

758-
const messageContainer = append(this.messageElement, $('.no-sessions-message'));
748+
const messageContainer = append(this.messageElement, $('.no-sessions-message'));
759749

760-
append(messageContainer, $('.codicon.codicon-info'));
761-
const textElement = append(messageContainer, $('span'));
762-
textElement.textContent = messageText;
750+
append(messageContainer, $('.codicon.codicon-info'));
751+
const textElement = append(messageContainer, $('span'));
752+
textElement.textContent = messageText;
763753

764-
// Show the message element
765-
this.messageElement.style.display = 'block';
754+
// Show the message element
755+
this.messageElement.style.display = 'block';
766756

767-
// Hide the tree
768-
if (this.treeContainer) {
769-
this.treeContainer.style.display = 'none';
770-
}
771-
});
757+
// Hide the tree
758+
if (this.treeContainer) {
759+
this.treeContainer.style.display = 'none';
760+
}
772761
}
773762

774763
private hideMessage(): void {
@@ -782,6 +771,28 @@ class SessionsViewPane extends ViewPane {
782771
}
783772
}
784773

774+
/**
775+
* Updates the empty state message based on current tree data.
776+
* Uses the tree's existing data to avoid redundant provider calls.
777+
*/
778+
private updateEmptyStateMessage(): void {
779+
try {
780+
// Check if the tree has the provider node and get its children count
781+
if (this.tree?.hasNode(this.provider)) {
782+
const providerNode = this.tree.getNode(this.provider);
783+
const childCount = providerNode.children?.length || 0;
784+
785+
if (childCount === 0) {
786+
this.showEmptyMessage();
787+
} else {
788+
this.hideMessage();
789+
}
790+
}
791+
} catch (error) {
792+
this.logService.error('Error checking tree data for empty state:', error);
793+
}
794+
}
795+
785796
/**
786797
* Refreshes the tree data with progress indication.
787798
* Shows a progress indicator while the tree updates its children from the provider.
@@ -799,23 +810,11 @@ class SessionsViewPane extends ViewPane {
799810
},
800811
async () => {
801812
await this.tree!.updateChildren(this.provider);
802-
803-
// Check if we have any items and show/hide message accordingly
804-
try {
805-
const items = await this.provider.provideChatSessionItems(CancellationToken.None);
806-
if (items.length === 0) {
807-
this.showEmptyMessage();
808-
} else {
809-
this.hideMessage();
810-
}
811-
} catch (error) {
812-
// On error, also show the empty message for non-local providers
813-
if (this.provider.chatSessionType !== 'local') {
814-
this.showEmptyMessage();
815-
}
816-
}
817813
}
818814
);
815+
816+
// Check for empty state after refresh using tree data
817+
this.updateEmptyStateMessage();
819818
} catch (error) {
820819
// Log error but don't throw to avoid breaking the UI
821820
this.logService.error('Error refreshing chat sessions tree:', error);
@@ -839,23 +838,11 @@ class SessionsViewPane extends ViewPane {
839838
},
840839
async () => {
841840
await this.tree!.setInput(this.provider);
842-
843-
// Check if we have any items and show/hide message accordingly
844-
try {
845-
const items = await this.provider.provideChatSessionItems(CancellationToken.None);
846-
if (items.length === 0) {
847-
this.showEmptyMessage();
848-
} else {
849-
this.hideMessage();
850-
}
851-
} catch (error) {
852-
// On error, also show the empty message for non-local providers
853-
if (this.provider.chatSessionType !== 'local') {
854-
this.showEmptyMessage();
855-
}
856-
}
857841
}
858842
);
843+
844+
// Check for empty state after loading using tree data
845+
this.updateEmptyStateMessage();
859846
} catch (error) {
860847
// Log error but don't throw to avoid breaking the UI
861848
this.logService.error('Error loading chat sessions data:', error);

0 commit comments

Comments
 (0)