PowerShell / vscode-powershell

Provides PowerShell language and debugging support for Visual Studio Code
https://marketplace.visualstudio.com/items/ms-vscode.PowerShell
MIT License
1.69k stars 480 forks source link

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

Open plmcgrn opened 3 weeks ago

plmcgrn commented 3 weeks ago

Prerequisites

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

JustinGrote commented 3 weeks ago

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