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

TreeSection.openItem() doesn't work with compacted folders #50

Open
jeffb-sfdc opened this issue Oct 5, 2022 · 3 comments
Open

TreeSection.openItem() doesn't work with compacted folders #50

jeffb-sfdc opened this issue Oct 5, 2022 · 3 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@jeffb-sfdc
Copy link
Contributor

jeffb-sfdc commented Oct 5, 2022

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.

@christian-bromann
Copy link
Contributor

@jeffb-sfdc have you found a root cause for this issue?

@christian-bromann christian-bromann added bug Something isn't working help wanted Extra attention is needed labels Nov 14, 2022
@jeffb-sfdc
Copy link
Contributor Author

@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.

@christian-bromann
Copy link
Contributor

@jeffb-sfdc gotcha, what would you suggest as a solution to this problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants