Skip to content

Syntax-based code folding unavailable in virtual workspaces #4051

Open

Description

@ctholloway

Prerequisites

  • I have written a descriptive issue title.
  • I have searched all issues to ensure it has not already been reported.
  • I have read the troubleshooting guide.
  • I am sure this issue is with the extension itself and does not reproduce in a standalone PowerShell instance.
  • I have verified that I am using the latest version of Visual Studio Code and the PowerShell extension.
  • If this is a security issue, I have read the security issue reporting guidance.

Summary

I originally opened this bug with the Azure Repo extension team but subsequent troubleshooting shows this issue only occurs when the PowerShell Extension is enabled. I have tried rolling back the PowerShell extension from v2022.6.1 to 2022.5.1 and the issue still occurs. After disabling the PowerShell Extension I can no longer reproduce the error described below.

After connecting to an Azure Repo and trusting the repo in Manage Workspace trust, the code collapse arrows disappear and we cannot collapse various codeblocks. Previously collapsed code expands. Putting the repo back in Restricted mode resolves the issue immediately. We are not having any issues with local files or any files not contained in our Azure Repo. This issue appeared recently and occurs for multiple users on my team and on multiple computers. We have PowerShell scripts in our repo. This issue occurs for us on both the stable and prerelease version of Azure Repo.

Azure Repo Version:

v0.12.0

PowerShell Version

PSVersion                      7.2.5
PSEdition                      Core
GitCommitId                    7.2.5
OS                             Microsoft Windows 10.0.19043
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}       
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visual Studio Code Version

1.68.1
30d9c6cd9483b2cc586687151bcbcd635f373630
x64

Extension Version

ms-vscode.powershell@2022.6.1

Steps to Reproduce

Install Azure Repos Extension
Install PowerShell Extension
Connect to script hosted in Azure Remote Repo
Collapsing Codeblock works.
Trust Repo in Manage Workspace Trust
Collapsed codeblocks expand, can no longer click collapse.
Set Repo to restricted in Manage Workspace Trust, issue immediately resolves
Disable PowerShell Extension
Reload VSCode
Blocks now collapse as expected in Both Restricted and Trusted Mode

Visuals

RestrictedRepo
TrustedRepo

Logs

Logs sent privately per troubleshooting article.

Activity

  1. ghost added
    Needs: TriageMaintainer attention needed!
    on Jun 27, 2022
  2. SydneyhSmith commented on Jun 28, 2022

    @SydneyhSmith
    Collaborator

    Thanks, does this also reproduce for you without the Azure Repos extension?

  3. ctholloway commented on Jun 28, 2022

    @ctholloway
    Author
  4. ghost closed this as completedon Jul 6, 2022
  5. ctholloway commented on Jul 7, 2022

    @ctholloway
    Author

    My Repro Info is in Steps to Reproduce. Is anything further needed?

  6. ctholloway commented on Sep 9, 2022

    @ctholloway
    Author

    Collapse

  7. andyleejordan commented on Sep 12, 2022

    @andyleejordan
    Member

    If you have only the PowerShell extension installed, and not the Azure Repos extension, can you collapse the blocks are you're expecting to be able to?

  8. ctholloway commented on Sep 12, 2022

    @ctholloway
    Author

    If you have only the PowerShell extension installed, and not the Azure Repos extension, can you collapse the blocks are you're expecting to be able to?

    Correct. This only happens in Azure Repos once the repo has been trusted. It also only happens in Azure Repos with the powershell extension installed (as of sometime in May). Everything was groovy before that. Per my initial comment, I did report this to the Azure Repos Team and they said that because it only happens with the powershell extension installed it's not their problem. Of course, the inverse can be said as well. My issue lives in the spot of the vin diagram where it's in nobody's scope of support.

  9. 18 remaining items

  10. added
    Pending: ExternalThis issue is not fixed here, it is fixed in a dependent repo such as PowerShell,PSScriptAnalyzer
    and removed on Apr 2, 2026
  11. github-actions commented on Apr 2, 2026

    @github-actions
    Contributor

    🎯 Agentic Issue Triage

    Summary: When PowerShell files are opened inside a virtual workspace (e.g. Azure DevOps Repos via the Remote Repositories extension), the PowerShell extension's syntax-based code folding stops working once the workspace is trusted. The LSP-powered folding provider registers itself but the language server cannot run in a virtual workspace, leaving users with no folding at all.

    The issue has been present since at least 2022 and a recent comment (2026) confirms the previously suggested workaround (powershell.codeFolding.enable: false) no longer resolves it.

    🔍 Root Cause Analysis

    The PowerShell extension provides syntax-based folding via the Language Server (LSP textDocument/foldingRange). In a virtual workspace, VS Code restrictions prevent spawning local processes, so the language server never starts. However, the extension still registers itself as the folding provider for .ps1/.psm1 files (via languages.registerFoldingRangeProvider), overriding VS Code's built-in indentation-based fallback — leaving the user with zero folding.

    Key facts:

    • In Restricted mode: VS Code's own folding runs → folding works.
    • In Trusted mode with PowerShell extension enabled: extension claims folding, language server can't start → folding breaks.
    • Disabling powershell.codeFolding.enable was supposed to deregister the provider, but users now report this no longer helps.

    The VS Code Virtual Workspaces guide notes that extensions should declare their virtual workspace capabilities in package.json and avoid registering providers that require local processes.

    🛠 Suggested Fix Approaches
    1. Declare virtual workspace support level in package.json
      Add a capabilities.virtualWorkspaces entry to package.json to signal limited support. This can prevent the folding provider from being registered when no language server is available:

      "capabilities": {
        "virtualWorkspaces": {
          "supported": "limited",
          "description": "Syntax-based folding is unavailable in virtual workspaces."
        }
      }
    2. Guard folding provider registration on workspace type
      Before registering the FoldingRangeProvider, check whether the workspace is virtual (i.e., the URI scheme is not file:). If virtual, skip registration to allow VS Code's built-in folding to take over:

      const isVirtualWorkspace = vscode.workspace.workspaceFolders?.every(
        f => f.uri.scheme !== 'file'
      );
      if (!isVirtualWorkspace) {
        // register LSP folding provider
      }
    3. Implement a lightweight regex-based folding provider (longer term)
      Implement a pure-syntax folding provider (without LSP) using regex to detect {/}, begin/end, #region/#endregion, etc. This would work even without the language server and enable proper folding in virtual workspaces.

    🔄 Reproduction Steps
    1. Install VS Code with the PowerShell extension and the [Remote Repositories]((marketplace.visualstudio.com/redacted) extension.
    2. Use Open Remote Repository → connect to an Azure DevOps or GitHub repo containing .ps1 files.
    3. Open a PowerShell file — verify folding arrows appear (Restricted mode).
    4. Trust the workspace via Manage Workspace Trust.
    5. Observe: folding arrows disappear, existing collapsed regions expand, clicking gutter has no effect.
    6. Set workspace back to Restricted → folding immediately returns.
    7. Key test asked by @JustinGrote: Does this also reproduce with a plain GitHub repo via "Open Remote Repository"? This would confirm whether the issue is Azure DevOps-specific or a general virtual workspace problem.
    📂 Relevant Code Areas

    Look for folding provider registration in the extension source, likely in:

    • src/features/folding.ts (or similar) — where vscode.languages.registerFoldingRangeProvider is called
    • package.json — capabilities section for virtual workspace declarations
    • The condition controlling whether the language client/server is started

    Reference: VS Code Virtual Workspaces wiki

    ✅ Sub-tasks / Checklist
    • Confirm reproduction with a plain GitHub repo via "Open Remote Repository" (not just Azure DevOps)
    • Locate folding provider registration code and add a virtual-workspace guard
    • Add/update capabilities.virtualWorkspaces in package.json
    • Investigate why powershell.codeFolding.enable: false no longer falls back to built-in folding
    • (Stretch) Implement regex-based folding provider that works without LSP for virtual workspaces

    Generated by Agentic Triage for issue #4051

    To install this workflow, run gh aw add githubnext/agentics/workflows/issue-triage.md@2f03fdaafb8c1ae62dfde7e0be762a822a201aeb. View source at https://github.com/githubnext/agentics/tree/2f03fdaafb8c1ae62dfde7e0be762a822a201aeb/workflows/issue-triage.md.

  12. DanGilbertTX commented on Apr 2, 2026

    @DanGilbertTX

    @DanGilbertTX we have no control over that extension. If this is due to virtual workspaces in general, it might be something we can fix, but we've only ever seen it in Azure repos. Does it reproduce if you do Open Remote Repository with a normal GitHub (not Azure Devops) repo?

    I will test that in the morning and report back. I can take a video if that would help.

  13. andyleejordan commented on Apr 2, 2026

    @andyleejordan
    Member

    🎯 Agentic Issue Triage

    Summary: When PowerShell files are opened inside a virtual workspace (e.g. Azure DevOps Repos via the Remote Repositories extension), the PowerShell extension's syntax-based code folding stops working once the workspace is trusted. The LSP-powered folding provider registers itself but the language server cannot run in a virtual workspace, leaving users with no folding at all.

    The issue has been present since at least 2022 and a recent comment (2026) confirms the previously suggested workaround (powershell.codeFolding.enable: false) no longer resolves it.

    🔍 Root Cause Analysis
    🛠 Suggested Fix Approaches
    🔄 Reproduction Steps
    📂 Relevant Code Areas
    ✅ Sub-tasks / Checklist

    Generated by Agentic Triage for issue #4051
    To install this workflow, run gh aw add githubnext/agentics/workflows/issue-triage.md@2f03fdaafb8c1ae62dfde7e0be762a822a201aeb. View source at https://github.com/githubnext/agentics/tree/2f03fdaafb8c1ae62dfde7e0be762a822a201aeb/workflows/issue-triage.md.

    I need to actually configure this, because this was useless, but I want to set it up to auto close obvious spam issues, of which we have a lot.

  14. DanGilbertTX commented on Apr 3, 2026

    @DanGilbertTX

    @DanGilbertTX we have no control over that extension. If this is due to virtual workspaces in general, it might be something we can fix, but we've only ever seen it in Azure repos. Does it reproduce if you do Open Remote Repository with a normal GitHub (not Azure Devops) repo?

    Yes. It actually installs the 3 Remote extensions when you click on it. I started with a new install of VSCode in a VM to test this just to make sure I wasn't bringing crap over. I installed PowerShell extension and nothing else. Then clicked Remote Repository like you asked. Of note, when I start VSCode and/or first connect, it does show the folding carats. Those go away after a few seconds. My guess is that it is the virtual workspace issue.

    Here are screenshots of connecting, what it looks like untrusted, and what it looks like trusted:

    Image Image Image Image Image Image
  15. DanGilbertTX commented on Apr 3, 2026

    @DanGilbertTX

    Also, putting the workspace back to restricted mode is not giving me the option to fold. It disables the PowerShell extension.

    Image
  16. ctholloway commented on Jun 8, 2026

    @ctholloway
    Author

    Just an update since this was reopened, code folding still does not work for me. I'm even on a new image from when I originally opened the issue. It used to work, it broke several years ago and has remained broken ever since in the remote repos. My experience is identical to Dan's.

  17. JustinGrote commented on Jun 9, 2026

    @JustinGrote
    Collaborator

    Thanks for the update! We do know that the semantic highlighting has some issues after a regression we are planning to fix, can you try disabling semantic highlighting and see if it persists?

  18. DanGilbertTX commented on Jun 9, 2026

    @DanGilbertTX

    Thanks for the update! We do know that the semantic highlighting has some issues after a regression we are planning to fix, can you try disabling semantic highlighting and see if it persists?

    I assume you mean the editor.semanticHighlighting setting in VSCode. I checked mine and it was set for both User/Workspace as ConfiguredByTheme. I changed it to false and folding is still broken.

    Of note, when I changed it and went back, semantic highlighting is still Enabled. It also says it is modified elsewhere (see screenshot). I have clicked those and set it to false in all those places and semantic highlighting still seems to be Enabled. I made sure it was false in all places I could search for semantic. I rebooted the computer as well; just to make sure that wasn't something that was needed.

    This is a Win11 test VM with nothing but VSCode on it, the Remote Repositories extension and the PowerShell extension. This is my userspace settings.json. The workspace settings.json has the same except no workbench.colorTheme line.

    {
        "workbench.colorTheme": "Visual Studio Dark",
        "editor.semanticHighlighting.enabled": false,
        "editor.semanticTokenColorCustomizations": {},
        "[powershell]": {
            "editor.semanticHighlighting.enabled": false
        }
    }
    

    Is there some other way/place I am supposed to disable it?

    Image
  19. JustinGrote commented on Jun 9, 2026

    @JustinGrote
    Collaborator

    Nope that should do it. Thanks!

    Since virtual workspaces is a relatively new (Sept 2025) feature I'm sure there's some stuff we need to fix to update for it. It would definitely be partial support as parts of the extension cannot work today with virtual file paths, they must be absolute local file paths on the file system due to how PowerShell works.

    https://github.com/microsoft/vscode/wiki/Virtual-Workspaces#what-are-the-expectations-for-language-support-with-virtual-workspaces

    Things like code folding should be doable within a single file however.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Area-FoldingBug: VS CodeBugs in VS Code itself.Pending: ExternalThis issue is not fixed here, it is fixed in a dependent repo such as PowerShell,PSScriptAnalyzer

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions