Skip to content

Commit cf85805

Browse files
committed
Chat sessions empty message
1 parent c915ea1 commit cf85805

File tree

2 files changed

+124
-1
lines changed

2 files changed

+124
-1
lines changed

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

Lines changed: 105 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import { FuzzyScore } from '../../../../base/common/filters.js';
3434
import { ResourceLabels, IResourceLabel } from '../../../browser/labels.js';
3535
import { ActionBar } from '../../../../base/browser/ui/actionbar/actionbar.js';
3636
import { Disposable } from '../../../../base/common/lifecycle.js';
37-
import { append, $, getActiveWindow } from '../../../../base/browser/dom.js';
37+
import { append, $, getActiveWindow, clearNode } from '../../../../base/browser/dom.js';
3838
import { URI } from '../../../../base/common/uri.js';
3939
import { IEditorGroupsService, IEditorGroup } from '../../../services/editor/common/editorGroupsService.js';
4040
import { GroupModelChangeKind } from '../../../common/editor.js';
@@ -673,6 +673,7 @@ class SessionsViewPane extends ViewPane {
673673
private treeContainer?: HTMLElement;
674674
private dataSource?: SessionsDataSource;
675675
private labels?: ResourceLabels;
676+
private messageElement?: HTMLElement;
676677

677678
constructor(
678679
private readonly provider: IChatSessionItemProvider,
@@ -690,6 +691,7 @@ class SessionsViewPane extends ViewPane {
690691
@IViewsService private readonly viewsService: IViewsService,
691692
@ILogService private readonly logService: ILogService,
692693
@IProgressService private readonly progressService: IProgressService,
694+
@IChatSessionsService private readonly chatSessionsService: IChatSessionsService,
693695
) {
694696
super(options, keybindingService, contextMenuService, configurationService, contextKeyService, viewDescriptorService, instantiationService, openerService, themeService, hoverService);
695697

@@ -713,6 +715,73 @@ class SessionsViewPane extends ViewPane {
713715
}
714716
}
715717

718+
private async getProviderDisplayName(): Promise<string> {
719+
// For local provider, return default name
720+
if (this.provider.chatSessionType === 'local') {
721+
return 'Local';
722+
}
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;
735+
}
736+
737+
private showEmptyMessage(): void {
738+
if (!this.messageElement) {
739+
return;
740+
}
741+
742+
// Only show message for non-local providers
743+
if (this.provider.chatSessionType === 'local') {
744+
this.hideMessage();
745+
return;
746+
}
747+
748+
this.getProviderDisplayName().then(providerName => {
749+
if (!this.messageElement) {
750+
return;
751+
}
752+
753+
const messageText = nls.localize('chatSessions.noResults', "No sessions found from {0}", providerName);
754+
755+
// Clear the message element using DOM utility
756+
clearNode(this.messageElement);
757+
758+
const messageContainer = append(this.messageElement, $('.no-sessions-message'));
759+
760+
append(messageContainer, $('.codicon.codicon-info'));
761+
const textElement = append(messageContainer, $('span'));
762+
textElement.textContent = messageText;
763+
764+
// Show the message element
765+
this.messageElement.style.display = 'block';
766+
767+
// Hide the tree
768+
if (this.treeContainer) {
769+
this.treeContainer.style.display = 'none';
770+
}
771+
});
772+
}
773+
774+
private hideMessage(): void {
775+
if (this.messageElement) {
776+
this.messageElement.style.display = 'none';
777+
}
778+
779+
// Show the tree
780+
if (this.treeContainer) {
781+
this.treeContainer.style.display = 'block';
782+
}
783+
}
784+
716785
/**
717786
* Refreshes the tree data with progress indication.
718787
* Shows a progress indicator while the tree updates its children from the provider.
@@ -730,6 +799,21 @@ class SessionsViewPane extends ViewPane {
730799
},
731800
async () => {
732801
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+
}
733817
}
734818
);
735819
} catch (error) {
@@ -755,6 +839,21 @@ class SessionsViewPane extends ViewPane {
755839
},
756840
async () => {
757841
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+
}
758857
}
759858
);
760859
} catch (error) {
@@ -766,6 +865,10 @@ class SessionsViewPane extends ViewPane {
766865
protected override renderBody(container: HTMLElement): void {
767866
super.renderBody(container);
768867

868+
// Create message element for empty state
869+
this.messageElement = append(container, $('.chat-sessions-message'));
870+
this.messageElement.style.display = 'none';
871+
769872
this.treeContainer = append(container, $('.chat-sessions-tree.show-file-icons'));
770873
this.treeContainer.classList.add('file-icon-themable-tree');
771874

@@ -807,6 +910,7 @@ class SessionsViewPane extends ViewPane {
807910
// Handle double-click and keyboard selection to open editors
808911
this._register(this.tree.onDidOpen(async e => {
809912
const element = e.element as IChatSessionItem & { provider: IChatSessionItemProvider };
913+
810914
if (element && this.isLocalChatSessionItem(element)) {
811915
if (element.sessionType === 'editor' && element.editor && element.group) {
812916
// Open the chat editor

src/vs/workbench/contrib/chat/browser/media/chatSessions.css

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,22 @@
2121
margin-right: 4px;
2222
margin-left: 4px;
2323
}
24+
25+
/* Style for empty state message */
26+
.chat-sessions-message {
27+
padding: 20px;
28+
text-align: center;
29+
color: var(--vscode-descriptionForeground);
30+
}
31+
32+
.chat-sessions-message .no-sessions-message {
33+
display: flex;
34+
align-items: center;
35+
justify-content: center;
36+
gap: 8px;
37+
font-style: italic;
38+
}
39+
40+
.chat-sessions-message .no-sessions-message .codicon {
41+
opacity: 0.7;
42+
}

0 commit comments

Comments
 (0)