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

PowerShell formatting and indent bug when using the backtick character

Open daviwil opened this issue 8 years ago • 3 comments

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:

  1. 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

daviwil avatar Aug 14 '17 23:08 daviwil

@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?

daviwil avatar Aug 14 '17 23:08 daviwil

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.

dahlbyk avatar Mar 27 '22 16:03 dahlbyk

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'}

o-l-a-v avatar Mar 02 '24 10:03 o-l-a-v