Skip to content

[Preview-2020-5.0] Formatting broken when using default PipelineIndentationStyle setting value of None #2696

Closed

Description

Issue Description

I am experiencing a problem with... formatting. Pressing shortcuts or choosing from menu doesn't work. F8 / F5 works fine. Intellisense works as well.

1589385610-e162f223-5ab6-4d60-bdbb-aa205fe17f2f1589385348230.zip

Attached Logs

Follow the instructions in the README about
capturing and sending logs.

Environment Information

Visual Studio Code

Name Version
Operating System Windows_NT x64 10.0.18363
VSCode 1.45.0
PowerShell Extension Version 2020.5.0

PowerShell Information

Name Value
PSVersion 5.1.18362.752
PSEdition Desktop
PSCompatibleVersions 1.0 2.0 3.0 4.0 5.0 5.1.18362.752
BuildVersion 10.0.18362.752
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
beautify HookyQR 1.5.0
bracket-pair-colorizer-2 CoenraadS 0.1.3
code-settings-sync Shan 3.4.3
excel-to-markdown-table csholmq 1.2.2
gistfs vsls-contrib 0.0.67
gitdoc vsls-contrib 0.0.6
github-linker gimenete 0.2.3
gitlens eamodio 10.2.1
html-preview-vscode george-alisson 0.2.5
markdown-all-in-one yzhang 2.8.0
markdown-preview-enhanced shd101wyy 0.5.3
markdown-shortcuts mdickin 0.12.0
material-icon-theme PKief 4.1.0
pdf tomoki1207 0.6.0
powershell-preview ms-vscode 2020.5.0
project-manager alefragnani 10.12.0
rainbow-csv mechatroner 1.7.0
reg ionutvmi 1.0.1
vscode-html-css ecmel 0.2.3
vscode-markdownlint DavidAnson 0.35.1
vscode-pull-request-github GitHub 0.16.0
vscode-toggle-quotes BriteSnow 0.3.2
vscode-versionlens pflannery 0.27.0
vscode-wakatime WakaTime 4.0.0
vscode-yaml redhat 0.8.0
xml DotJoshJohnson 2.5.0

Activity

  1. ghost added
    Needs: Triage
    on May 13, 2020
  2. TylerLeonhardt commented on May 13, 2020

    @TylerLeonhardt
    Member

    hmm Christoph Bergmeister (@bergmeister) looks like these are the settings used:

    {
        "IncludeRules": [
            "PSPlaceCloseBrace",
            "PSPlaceOpenBrace",
            "PSUseConsistentWhitespace",
            "PSUseConsistentIndentation",
            "PSAlignAssignmentStatement"
        ],
        "Rules": {
            "PSUseConsistentIndentation": {
                "IndentationSize": 4,
                "Enable": true,
                "PipelineIndentation": 3,
                "Kind": "space"
            },
            "PSAvoidUsingCmdletAliases": {},
            "PSPlaceOpenBrace": {
                "Enable": true,
                "NewLineAfter": true,
                "OnSameLine": true,
                "IgnoreOneLineBlock": true
            },
            "PSAlignAssignmentStatement": {
                "Enable": true,
                "CheckHashtable": true
            },
            "PSUseCorrectCasing": {
                "Enable": true
            },
            "PSPlaceCloseBrace": {
                "Enable": true,
                "NewLineAfter": false,
                "IgnoreOneLineBlock": true
            },
            "PSUseConsistentWhitespace": {
                "CheckPipe": true,
                "CheckSeparator": true,
                "CheckOpenBrace": true,
                "Enable": true,
                "CheckParameter": false,
                "CheckOpenParen": true,
                "CheckPipeForRedundantWhitespace": false,
                "CheckInnerBrace": true,
                "CheckOperator": true
            }
        }
    }

    Does that look alright to you?

  3. bergmeister commented on May 13, 2020

    @bergmeister
    Contributor

    I updated the preview extension in my insider version of code and cannot repro. Przemysław Kłys (@PrzemyslawKlys) Have you tried using the > Format Document command? Because I know some other extensions can override the shortcut for formatting a selection

  4. PrzemyslawKlys commented on May 13, 2020

    @PrzemyslawKlys
    ContributorAuthor

    No change - i tried shorcut, right click format, > format document. I'll uninstall extension and try fresh

  5. PrzemyslawKlys commented on May 13, 2020

    @PrzemyslawKlys
    ContributorAuthor

    Uninstall/install didn't help

  6. bergmeister commented on May 13, 2020

    @bergmeister
    Contributor

    I tried switching to PowerShell 5.1 locally to be closer to your environment but it still works... Also tried VS Code stable

  7. bergmeister commented on May 13, 2020

    @bergmeister
    Contributor

    TylerLeonhardt the settings look to me.

  8. TylerLeonhardt commented on May 13, 2020

    @TylerLeonhardt
    Member

    Another option is to run PSScriptAnalyzer directly to see if anything changes:

    $jsonRules = @'
    {
        "IncludeRules": [
            "PSPlaceCloseBrace",
            "PSPlaceOpenBrace",
            "PSUseConsistentWhitespace",
            "PSUseConsistentIndentation",
            "PSAlignAssignmentStatement"
        ],
        "Rules": {
            "PSUseConsistentIndentation": {
                "IndentationSize": 4,
                "Enable": true,
                "PipelineIndentation": 3,
                "Kind": "space"
            },
            "PSAvoidUsingCmdletAliases": {},
            "PSPlaceOpenBrace": {
                "Enable": true,
                "NewLineAfter": true,
                "OnSameLine": true,
                "IgnoreOneLineBlock": true
            },
            "PSAlignAssignmentStatement": {
                "Enable": true,
                "CheckHashtable": true
            },
            "PSUseCorrectCasing": {
                "Enable": true
            },
            "PSPlaceCloseBrace": {
                "Enable": true,
                "NewLineAfter": false,
                "IgnoreOneLineBlock": true
            },
            "PSUseConsistentWhitespace": {
                "CheckPipe": true,
                "CheckSeparator": true,
                "CheckOpenBrace": true,
                "Enable": true,
                "CheckParameter": false,
                "CheckOpenParen": true,
                "CheckPipeForRedundantWhitespace": false,
                "CheckInnerBrace": true,
                "CheckOperator": true
            }
        }
    }
    '@
    
    $scriptContent = Get-Content -Raw ./path/to/file.ps1
    Invoke-Formatter -ScriptDefinition $scriptContent -Settings ($jsonRules | ConvertFrom-Json -AsHashtable)

    This actually gets me Invoke-Formatter: Cannot parse settings. Will abort the invocation. So either the settings aren't correct or (more likely) I did it wrong.

  9. PrzemyslawKlys commented on May 13, 2020

    @PrzemyslawKlys
    ContributorAuthor

    Ok, i've it reproduced - only part of formatting doesn't work...

    Formatting

  10. PrzemyslawKlys commented on May 13, 2020

    @PrzemyslawKlys
    ContributorAuthor

    It doesn't seem to touch things on the left side.. notice the Action on 11th line

  11. bergmeister commented on May 13, 2020

    @bergmeister
    Contributor

    TylerLeonhardt Running this exact repro script of you, would also throw a settings parser error in 1.18.3, so does not seem to be a regression

  12. TylerLeonhardt commented on May 13, 2020

    @TylerLeonhardt
    Member

    Christoph Bergmeister (@bergmeister) sorry I was side-chaining 😅 that was more of a "Chris pls help fix my script to do what I want" than "PSSA is broken"

  13. bergmeister commented on May 13, 2020

    @bergmeister
    Contributor

    TylerLeonhardt No worries, something is wrong in the format of how you convert the JSON because the following (manually converted) works fine:

    Invoke-Formatter -ScriptDefinition 'gci' -Settings @{
        "IncludeRules" = @(
            "PSPlaceCloseBrace",
            "PSPlaceOpenBrace",
            "PSUseConsistentWhitespace",
            "PSUseConsistentIndentation",
            "PSAlignAssignmentStatement"
        );
        "Rules"        = @{
            "PSAvoidUsingCmdletAliases"  = @{}
            "PSUseConsistentIndentation" = @{
                "IndentationSize"     = 4;
                "Enable"              = $true;
                "PipelineIndentation" = 3;
                "Kind"                = "space"
            };
            "PSPlaceOpenBrace"           = @{
                "Enable"             = $true;
                "NewLineAfter"       = $true;
                "OnSameLine"         = $true;
                "IgnoreOneLineBlock" = $true
            };
            "PSAlignAssignmentStatement" = @{
                "Enable"         = $true;
                "CheckHashtable" = $true
            };
            "PSUseCorrectCasing"         = @{
                "Enable" = $true
            };
            "PSPlaceCloseBrace"          = @{
                "Enable"             = $true;
                "NewLineAfter"       = $false;
                "IgnoreOneLineBlock" = $true
            };
            "PSUseConsistentWhitespace"  = @{
                "CheckPipe"                       = $true;
                "CheckSeparator"                  = $true;
                "CheckOpenBrace"                  = $true;
                "Enable"                          = $true;
                "CheckParameter"                  = $false;
                "CheckOpenParen"                  = $true;
                "CheckPipeForRedundantWhitespace" = $false;
                "CheckInnerBrace"                 = $true;
                "CheckOperator"                   = $true
            }
        }
    }
  14. bergmeister commented on May 13, 2020

    @bergmeister
    Contributor

    Przemysław Kłys (@PrzemyslawKlys) Formatting therefore seems to generally work. Please supply the script where the Action hashtable entry does not get corrected. Also: If you revert to the previous extension version and reload, does it still repro? Have you got PSSA 1.19.0 installed locally or do you just use the version that comes out of the box with the extension (both are the same so, no worries)

  15. PrzemyslawKlys commented on May 13, 2020

    @PrzemyslawKlys
    ContributorAuthor

    Christoph Bergmeister (@bergmeister)

    Yes, I jumped the gun a bit because I just was working on a different file that didn't have hash. Generally last preview didn't have an issue and i have installed 1.19.0 before newest preview so not sure if it's related to PSScriptAnalyzer code, more like some configuration on VsCode part.

    PS C:\Support\GitHub\GpoZaurr> get-module -ListAvailable PSScriptAnalyzer
    
    
    
        Directory: C:\Users\przemyslaw.klys\Documents\WindowsPowerShell\Modules
    
    
    ModuleType Version    Name                                ExportedCommands
    ---------- -------    ----                                ----------------
    Script     1.19.0     PSScriptAnalyzer                    {Get-ScriptAnalyzerRule, Invoke-ScriptAnalyzer, Invoke-Formatter}
    
    
        Directory: C:\Program Files\WindowsPowerShell\Modules
    
    
    ModuleType Version    Name                                ExportedCommands
    ---------- -------    ----                                ----------------
    Script     1.18.3     PSScriptAnalyzer                    {Get-ScriptAnalyzerRule, Invoke-ScriptAnalyzer, Invoke-Formatter}
    Script     1.18.2     PSScriptAnalyzer                    {Get-ScriptAnalyzerRule, Invoke-ScriptAnalyzer, Invoke-Formatter}
    Script     1.18.1     PSScriptAnalyzer                    {Get-ScriptAnalyzerRule, Invoke-ScriptAnalyzer, Invoke-Formatter}
    
    
        Directory: C:\Users\przemyslaw.klys\.vscode\extensions\ms-vscode.powershell-preview-2020.5.0\modules
    
    
    ModuleType Version    Name                                ExportedCommands
    ---------- -------    ----                                ----------------
    Script     1.19.0     PSScriptAnalyzer                    {Get-ScriptAnalyzerRule, Invoke-ScriptAnalyzer, Invoke-Formatter}
    
    

    Here's the code I am testing it with:

    @{
    Test  = 'dfsf'
        dffdf = 'dddff'
    }
    
    foreach ($Test in $Test1) {
    foreach ($Test2 in TEst3) {
    
    }
    }

    Code above replicates it. On PowerShell (not preview) this is translated to

    @{
        Test  = 'dfsf'
        dffdf = 'dddff'
    }
    
    foreach ($Test in $Test1) {
        foreach ($Test2 in TEst3) {
    
        }
    }

    image

    On preview

    @{
    Test      = 'dfsf'
        dffdf = 'dddff'
    }
    
    foreach ($Test in $Test1) {
    foreach ($Test2 in TEst3) {
    
    }
    }

    image

  16. 18 remaining items

  17. JustinGrote commented on May 13, 2020

    @JustinGrote
    Collaborator

    Christoph Bergmeister (@bergmeister) I've also noticed something: If you have an older version of PSScriptAnalyzer (1.18.* in my case), this is taking precedence and the assemblies for this are loading in the integrated terminal, rather than the "bundled" vscode one. This prevented for instance parameter casing "format document" from working correctly until I deleted my "modules" version of PSSA and reloading, then it worked fine.

    You may want to make sure the module load search order prefers the vscode bundled one.

    This is on a "fresh" load:
    image

  18. PrzemyslawKlys commented on May 13, 2020

    @PrzemyslawKlys
    ContributorAuthor

    That's weird, I have multiple versions and only new one loads?

    image

    image

  19. JustinGrote commented on May 13, 2020

    @JustinGrote
    Collaborator

    Przemysław Kłys (@PrzemyslawKlys) try removing your 1.19.0 in your modules folder, I'm saying if you only have the older version still installed, that one takes precedence.

    Even in your example, your modules folder one took precedence, I'm saying that the one in the powershell extensions folder bundled with vscode should take precedence even if it is older.

  20. PrzemyslawKlys commented on May 13, 2020

    @PrzemyslawKlys
    ContributorAuthor

    Sorry. You're correct.

    image

  21. PrzemyslawKlys commented on May 13, 2020

    @PrzemyslawKlys
    ContributorAuthor

    I am not sure I agree that it should take precedence tho? Newest one should be used - I often install PSScriptAnalyzer newer than in extension?

  22. JustinGrote commented on May 13, 2020

    @JustinGrote
    Collaborator

    Przemysław Kłys (@PrzemyslawKlys) well ideally it would use an AssemblyLoadContext like the other "builtin" modules so that this is a moot point, but regardless I'd be OK either way as long as it's "whatever the latest version is". Currently it's "Whatever is in Modules takes precedence regardless"

  23. bergmeister commented on May 13, 2020

    @bergmeister
    Contributor

    Justin Grote (@JustinGrote) This should not happen, can you open a new issue for that one please? Do you know why that would be TylerLeonhardt
    This also happens with the previous version of the preview extension.

  24. bergmeister commented on May 13, 2020

    @bergmeister
    Contributor

    Przemysław Kłys (@PrzemyslawKlys) or TylerLeonhardt Can you please rename this issue to something like:
    [Preview-2020-5.0] Formatting broken when using default PipelineIndentationStyle setting value of None

  25. changed the title [-]Formatting doesn't work on PowerShell Extension Version 2020.5.0[/-] [+][Preview-2020-5.0] Formatting broken when using default PipelineIndentationStyle setting value of None[/+] on May 13, 2020
  26. PrzemyslawKlys commented on May 13, 2020

    @PrzemyslawKlys
    ContributorAuthor

    Done

  27. removed
    Needs: Triage
    on May 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions