From 95147456e499613748ceb03a3e82e7b31c3323f6 Mon Sep 17 00:00:00 2001 From: Alex Ross Date: Tue, 5 Dec 2023 11:11:58 +0000 Subject: [PATCH] Fix tree item order when reveal is the cause of getChildren (#200022) Fixes #191511 --- src/vs/workbench/api/common/extHostTreeViews.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/vs/workbench/api/common/extHostTreeViews.ts b/src/vs/workbench/api/common/extHostTreeViews.ts index 51d394e431d..2ea75f8b775 100644 --- a/src/vs/workbench/api/common/extHostTreeViews.ts +++ b/src/vs/workbench/api/common/extHostTreeViews.ts @@ -658,14 +658,17 @@ class ExtHostTreeView extends Disposable { return undefined; } - const items = await Promise.all(coalesce(elements || []).map(async element => { - const item = await this.dataProvider.getTreeItem(element); - return item && !cts.token.isCancellationRequested ? this.createAndRegisterTreeNode(element, item, parentNode) : null; + const coalescedElements = coalesce(elements || []); + const treeItems = await Promise.all(coalesce(coalescedElements).map(element => { + return this.dataProvider.getTreeItem(element); })); if (cts.token.isCancellationRequested) { return undefined; } + // createAndRegisterTreeNodes adds the nodes to a cache. This must be done sync so that they get added in the correct order. + const items = treeItems.map((item, index) => item ? this.createAndRegisterTreeNode(coalescedElements[index], item, parentNode) : null); + return coalesce(items); } finally { cts.dispose();