Skip to content

Commit 41c1976

Browse files
authored
Merge pull request microsoft#257883 from microsoft/copilot/fix-d26c41ec-2939-4f32-a432-2e2763bd6de8
Add progress indicator to chat sessions async data provider using IProgressService
2 parents 1fe13cd + e8c821e commit 41c1976

File tree

1 file changed

+62
-7
lines changed

1 file changed

+62
-7
lines changed

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

Lines changed: 62 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { IContextMenuService } from '../../../../platform/contextview/browser/co
1010
import { SyncDescriptor } from '../../../../platform/instantiation/common/descriptors.js';
1111
import { IInstantiationService } from '../../../../platform/instantiation/common/instantiation.js';
1212
import { ILogService } from '../../../../platform/log/common/log.js';
13+
import { IProgressService } from '../../../../platform/progress/common/progress.js';
1314
import { Registry } from '../../../../platform/registry/common/platform.js';
1415
import { IStorageService } from '../../../../platform/storage/common/storage.js';
1516
import { ITelemetryService } from '../../../../platform/telemetry/common/telemetry.js';
@@ -552,7 +553,8 @@ class SessionsRenderer extends Disposable implements ITreeRenderer<IChatSessionI
552553

553554
constructor(
554555
private readonly labels: ResourceLabels,
555-
@IThemeService private readonly themeService: IThemeService
556+
@IThemeService private readonly themeService: IThemeService,
557+
@ILogService private readonly logService: ILogService,
556558
) {
557559
super();
558560

@@ -600,7 +602,7 @@ class SessionsRenderer extends Disposable implements ITreeRenderer<IChatSessionI
600602

601603
this.appliedIconColorStyles.add(styleKey);
602604
} else {
603-
console.log('No color found for colorId:', colorId);
605+
this.logService.debug('No color found for colorId:', colorId);
604606
}
605607
}
606608

@@ -686,14 +688,16 @@ class SessionsViewPane extends ViewPane {
686688
@IHoverService hoverService: IHoverService,
687689
@IEditorService private readonly editorService: IEditorService,
688690
@IViewsService private readonly viewsService: IViewsService,
691+
@ILogService private readonly logService: ILogService,
692+
@IProgressService private readonly progressService: IProgressService,
689693
) {
690694
super(options, keybindingService, contextMenuService, configurationService, contextKeyService, viewDescriptorService, instantiationService, openerService, themeService, hoverService);
691695

692696
// Listen for changes in the provider if it's a LocalChatSessionsProvider
693697
if (provider instanceof LocalChatSessionsProvider) {
694698
this._register(provider.onDidChange(() => {
695699
if (this.tree && this.isBodyVisible()) {
696-
this.tree.updateChildren(this.provider);
700+
this.refreshTreeWithProgress();
697701
}
698702
}));
699703
}
@@ -705,7 +709,57 @@ class SessionsViewPane extends ViewPane {
705709

706710
public refreshTree(): void {
707711
if (this.tree && this.isBodyVisible()) {
708-
this.tree.updateChildren(this.provider);
712+
this.refreshTreeWithProgress();
713+
}
714+
}
715+
716+
/**
717+
* Refreshes the tree data with progress indication.
718+
* Shows a progress indicator while the tree updates its children from the provider.
719+
*/
720+
private async refreshTreeWithProgress(): Promise<void> {
721+
if (!this.tree) {
722+
return;
723+
}
724+
725+
try {
726+
await this.progressService.withProgress(
727+
{
728+
location: this.id, // Use the view ID as the progress location
729+
title: nls.localize('chatSessions.refreshing', 'Refreshing chat sessions...'),
730+
},
731+
async () => {
732+
await this.tree!.updateChildren(this.provider);
733+
}
734+
);
735+
} catch (error) {
736+
// Log error but don't throw to avoid breaking the UI
737+
this.logService.error('Error refreshing chat sessions tree:', error);
738+
}
739+
}
740+
741+
/**
742+
* Loads initial tree data with progress indication.
743+
* Shows a progress indicator while the tree loads data from the provider.
744+
*/
745+
private async loadDataWithProgress(): Promise<void> {
746+
if (!this.tree) {
747+
return;
748+
}
749+
750+
try {
751+
await this.progressService.withProgress(
752+
{
753+
location: this.id, // Use the view ID as the progress location
754+
title: nls.localize('chatSessions.loading', 'Loading chat sessions...'),
755+
},
756+
async () => {
757+
await this.tree!.setInput(this.provider);
758+
}
759+
);
760+
} catch (error) {
761+
// Log error but don't throw to avoid breaking the UI
762+
this.logService.error('Error loading chat sessions data:', error);
709763
}
710764
}
711765

@@ -721,7 +775,7 @@ class SessionsViewPane extends ViewPane {
721775
this.dataSource = new SessionsDataSource(this.provider);
722776

723777
const delegate = new SessionsDelegate();
724-
const renderer = new SessionsRenderer(this.labels, this.themeService);
778+
const renderer = new SessionsRenderer(this.labels, this.themeService, this.logService);
725779
this._register(renderer);
726780

727781
this.tree = this.instantiationService.createInstance(
@@ -747,6 +801,7 @@ class SessionsViewPane extends ViewPane {
747801
}
748802
) as WorkbenchAsyncDataTree<IChatSessionItemProvider, IChatSessionItem, FuzzyScore>;
749803

804+
this.logService.debug('Tree created with hideTwistiesOfChildlessElements: true');
750805
this._register(this.tree);
751806

752807
// Handle double-click and keyboard selection to open editors
@@ -773,13 +828,13 @@ class SessionsViewPane extends ViewPane {
773828
// Handle visibility changes to load data
774829
this._register(this.onDidChangeBodyVisibility(async visible => {
775830
if (visible && this.tree) {
776-
await this.tree.setInput(this.provider);
831+
await this.loadDataWithProgress();
777832
}
778833
}));
779834

780835
// Initially load data if visible
781836
if (this.isBodyVisible() && this.tree) {
782-
this.tree.setInput(this.provider);
837+
this.loadDataWithProgress();
783838
}
784839
}
785840

0 commit comments

Comments
 (0)