-
Notifications
You must be signed in to change notification settings - Fork 498
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
[Preview-2020-5.0] Formatting broken when using default PipelineIndentationStyle setting value of None #2696
Comments
hmm @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? |
I updated the preview extension in my insider version of code and cannot repro. @PrzemyslawKlys Have you tried using the |
No change - i tried shorcut, right click format, > format document. I'll uninstall extension and try fresh |
Uninstall/install didn't help |
I tried switching to PowerShell 5.1 locally to be closer to your environment but it still works... Also tried VS Code stable |
@TylerLeonhardt the settings look to me. |
Another option is to run $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 |
It doesn't seem to touch things on the left side.. notice the Action on 11th line |
@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 |
@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" |
@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
}
}
} |
@PrzemyslawKlys Formatting therefore seems to generally work. Please supply the script where the |
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.
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) {
}
} On preview @{
Test = 'dfsf'
dffdf = 'dddff'
}
foreach ($Test in $Test1) {
foreach ($Test2 in TEst3) {
}
} |
@PrzemyslawKlys Your example formats fine for me with the PowerShell preview. Please try just commenting out all your settings once as a test ( |
@bergmeister The only problem is... I don't use custom settings except those available within VSCode. There's nothing to comment out. The settings that @TylerLeonhardt showed were not set by me. {
"workbench.colorTheme": "Monokai",
"workbench.iconTheme": "material-icon-theme",
"powershell.codeFormatting.preset": "OTBS",
"editor.fontSize": 12,
"search.showLineNumbers": true,
"terminal.integrated.scrollback": 30000,
"debug.inlineValues": true,
"editor.minimap.enabled": false,
"workbench.useExperimentalGridLayout": true,
"breadcrumbs.enabled": true,
"workbench.editor.highlightModifiedTabs": true,
"window.title": "${folderName}${separator}${activeEditorShort}",
"debug.openDebug": "neverOpen",
"typescript.implementationsCodeLens.enabled": true,
"powershell.developer.editorServicesLogLevel": "Diagnostic",
"editor.snippetSuggestions": "none",
"files.autoSave": "off",
"files.autoSaveDelay": 5000,
"explorer.confirmDragAndDrop": false,
"files.trimTrailingWhitespace": true,
"editor.renderWhitespace": "all",
"gitlens.blame.ignoreWhitespace": true,
"powershell.codeFormatting.useCorrectCasing": true,
"[powershell]": {
"editor.defaultFormatter": "ms-vscode.powershell-preview",
/* "editor.wordSeparators": "`~!@#%^&*()=+[{]}\\|;:'\",.<>/?" */
},
"[markdown]": {
"editor.defaultFormatter": "yzhang.markdown-all-in-one"
},
"files.encoding": "utf8bom",
"extensions.autoUpdate": true,
"window.zoomLevel": 0,
"editor.suggest.localityBonus": true,
"editor.suggest.maxVisibleSuggestions": 15,
"search.maintainFileSearchCache": true,
"extensions.showRecommendationsOnlyOnDemand": true,
"terminal.integrated.experimentalRefreshOnResume": true,
"html.format.indentInnerHtml": true,
"[html]": {
"editor.defaultFormatter": "HookyQR.beautify"
},
"[json]": {
"editor.defaultFormatter": "vscode.json-language-features"
},
"[jsonc]": {
"editor.defaultFormatter": "vscode.json-language-features"
},
"[javascript]": {
"editor.defaultFormatter": "vscode.typescript-language-features"
},
"cSpell.enabledLanguageIds": [
"asciidoc",
"c",
"cpp",
"csharp",
"css",
"git-commit",
"go",
"handlebars",
"html",
"jade",
"java",
"javascript",
"javascriptreact",
"json",
"jsonc",
"latex",
"less",
"markdown",
"php",
"plaintext",
"pug",
"python",
"restructuredtext",
"rust",
"scala",
"scss",
"text",
"typescript",
"typescriptreact",
"yaml",
"yml"
],
"cSpell.userWords": [
"Kłys",
"Przemysław",
"dashimo",
"documentimo"
],
"sqltools.telemetry": false,
"mssql.copyIncludeHeaders": true,
"peacock.favoriteColors": [
{
"name": "Angular Red",
"value": "#b52e31"
},
{
"name": "Auth0 Orange",
"value": "#eb5424"
},
{
"name": "Azure Blue",
"value": "#007fff"
},
{
"name": "C# Purple",
"value": "#68217A"
},
{
"name": "Gatsby Purple",
"value": "#639"
},
{
"name": "Go Cyan",
"value": "#5dc9e2"
},
{
"name": "Java Blue-Gray",
"value": "#557c9b"
},
{
"name": "JavaScript Yellow",
"value": "#f9e64f"
},
{
"name": "Mandalorian Blue",
"value": "#1857a4"
},
{
"name": "Node Green",
"value": "#215732"
},
{
"name": "React Blue",
"value": "#00b3e6"
},
{
"name": "Something Different",
"value": "#832561"
},
{
"name": "Vue Green",
"value": "#42b883"
}
],
"editor.smoothScrolling": true,
"editor.tabCompletion": "on",
"html.format.wrapLineLength": 0,
"powershell.codeFormatting.autoCorrectAliases": true,
"editor.detectIndentation": false,
"editor.renderControlCharacters": false,
"editor.suggest.snippetsPreventQuickSuggestions": false,
"terminal.integrated.rendererType": "experimentalWebgl",
"powershell.powerShellDefaultVersion": "Windows PowerShell (x64)",
"editor.fontFamily": "Fira Code Retina, Consolas, Monaco, 'Courier New', monospace",
//"editor.fontFamily": "Fira Code",
"editor.fontLigatures": false,
"workbench.colorCustomizations": {
//https://code.visualstudio.com/api/references/theme-color
//"titleBar.activeBackground": "#ff0000"
//"statusBar.background": "#ff0000"
"statusBar.debuggingBackground": "#FF7F00"
},
"powershell.integratedConsole.suppressStartupBanner": true,
"explorer.compactFolders": false,
"grammarly.userWords": [
"ADEssentials"
],
"editor.codeActionsOnSave": {
"source.fixAll.markdownlint": true
},
"markdownlint.config": {
"MD033": false
},
"timeline.showView": true,
"terminal.integrated.shell.windows": "C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
"javascript.updateImportsOnFileMove.enabled": "always",
"powershell.integratedConsole.forceClearScrollbackBuffer": true,
"git.enableCommitSigning": true
} |
"powershell.codeFormatting.preset": "OTBS",
"powershell.codeFormatting.useCorrectCasing": true,
"powershell.codeFormatting.autoCorrectAliases": true,
"[powershell]": {
"editor.defaultFormatter": "ms-vscode.powershell-preview",
}, Here are the PowerShell formatting settings @bergmeister (I'm pretty sure you can delete that last one... I don't think it really does anything for you?) |
@PrzemyslawKlys I tried your settings and still cannot repro. One more suggestion would be to try to disable all extensions except the PowerShell extension. The settings that Tyler showed you are a low level detail, which is a result of the combination of |
I've disabled everything except PowerShell Preview. No change. |
@TylerLeonhardt With your settings, I can reproduce that the formatter doesn't do anything, however, the {
"powershell.codeFormatting.preset": "OTBS",
"powershell.developer.editorServicesLogLevel": "Diagnostic",
"powershell.codeFormatting.useCorrectCasing": true,
"[powershell]": {
"editor.defaultFormatter": "ms-vscode.powershell-preview",
},
"powershell.codeFormatting.autoCorrectAliases": true,
"powershell.powerShellDefaultVersion": "Windows PowerShell (x64)",
"powershell.integratedConsole.suppressStartupBanner": true,
"powershell.integratedConsole.forceClearScrollbackBuffer": true
} |
@PrzemyslawKlys you don't have any workspace level settings do you? That would be in a .vscode folder in the folder you have open in VS Code. |
@TylerLeonhardt Not using any workspace settings. Since PowerShell doesn't really support multiple workspaces for formatting I don't use that. |
Just to add, non-preview extension just works. So my settings are not impacting standard extension. |
I'm happy to share screen (teamviewer) or teams or anything you wish to do. |
@PrzemyslawKlys I can now sometimes repro, but behaviour is not consistent, give me a bit more time in the meantime. P.S. In your repro example, you are missing a dollar before |
ye, typo during typing ;) Doesn't change if it's dollar or not for formatting. |
I can reproduce now, it was actually one of my settings that caused the bug to not occur. The culprit seems to be |
Yep, setting it to NoIndentation works :-) |
I found another bug - when you enable Import-Module "$PSScriptRoot\..\GPoZaurr.psd1" -Force
$Type = 'Test'
'Onet','Evotec' | Where-Object {
if ($Type -eq 'Test') {
#$_
}
} is converted to:
So basically the first line looses "powershell.codeFormatting.pipelineIndentationStyle": "NoIndentation",
"powershell.codeFormatting.trimWhitespaceAroundPipe": true The moment I add |
A simple repro for PSSA is. Thanks for your patience @PrzemyslawKlys . @TylerLeonhardt I will investigate the cause but a simple quick fix would be revert the default of Invoke-Formatter -Settings @{ IncludeRules = @('PSUseConsistentIndentation'); Rules = @{ PSUseConsistentIndentation = @{ Enable = $true; PipelineIndentation = 'None' } } } -ScriptDefinition @'
@{
foo = "dfsf"
bar = "dddff"
}
foreach ($Test in $Test1) {
foreach ($Test2 in $TEst3) {
}
}
'@ I opened this PSSA issue for the new issue around |
Will do. Sorry, |
No worries, thanks for bringing up the issue and being patient with us. |
@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. |
@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. |
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? |
@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" |
@JustinGrote This should not happen, can you open a new issue for that one please? Do you know why that would be @TylerLeonhardt |
@PrzemyslawKlys or @TylerLeonhardt Can you please rename this issue to something like: |
Done |
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
PowerShell Information
Visual Studio Code Extensions
Visual Studio Code Extensions(Click to Expand)
The text was updated successfully, but these errors were encountered: