Skip to content

pipelineIndentationStyle feature causes premature un-indentation #1840

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ThubLives opened this issue Apr 2, 2019 · 4 comments
Closed

pipelineIndentationStyle feature causes premature un-indentation #1840

ThubLives opened this issue Apr 2, 2019 · 4 comments

Comments

@ThubLives
Copy link

System Details

System Details Output

### VSCode version: 1.32.3 a3db5be9b5c6ba46bb7555ec5d60178ecc2eaae4 x64

### VSCode extensions:
ms-vscode.powershell@1.12.0


### PSES version: 1.12.0.0

### PowerShell version:

Name                           Value
----                           -----
PSVersion                      5.1.14409.1018
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.14409.1018
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Issue Description

Setting powershell.codeFormatting.pipelineIndentationStyle to "IncreaseIndentationForFirstPipeline" or "IncreaseIndentationAfterEveryPipeline" causes every line after a single-line pipeline to be un-indented by an extra level. Setting the value to the default "NoIndentation" value, pipelines are ignored and indentation behaviour returns to that which was provided in the previous release of vscode-PowerShell.

Use this code for example:

function Test-Function ($FullPath) {
if ($FullPath) {

# These lines have pipelines split over two lines.  They indent as expected.
$Path = $FullPath |
Split-Path -Parent
$FileName = $FullPath |
Split-Path -Leaf

# These lines have full pipelines.  Each removes an additional indentation.
$Path = $FullPath | Split-Path -Parent
$FileName = $FullPath | Split-Path -Leaf

$Path = $Path.Trim()
$FileName = $FileName.Trim()
return Join-Path $Path $FileName
}
}

Expected Behaviour

If a line contains a complete pipeline (i.e., one that does not continue on the following line), the following line should be at the same indentation level unless it closes a code or evaluation block as per normal indentation rules:

function Test-Function ($FullPath) {
  if ($FullPath) {

    # These lines have pipelines split over two lines.  They indent as expected.
    $Path = $FullPath |
      Split-Path -Parent
    $FileName = $FullPath |
      Split-Path -Leaf

    # These lines have full pipelines.  Each removes an additional indentation.
    $Path = $FullPath | Split-Path -Parent
    $FileName = $FullPath | Split-Path -Leaf

    $Path = $Path.Trim()
    $FileName = $FileName.Trim()
    return Join-Path $Path $FileName
  }
}

Actual Behaviour

Each complete, single-line pipeline removes one indentation level for all lines following it, in addition to normal end-block un-indentation:

function Test-Function ($FullPath) {
  if ($FullPath) {

    # These lines have pipelines split over two lines.  They indent as expected.
    $Path = $FullPath |
      Split-Path -Parent
    $FileName = $FullPath |
      Split-Path -Leaf

    # These lines have full pipelines.  Each removes an additional indentation.
    $Path = $FullPath | Split-Path -Parent
  $FileName = $FullPath | Split-Path -Leaf

$Path = $Path.Trim()
$FileName = $FileName.Trim()
return Join-Path $Path $FileName
}
}

Attached Logs

Logs will be send directly.

@rjmholt
Copy link
Contributor

rjmholt commented Apr 2, 2019

Formatting in the PowerShell is provided by PSScriptAnalyzer.

This regression was identified and fixed in that project in PowerShell/PSScriptAnalyzer#1191. It will be available with the next PSScriptAnalzyer release, which should fix this problem when installed on your module path.

We actually deliberately set the default in the extension to lessen the impact of this regression.

@Adam-S-Daniel
Copy link

Verified the fix. described by @rjmholt . After running Install-Module -Name PSScriptAnalyzer and restarting VSCode, the problem was resolved.

@SydneyhSmith
Copy link
Collaborator

@geeeyetee thanks for verifying!

@ThubLives
Copy link
Author

I'm still seeing premature un-indentation when the pipeline includes script blocks like in the case of ForEach-Object.
I'll try to complain in the right direction: PowerShell/PSScriptAnalyzer#1032.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants