Hi,
I saw with 1.8.0/1.8.1 you guys had some problems with regions folding, and 1.8.2 was supposed to fix it. But as you see in this gif, I'm still having problems with everything getting folded instead of my designed regions.
I'm using "ctrl+k ctrl+8" and "ctrl+k ctrl+9" to fold/unfold. With the extentsion installed, I'm having trouble, but without it, I got no problem at all. I can't recall I moment where it didn't work before 1.8.x.
Thanks !!

| Name | Version |
| --- | --- |
| Operating System | Windows_NT x64 10.0.17134 |
| VSCode | 1.25.1|
| PowerShell Extension Version | 1.8.2 |
|Name|Value|
|---|---|
|PSVersion|5.1.17134.165|
|PSEdition|Desktop|
|PSCompatibleVersions|1.0 2.0 3.0 4.0 5.0 5.1.17134.165|
|BuildVersion|10.0.17134.165|
|CLRVersion|4.0.30319.42000|
|WSManStackVersion|3.0|
|PSRemotingProtocolVersion|2.3|
|SerializationVersion|1.1.0.1|
Visual Studio Code Extensions(Click to Expand)
|Extension|Author|Version|
|---|---|---|
|PowerShell|ms-vscode|1.8.2|;
Hi @MayPLaY, I've watched through the GIF a couple of times, but just want to be clear about the behaviour you're seeing vs the behaviour you're expecting.
Can you restate, in words, (1) the behaviour you're expecting and (2) the behaviour you're experiencing that differs from that expectation?
Also worth noting that this folding feature can be disabled with:
"powershell.codeFolding.enable": false
Sorry for the confusion.
Expected
What it does
I hope it's a bit more clear :).
Thanks.
@MayPLaY for the notification just in case
Your guess is right ,"Un/Fold All Regions" doesn't fold block comments, but "Un/Fold All" does.

This seems like expected behaviour.
Line comments (# line comment) and region comments (<# ..... #>) are Comments (Unfold/Fold all Block Comments)
Everything else is a Region (Unfold/Fold all Regions)
There are only 3 types of folding types (https://code.visualstudio.com/docs/extensionAPI/vscode-api#FoldingRangeKind)
Yeah, Glenn's right. I think we should probably open an issue on vscode to add another item to the enum... Maybe like a "Code" FoldingRangeKind
I haven't tried using an invalid enum integer e.g. -1
Actually, that's not a bad idea. Does assigning 4 work?
Wait, we're depending on VSCode to work out what to do based on the value, so we need a new enum value...
Okay...so quick test, it does work. With an ID that is not in the enum, it doesn't respond to Unfold/Fold all Regions or Block Comments, BUT it still responsed to Unfold/Fold All.
Can't say I'm happy about it though. It's definitely a hack
Changed the following
From:
// Find matching comment regions #region -> #endregion
this.matchScopeElements(
this.extractRegionScopeElements(tokens, document),
"custom.start.region",
"custom.end.region",
vscode.FoldingRangeKind.Region, document)
.forEach((match) => { matchedTokens.push(match); });
To
// Find matching comment regions #region -> #endregion
this.matchScopeElements(
this.extractRegionScopeElements(tokens, document),
"custom.start.region",
"custom.end.region",
56, document)
.forEach((match) => { matchedTokens.push(match); });
Ok. Let's maybe have a const static variable called like FoldingRangeKindCode? That's set to some arbitrary int?
Then we can have the expected behavior at least.
Wow, issue 55,686!
To quote from the VSCode issue:
Region is only to be used for ranges originating from folding range marked by #region and #endregion
For syntax ranges, don't set kind. kind is optional.
Nice find, Rob!
OKay, I sense another PR on the way
Might have to PR a docs edit to the VS Code API. As it doesn't mention that bit. The only thing to indicate it's optional is the ? in the interface definition, which is pretty obtuse.
... And it's already done. https://github.com/Microsoft/vscode/commit/dea3960817a9b20d854f6c003f49abe16de065c5
Fix PR is up - https://github.com/PowerShell/vscode-powershell/pull/1467
Thanks @glennsarti
Most helpful comment
OKay, I sense another PR on the way