Repository: vscode
Issue: Strange behavior of files.exclude in workspace with deep nested folders
Labels: bug,file-explorer

<!-- ⚠️⚠️ Do Not Delete This! bug_report_template ⚠️⚠️ -->
<!-- Please read our Rules of Conduct: https://opensource.microsoft.com/codeofconduct/ -->
<!-- 🕮 Read our guide about submitting issues: https://github.com/microsoft/vscode/wiki/Submitting-Bugs-and-Suggestions -->
<!-- 🔎 Search existing issues to avoid creating duplicates. -->
<!-- 🧪 Test using the latest Insiders build to see if your issue has already been fixed: https://code.visualstudio.com/insiders/ -->
<!-- 💡 Instead of creating your report here, use 'Report Issue' from the 'Help' menu in VS Code to pre-fill useful information. -->
<!-- 🔧 Launch with `code --disable-extensions` to check. -->
Does this issue occur when all extensions are disabled?: Yes

<!-- 🪓 If you answered No above, use 'Help: Start Extension Bisect' from Command Palette to try to identify the cause. -->
<!-- 📣 Issues caused by an extension need to be reported directly to the extension publisher. The 'Help > Report Issue' dialog can assist with this. -->
- VS Code Version: 1.67.2
- OS Version: Windows 11 x64

Related issues:
https://github.com/microsoft/vscode/issues/118557
https://github.com/microsoft/vscode/issues/150764

Steps to Reproduce:

1. Create a root folder `folder-exclude-sample`
2. Inside that folder create a folder `packages`
3. Inside that folder create two nested folders `module-a` & `module-b`
4. Inside each folder, `module-a` & `module-b` create at least four files: `test1.txt`, `test2.txt`, `test3.txt` & `package.json`
5. In root folder (`folder-exclude-sample`), create a workspace definition file `folder-exclude-sample.code-workspace`

```json
{
  "folders": [
    {
      "name": "Root",
      "path": "."
    },
    {
      "name": "Module-A",
      "path": "packages/module-a"
    },
    {
      "name": "Module-B",
      "path": "packages/module-b"
    }
  ],
  "settings": {
    "files.exclude": {
      "packages": true
    }
  }
}
```

Alternatively to previous steps, just clone this GitHub repo: https://github.com/jrson83/folder-exclude-sample

6. Open the workspace (`folder-exclude-sample.code-workspace`)
7. Collapse all folders (`Root`, `Module-A`, `Module-B`
8. Random click on files from the modules folders

![2022-06-08_00h12_33](https://user-images.githubusercontent.com/45284565/172492183-d14e5d1b-6469-465b-88da-722acf233264.gif)

9. The expected behavior is that the excluded `package` folder is not displayed inside the `Root` workspace (and also `Module-A` & `Module-B`, since they exist inside the hidden `packages` folder). Instead when opening random files from the modules workspaces, the `package` folder is getting displayed randomly, until you close the selected file again.

This is also happening when using alternativ a `settings.json` inside `.vscode` folder in root.

It would be great if this issue could be fixed, since the recommended setup for monorepo workspaces from package managers like [pnpm](https://pnpm.io/pnpm-workspace_yaml), [npm](https://docs.npmjs.com/cli/v7/using-npm/workspaces#running-commands-in-the-context-of-workspaces) & [yarn](https://classic.yarnpkg.com/lang/en/docs/workspaces/) is to include modules inside one `packages` folder.