powershell.codeFormatting.whitespaceBetweenParameters inappropriately removes + operators in string concatenation
See original GitHub issueIssue Description
When formatting a document with powershell.codeFormatting.whitespaceBetweenParameters enabled, the formatter inappropriately removes + operators in string concatenation.
Steps to reproduce:
- Enter this code example:
Write-Output ($env:computername + ", " + $env:username)
(GitHub is collapsing the whitespace, but there are four spaces on each side of each plus sign) - Enable powershell.codeFormatting.whitespaceBetweenParameters
- Format document
Expected result:
Write-Output ($env:computername + ", " + $env:username)
Actual result:
Write-Output ($env:computername ", " + $env:username)
(which is syntactically invalid!)
Additionally, if you start out with the expected result and format the document, you get the following result:
Write-Output ($env:computername ", " $env:username)
…which is even worse, as the operators have been removed entirely.
Attached Logs
1593619176-7b7e0c1b-7340-41cb-a9a0-c526c1c513bd1593619173652.zip editor services.log
Environment Information
Visual Studio Code
Name | Version |
---|---|
Operating System | Windows_NT x64 10.0.19041 |
VSCode | 1.46.1 |
PowerShell Extension Version | 2020.6.0 |
PowerShell Information
Name | Value |
---|---|
PSVersion | 5.1.19041.1 |
PSEdition | Desktop |
PSCompatibleVersions | 1.0 2.0 3.0 4.0 5.0 5.1.19041.1 |
BuildVersion | 10.0.19041.1 |
CLRVersion | 4.0.30319.42000 |
WSManStackVersion | 3.0 |
PSRemotingProtocolVersion | 2.3 |
SerializationVersion | 1.1.0.1 |
Visual Studio Code Extensions
Visual Studio Code Extensions(Click to Expand)
Extension | Author | Version |
---|---|---|
powershell | ms-vscode | 2020.6.0 |
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Powershell string concatenation mystery
The implication is that $ver contains an array of strings, not just a single string: The -replace operator can operate on arrays as...
Read more >How to Concatenate a String in PowerShell
Learn how to easily concatenate a string, variable, objects and more with PowerShell. All methods explained!
Read more >Strings in PowerShell – Replace, compare, concatenate, ...
PowerShell automatically inserts a space here between the linked array elements. Another option for concatenating strings is the join operator.
Read more >PowerShell Concatenate String: Examples & Functions
Concatenation is a method of joining two strings using certain operators. The PowerShell concatenation of strings happens with string builder, string with ...
Read more >Concatenate - PowerShell
String Substitution has one important limitation: PowerShell will identify each variable in the expression by matching characters, that are legal for a $ ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I trust you on this
Looks like I can unfortunately