PowerShell / vscode-powershell

Provides PowerShell language and debugging support for Visual Studio Code

Home Page:https://marketplace.visualstudio.com/items/ms-vscode.PowerShell

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

When a line ends in an equal sign, automatically indent the next line since it is part of the assignment statement

deadlydog opened this issue · comments

Prerequisites

  • I have written a descriptive issue title.
  • I have searched all issues to ensure it has not already been reported.

Summary

When a line ends in an equal sign, I would like the formatting of the next line to be automatically indented. This would help make it clear that the next line is part of the assignment and not the start of a new code statement. This would also allow it to match the behaviour used when a line ends with the pipe character, since it too is a continuation of a code statement, and would match the default behaviour of other languages, such as C# in Visual Studio.

For example, when using the VS Code setting powershell.codeFormatting.pipelineIndentationStyle = IncreaseIndentationForFirstPipeline, the code is currently formatted like this:

$result =
Get-Process |
    Select-Object -First 1

I would prefer = to follow the same rules as | and have the code formatted like this:

$result =
    Get-Process |
    Select-Object -First 1

In this small example it may look silly to not just do:

$result = Get-Process |
    Select-Object -First 1

However, sometimes with fully qualified namespaces and descriptive variable names, the left-side of the equal operator may get very lengthy, such as:

[System.Collections.ArrayList] $listOfCustomersWithValidDriversLicenses = Get-CustomersFromCmdletWithAVeryLongName -Country Canada -AreaCode 123

This would look much better and prevent horizontal scrolling as:

[System.Collections.ArrayList] $listOfCustomersWithValidDriversLicenses = 
    Get-CustomersFromCmdletWithAVeryLongName -Country Canada -AreaCode 123

Currently, VS Code formats the code like this:

[System.Collections.ArrayList] $listOfCustomersWithValidDriversLicenses = 
Get-CustomersFromCmdletWithAVeryLongName -Country Canada -AreaCode 123

The current formatting makes it easy to overlook that the results returned from Get-CustomersFromCmdletWithAVeryLongName are being saved in a variable.

Proposed Design

No response

Looking at some other formatting requests, it looks like it is PSScriptAnalyzer that handles all of the code formatting, so I have moved this request to the PSScriptAnalyzer repo here.