vscode-powershell icon indicating copy to clipboard operation
vscode-powershell copied to clipboard

Using region comments, collapsing doesn't include the endregion line

Open plmcgrn opened this issue 1 year ago • 1 comments

Prerequisites

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

Summary

When using #region and #endregion in developing PowerShell code, there is a difference in how code collapse works in ISE vs. VS Code. In ISE, collapsing a region will also hide the endregion line. In VS Code, it will not. This leads to extraneough lines when trying to collapse all regions for easier code viewing.

PowerShell Version

Name                           Value
----                           -----
PSVersion                      7.4.3
PSEdition                      Core
GitCommitId                    7.4.3
OS                             Darwin 23.6.0 Darwin Kernel Version 23.6.0: Mon Jul 29 21:13:04 PDT 2024; root:xn…
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Name             : Visual Studio Code Host
Version          : 2024.2.2
InstanceId       : 299e7431-e53b-4bb8-b868-133a1dd5f18c
UI               : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture   : en-US
CurrentUICulture : en-US
PrivateData      : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
DebuggerEnabled  : True
IsRunspacePushed : False
Runspace         : System.Management.Automation.Runspaces.LocalRunspace

Visual Studio Code Version

Version: 1.92.1 (Universal)
Commit: eaa41d57266683296de7d118f574d0c2652e1fc4
Date: 2024-08-07T20:16:39.455Z
Electron: 30.1.2
ElectronBuildId: 9870757
Chromium: 124.0.6367.243
Node.js: 20.14.0
V8: 12.4.254.20-electron.0
OS: Darwin arm64 23.6.0

Extension Version

v2024.2.2

Steps to Reproduce

Write a region in a PowerShell script within VS Code, example:

#region: Enable archive for each mailbox
if ($mailboxes.count -gt 0) {
    foreach ($mailbox in $mailboxes) {
        try {
            $mailboxOutput = $mailbox | Enable-Mailbox -Archive
            Write-Output "Enabled archive for $($mailbox.DisplayName)"
        }
        catch {
            Write-Output "Failed to enable archive for $($mailbox.DisplayName)"
            Write-Error "Failed to enable archive for $($mailbox.DisplayName)"
            Write-Output $_.Exception
            Write-Output $_.ErrorDetails
        }        
    }    
}
#endregion: Enable archive for each mailbox

When collapsing the region, it will show two lines, not 1

#region: Enable archive for each mailbox
#endregion: Enable archive for each mailbox

Visuals

image image

Logs

No response

plmcgrn avatar Aug 19 '24 15:08 plmcgrn

Thanks for the submission! It's certainly something we should look into in terms of the grammar, because the standard with other languages appears to fold that end part inwards. At the very least we should have a configurable option ideally if it's not a hard-baked grammar rule thing.

Javascript Example: image

image

JustinGrote avatar Aug 19 '24 18:08 JustinGrote

it should be configurable by powershell.codeFolding.showLastLine setting.

peetrike avatar Jun 20 '25 13:06 peetrike

It is. Not sure when that was added but it covers this issue.

plmcgrn avatar Jun 20 '25 15:06 plmcgrn