vscode-powershell
vscode-powershell copied to clipboard
PowerShell formatting and indent bug when using the backtick character
From @woowil on August 14, 2017 17:6
- VSCode Version: Code 1.15.0 (8b95971d8cccd3afd86b35d4a0e098c189294ff2, 2017-08-09T20:16:06.988Z)
- OS Version: Windows_NT ia32 10.0.14393
- Extensions: the listing length exceeds browsers' URL characters limit
Steps to Reproduce:
- PowerShell Settings.json: "editor.formatOnSave": true, "editor.formatOnType": true,
Desired Formatting:
Get-Process | ForEach-Object `
-Begin {
$Count = 0
} `
-Process {
$Count++
} `
-End {
$Count
}
Bug Formatting
Get-Process | ForEach-Object `
-Begin {
$Count = 0
} `
-Process {
$Count++
} `
-End {
$Count
}
Reproduces without extensions: Yes/No
Copied from original issue: Microsoft/vscode#32494
@aeschli This seems to be caused by the new default of editor.autoIndent: true. I've been getting a few reports of code being improperly formatted on paste with this setting turned on. Is there an easy way to test my indentation regexes to make sure they work correctly with this new default behavior?
Seeing similar behavior auto-formatting/indenting this as:
$b = Invoke-NullCoalescing `
- { dbg 'Trying symbolic-ref' $sw; git --no-optional-locks symbolic-ref HEAD -q 2>$null } `
- { '({0})' -f (Invoke-NullCoalescing `
+ { dbg 'Trying symbolic-ref' $sw; git --no-optional-locks symbolic-ref HEAD -q 2>$null } `
+ { '({0})' -f (Invoke-NullCoalescing `
{
dbg 'Trying describe' $sw
I would expect any escaped newline to be indented relative to the first line of the expression.
One more case. I want it to be like this:
Microsoft.PowerShell.PSResourceGet\Get-InstalledPSResource -Path $Script:ModulesPath | `
Where-Object -FilterScript {
$_.'Type' -eq 'Module' -and
$_.'Repository' -eq 'PSGallery' -and
-not ($IncludePreReleaseVersions -and $_.'IsPrerelease')
} | ForEach-Object -Process {
Add-Member -InputObject $_ -MemberType 'AliasProperty' -Name 'Path' -Value 'InstalledLocation' -PassThru
} | Group-Object -Property 'Name' | Select-Object -Property 'Name',@{'Name'='Versions';'Expression'='Group'}
Auto indent does this:
Microsoft.PowerShell.PSResourceGet\Get-InstalledPSResource -Path $Script:ModulesPath | `
Where-Object -FilterScript {
$_.'Type' -eq 'Module' -and
$_.'Repository' -eq 'PSGallery' -and
-not ($IncludePreReleaseVersions -and $_.'IsPrerelease')
} | ForEach-Object -Process {
Add-Member -InputObject $_ -MemberType 'AliasProperty' -Name 'Path' -Value 'InstalledLocation' -PassThru
} | Group-Object -Property 'Name' | Select-Object -Property 'Name',@{'Name'='Versions';'Expression'='Group'}