wdio-vscode-service
wdio-vscode-service copied to clipboard
TreeSection.openItem() doesn't work with compacted folders
TreeSection.openItem() doesn't work with compacted (empty) folders.
Let's say I have the following folder structure:
/src
/src/project
/src/project/test
/src/project/test/two
/src/project/test/two/three
/src/project/test/two/three/example.ts
...and let's say that in my e2e test, I have /src/project open. When /src/project
is opened, VS Code displays just:
PROJECT
test
If /project/test is expanded, because VS Code has the explorer.compactFolders
setting set to true by default, what we see is:
PROJECT
test / two / three
example.ts
(/project/test only has one folder, "two", and project/test/two only has one folder, "three", and so they are compacted)
OK, next write a test and add:
const item = await treeViewSection.openItem('test');
The implementation of openItem()
is:
class TreeSection extends ViewSection_1.ViewSection {
async openItem(...path) {
let items = [];
for (let i = 0; i < path.length; i += 1) {
const item = await this.findItem(path[i], i + 1);
if (await item?.hasChildren() && !await item?.isExpanded()) {
await item?.expand();
}
}
let currentItem = await this.findItem(path[0], 1);
for (let i = 0; i < path.length; i += 1) {
.
.
.
Here, path is ['test'], and in the first loop, when findItem() is called:
const item = await this.findItem(path[i], i + 1);
...i is 0, and path[0] is "test", this.findItem(path[i], i + 1) succeeds, and then the node is expanded in VS Code's UI.
But next, immediately after the first for loop, findItem() is called again:
let currentItem = await this.findItem(path[0], 1);
path[0]
is still "test", but since the node was expanded, and it has nested empty folders, and explorer.compactFolders is true by default, the text of the node is now "test / two / three", and currentItem
returned from this.findItem(path[0], 1)
is undefined.
@jeffb-sfdc have you found a root cause for this issue?
@christian-bromann yes, if I remember correctly, the issue is that in openItem()
, the tree is walked and expended with:
await item?.expand();
When expanded, the first item is now "test / two / three", but path[0]
is now stale, and is only "test".
A few lines later there is:
let currentItem = await this.findItem(path[0], 1);
path[0]
is still "test", but within this.findItem()
, it has "test / two / three" not "test", and so the node is never found.
@jeffb-sfdc gotcha, what would you suggest as a solution to this problem?