Skip to content

Fixes #192055 avoids view refresh race condition #250239

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions src/vs/workbench/api/common/extHostTreeViews.ts
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,19 @@ class ExtHostTreeView<T> extends Disposable {
}));
}

private _loadingPromise: Promise<any> | undefined;
private trackAsLoading<T>(promise: Promise<T>): Promise<T> {
const chainedPromise = this._loadingPromise ? this._loadingPromise.finally(() => promise) : promise;
const last = chainedPromise.catch(() => { }).finally(() => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we want to catch and ignore exception here. Can this be done without the catch?

if (this._loadingPromise === last) {
this._loadingPromise = undefined;
}
});
this._loadingPromise = last;

return promise;
}

async getChildren(parentHandle: TreeItemHandle | Root): Promise<ITreeItem[] | undefined> {
const parentElement = parentHandle ? this.getExtensionElement(parentHandle) : undefined;
if (parentHandle && !parentElement) {
Expand All @@ -426,7 +439,7 @@ class ExtHostTreeView<T> extends Disposable {
let childrenNodes: TreeNode[] | undefined = this.getChildrenNodes(parentHandle); // Get it from cache

if (!childrenNodes) {
childrenNodes = await this.fetchChildrenNodes(parentElement);
childrenNodes = await this.trackAsLoading(this.fetchChildrenNodes(parentElement));
}

return childrenNodes ? childrenNodes.map(n => n.item) : undefined;
Expand Down Expand Up @@ -698,7 +711,11 @@ class ExtHostTreeView<T> extends Disposable {

private _refreshCancellationSource = new CancellationTokenSource();

private refresh(elements: (T | Root)[]): Promise<void> {
private async refresh(elements: (T | Root)[]): Promise<void> {
while (this._loadingPromise) {
await this._loadingPromise;
}

const hasRoot = elements.some(element => !element);
if (hasRoot) {
// Cancel any pending children fetches
Expand All @@ -713,7 +730,7 @@ class ExtHostTreeView<T> extends Disposable {
return this.refreshHandles(handlesToRefresh);
}
}
return Promise.resolve(undefined);
return undefined;
}

private getHandlesToRefresh(elements: T[]): TreeItemHandle[] {
Expand Down