Skip to content
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

Async Tree: Create a fast path for children that resolve sync #143162

Merged
merged 1 commit into from
Feb 17, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 20 additions & 16 deletions src/vs/base/browser/ui/tree/asyncDataTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { Iterable } from 'vs/base/common/iterator';
import { DisposableStore, dispose, IDisposable } from 'vs/base/common/lifecycle';
import { ScrollEvent } from 'vs/base/common/scrollable';
import { IThemable } from 'vs/base/common/styler';
import { isIterable } from 'vs/base/common/types';

interface IAsyncDataTreeNode<TInput, T> {
element: TInput | T;
Expand Down Expand Up @@ -764,15 +765,19 @@ export class AsyncDataTree<TInput, T, TFilterData = void> implements IDisposable
if (!node.hasChildren) {
childrenPromise = Promise.resolve(Iterable.empty());
} else {
const slowTimeout = timeout(800);
const children = this.doGetChildren(node);
if (isIterable(children)) {
childrenPromise = Promise.resolve(children);
} else {
const slowTimeout = timeout(800);

slowTimeout.then(() => {
node.slow = true;
this._onDidChangeNodeSlowState.fire(node);
}, _ => null);
slowTimeout.then(() => {
node.slow = true;
this._onDidChangeNodeSlowState.fire(node);
}, _ => null);

childrenPromise = this.doGetChildren(node)
.finally(() => slowTimeout.cancel());
childrenPromise = children.finally(() => slowTimeout.cancel());
}
}

try {
Expand All @@ -796,21 +801,20 @@ export class AsyncDataTree<TInput, T, TFilterData = void> implements IDisposable
}
}

private doGetChildren(node: IAsyncDataTreeNode<TInput, T>): Promise<Iterable<T>> {
private doGetChildren(node: IAsyncDataTreeNode<TInput, T>): Promise<Iterable<T>> | Iterable<T> {
let result = this.refreshPromises.get(node);

if (result) {
return result;
}

result = createCancelablePromise(async () => {
const children = await this.dataSource.getChildren(node.element!);
const children = this.dataSource.getChildren(node.element!);
if (isIterable(children)) {
return this.processChildren(children);
});

this.refreshPromises.set(node, result);

return result.finally(() => { this.refreshPromises.delete(node); });
} else {
result = createCancelablePromise(async () => this.processChildren(await children));
this.refreshPromises.set(node, result);
return result.finally(() => { this.refreshPromises.delete(node); });
}
}

private _onDidChangeCollapseState({ node, deep }: ICollapseStateChangeEvent<IAsyncDataTreeNode<TInput, T> | null, any>): void {
Expand Down