Skip to content
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

whitespaceBetweenParameters alters non-parameter's code multiple times #1541

Closed
ninmonkey opened this issue Jul 12, 2020 · 3 comments
Closed

Comments

@ninmonkey
Copy link

ninmonkey commented Jul 12, 2020

This is like issue #1536 but I created a new one because I have extra details and test cases that change code when operators are not involved.

Steps to reproduce

This only breaks using the setting "powershell.codeFormatting.whitespaceBetweenParameters": true, is enabled
You can create a fresh powershell file with only the following:

BaseGameXml = Get-ChildItem "${GameBase}\Content\" '*.xml'
Write-Output ($env:computername + ", " + $env:username)

Then run Format Document Running multiple times continues making non-formating changes to the code.

Expected behavior

BaseGameXml = Get-ChildItem "${GameBase}\Content\" '*.xml'
Write-Output ($env:computername + ", " + $env:username)

Actual behavior

formatting 1 time

BaseGameXml = Get-ChildItem "${GameBase}\'*.xml'
Write-Output ($env:computername " + $env:username)

formatting 3 times

BaseGameXml = Get-ChildItem "${GameBase}\'*.xml'
Write-Output ($env:computername $env:username)

screenshot of autoformat bug -- repeated use is incremental - 4 steps

end of attached log

[Info  - 12:34:49 PM] Microsoft.PowerShell.EditorServices.Services.Analysis.PssaCmdletAnalysisEngine: Found 0 violations |
[Trace - 12:34:49 PM] Received notification 'textDocument/publishDiagnostics'.
Params: {
    "uri": "file:///c:/Users/cppmo_000/Documents/2020/powershell/reporting_bugs/vscode-powershell/formatter%20deletes%20text/minimal-reproduction.ps1",
    "version": 0,
    "diagnostics": [
        {
            "range": {
                "start": {
                    "line": 6,
                    "character": 28
                },
                "end": {
                    "line": 8,
                    "character": 0
                }
            },
            "severity": 1,
            "code": 0,
            "source": "PowerShell",
            "message": "The string is missing the terminator: \"."
        }
    ]
}

interesting behavior

  1. The new test case contains \" which is not a PowerShell escape sequence, but maybe passing between the language server/addon it's not properly being escaped somewhere?
  2. whitespaceBetweenParameters is modifying strings directly, not the spacing between parameters
  3. running Format Document repeatedly results in more errors. The above example will modify the script every format up to the first 3 times.
  4. operators are not required

Environment data

> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.0.2
PSEdition                      Core
GitCommitId                    7.0.2
OS                             Microsoft Windows 10.0.18363
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0


> (Get-Module -ListAvailable PSScriptAnalyzer).Version | ForEach-Object { $_.ToString() }
1.19.0

VS Code settings.json

{
    "editor.wordWrap": "on",
    "files.insertFinalNewline": true,
    "files.trimFinalNewlines": true,
    "files.trimTrailingWhitespace": true,
    "powershell editor services.trace.server": "verbose",
    "powershell.buttons.showPanelMovementButtons": true,
    "powershell.buttons.showRunButtons": true,
    "powershell.codeFolding.enable": true,
    "powershell.codeFolding.showLastLine": true,
    "powershell.codeFormatting.addWhitespaceAroundPipe": true,
    "powershell.codeFormatting.autoCorrectAliases": true,
    "powershell.codeFormatting.ignoreOneLineBlock": true,
    "powershell.codeFormatting.pipelineIndentationStyle": "None",
    "powershell.codeFormatting.preset": "OTBS",
    "powershell.codeFormatting.useCorrectCasing": true,
    "powershell.codeFormatting.whitespaceBetweenParameters": true,
    "powershell.developer.editorServicesLogLevel": "Diagnostic",
    "powershell.enableProfileLoading": true,
    "[powershell]": {
        // powershell <move line up/down> is destructive when set to full
        "editor.autoIndent": "advanced",
        "editor.formatOnPaste": true,
        "editor.formatOnSave": false,
        "editor.formatOnType": true,
        "files.autoGuessEncoding": true,
        "files.encoding": "utf8bom",
    },
}

Visual Studio Code Extensions

Note: These are installed addons, they are not all enabled

  • ms-vscode.powershell-preview is enabled
  • ms-vscode.powershell is disabled
Visual Studio Code Extensions(Click to Expand)
Extension Author Version
nord-visual-studio-code arcticicestudio 0.14.0
better-toml bungcip 0.3.2
path-intellisense christian-kohler 2.2.1
bracket-pair-colorizer CoenraadS 1.0.61
bracket-pair-colorizer-2 CoenraadS 0.2.0
vscode-markdownlint DavidAnson 0.36.1
gitlens eamodio 10.2.2
vsc-community-material-theme Equinusocio 1.4.1
vsc-material-theme Equinusocio 32.8.0
vsc-material-theme-icons equinusocio 1.1.4
font-switcher evan-buss 3.1.0
vscode-firefox-debug firefox-devtools 2.9.0
code-runner formulahendry 0.11.0
vscode-theme-hydra juanmnl 3.1.0
mypy matangover 0.1.4
rainbow-csv mechatroner 1.7.0
code-point medo64 1.7.0
mssql ms-mssql 1.9.0
python ms-python 2020.6.91350
remote-wsl ms-vscode-remote 0.44.4
cpptools ms-vscode 0.28.3
powershell ms-vscode 2020.6.0
powershell-preview ms-vscode 2020.6.1
vscode-typescript-tslint-plugin ms-vscode 1.2.3
debugger-for-chrome msjsdiag 4.12.8
vscode-json-transform octref 0.1.2
material-icon-theme PKief 4.2.0
vscode-powerquery PowerQuery 0.1.2
synthwave-vscode RobbOwen 0.1.6
bash-debug rogalmic 0.3.9
rust rust-lang 0.7.8
vscode-duotone-dark sallar 0.3.3
powerquerymlanguage sea1jxr 1.0.0
bash-beautify shakram02 0.1.1
markdown-preview-enhanced shd101wyy 0.5.12
unique-window-colors stuart 1.0.51
vscode-lldb vadimcn 1.5.3
vscodeintellicode VisualStudioExptTeam 1.2.9
debug webfreak 0.25.0
material-theme zhuangtongfa 3.8.3

logs and sample files.zip

@ghost ghost added the Needs: Triage 🔍 label Jul 12, 2020
@SydneyhSmith
Copy link
Collaborator

Thanks @ninmonkey for providing such detailed information and repro steps... this information will be helpful as we continue to investigate this issue, for our own tracking purposes I will link this to issue #1536 (as you mention) and mark as a duplicate

@ghost
Copy link

ghost commented Jul 15, 2020

This issue has been marked as duplicate and has not had any activity for 1 day. It will be closed for housekeeping purposes.

@ghost ghost closed this as completed Jul 15, 2020
@bergmeister
Copy link
Collaborator

I can reproduce with 1.19.0 but not with the latest version of master. Fix was in PR #1498. We will release 1.19.1 with this fix in the next weeks

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

No branches or pull requests

3 participants