PowerShell / PowerShell/vscode-powershell

PowerShell Extension breaks Standard VSCode comment line code folding for `.ps1` and `.psm1` files

Open
#4,745 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Area-Folding Issue-Enhancement
Dominant language
TypeScript
Stars
1.9k
Forks
547
PR merge metrics
No merged PRs in 30d

Description

Prerequisites
  • I have written a descriptive issue title.
  • I have searched all open and closed 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

In VSCode you can fold entire blocks of code that are indented under a commented out line. I use this everywhere in other languages to organise my code, in PowerShell this simply does not work.

Today, I set out to find out why. Turns out the PowerShell extension is interfering, In the following example, only the PowerShell extension is enabled (you can see on the right, all other extensions are greyed out, I made sure to reload after).

At the start, I cannot fold any of the functions under their respective commented out lines, the code folding arrow for the commented out lines will not even show in the gutter.

When I disable the PowerShell extension and reload the window, I can fold both functions under their respective commented out lines.

Trying various configurations of "powershell.codeFolding.enable": false and "powershell.codeFolding.showLastLine": false, did not solve the issue. I am not sure what these lines are for but I did try various true/false settings, did not work.

PowerShell Version
Name                           Value
----                           -----
PSVersion                      7.3.4
PSEdition                      Core
GitCommitId                    7.3.4
OS                             Microsoft Windows 10.0.22621
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
Version:          Code 1.82.2 (abd2f3db4bdb28f9e95536dfa84d8479f1eb312d, 2023-09-14T05:55:25.390Z)
OS Version:       Windows_NT x64 10.0.22621
CPUs:             AMD Ryzen 9 5950X 16-Core Processor             (32 x 3400)
Memory (System):  127.93GB (99.32GB free)
VM:               0%
Screen Reader:    no
Extension Version
v2023.6.0
Steps to Reproduce

With the Powershell extension enabled try to fold the function under their respective commented out lines:


#------- Function 1 ------
	function Foo {
		param (
			$Foo
		)
		begin{}
		process{}
		end{}
	}
#------- Function 2 ------
	function Foo {
		param (
			$Foo
		)
		begin{}
		process{}
		end{}
	}

Then disable the extension, reload the window and try the same thing again with the above code, it should work this time around.

Visuals

No response

Logs

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the folding behavior in VS Code with the provided PowerShell sample, first with the extension enabled and then disabled. Trace the extension behavior affecting comment-led folding; done means the functions can be folded under their commented lines for .ps1 and .psm1 files without disabling the extension.

Written by the indexing model from the issue text.

Assessment

Tech stack
powershell, typescript, vscode
Domain
devtools, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.