Skip to content

Commit

Permalink
Create a fast path for children that resolve sync (#143162)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jackson Kearl authored Feb 17, 2022
1 parent ada5e5b commit 563785e
Showing 1 changed file with 20 additions and 16 deletions.
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

0 comments on commit 563785e

Please sign in to comment.