Vscode-powershell: Automatically split | characters to a new line

Created on 20 Sep 2019  路  5Comments  路  Source: PowerShell/vscode-powershell

Summary of the new feature/enhancement

I'd like to the ability to take the following line:

$Ports | ForEach-Object -Process { NETSTAT.EXE -ano | findstr.exe :8080 | ForEach-Object -Process { ($_ -split '\s+')[-1] } | Sort-Object | Get-Unique | ForEach-Object -Process { taskkill.exe /F /PID $_ } }

and convert it to:

$Ports |
    ForEach-Object -Process {
        NETSTAT.EXE -ano |
            findstr.exe :8080 |
            ForEach-Object -Process {
                ($_ -split '\s+')[-1]
            } | Sort-Object |
            Get-Unique |
            ForEach-Object -Process {
                taskkill.exe /F /PID $_
            }
    }

I think this would go a long way in approving readability. At the very least, with the

"powershell.codeFormatting.pipelineIndentationStyle": "IncreaseIndentationForFirstPipeline"

setting enabled, when I manually add the new line after each | and }, it will format the indentation correctly which is nice.

Area-Script Analysis Issue-Enhancement

Most helpful comment

@thomasrea0113 this type of change would first need to be done in https://github.com/PowerShell/PSScriptAnalyzer which provides the formatting experience in the PowerShell extension for VSCode.

Once a formatting rule is added there, then we can add a vscode setting to configure it.

Can you open an issue issue over there first?

cc @bergmeister

Done. I created the issue here: https://github.com/PowerShell/PSScriptAnalyzer/issues/1345

in the meantime, should this issue be closed?

All 5 comments

@thomasrea0113 this type of change would first need to be done in https://github.com/PowerShell/PSScriptAnalyzer which provides the formatting experience in the PowerShell extension for VSCode.

Once a formatting rule is added there, then we can add a vscode setting to configure it.

Can you open an issue issue over there first?

cc @bergmeister

Indeed, please transfer it to PSSA. As it was already said the pipelineIndentationStyle setting of IncreaseIndentationForFirstPipeline already formats it correctly when there are already newlines but it does not break a 1 liner into multiple lines. I'd need to do some research if that is feasible (I believe there are good reasons to not try to force newlines to the user because what if one has a few short pipelines on line 2 that one does not want to be broken up due to the increase in indentation, one might need a new setting like pipelineNewlineStyle, I hope we are not drifting off here into configuration hell...)

Indeed, please transfer it to PSSA. As it was already said the pipelineIndentationStyle setting of IncreaseIndentationForFirstPipeline already formats it correctly when there are already newlines but it does not break a 1 liner into multiple lines. I'd need to do some research if that is feasible (I believe there are good reasons to not try to force newlines to the user because what if one has a few short pipelines on line 2 that one does not want to be broken up due to the increase in indentation, one might need a new setting like pipelineNewlineStyle, I hope we are not drifting off here into configuration hell...)

A new setting like you mentioned is exactly what I'd be looking for. I'm thinking the setting could automatically split one-liners into multiple of the line reaches the standard 80 character limit.

@thomasrea0113 this type of change would first need to be done in https://github.com/PowerShell/PSScriptAnalyzer which provides the formatting experience in the PowerShell extension for VSCode.

Once a formatting rule is added there, then we can add a vscode setting to configure it.

Can you open an issue issue over there first?

cc @bergmeister

Done. I created the issue here: https://github.com/PowerShell/PSScriptAnalyzer/issues/1345

in the meantime, should this issue be closed?

Thanks for transferring the issue, yes, we can close here. Should that new setting be implemented in PSSA, it should be natural to the implementer that PRs would later be needed here and in PSES to propagate the setting.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

inthemedium picture inthemedium  路  3Comments

timoline picture timoline  路  3Comments

TheDanishDynamo picture TheDanishDynamo  路  3Comments

AWahlqvist picture AWahlqvist  路  3Comments

GQnzo picture GQnzo  路  3Comments