Skip to content

Formatting is ignoring the Code Formatting settings #4283

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

Closed
6 tasks done
RansomVO opened this issue Nov 28, 2022 · 7 comments
Closed
6 tasks done

Formatting is ignoring the Code Formatting settings #4283

RansomVO opened this issue Nov 28, 2022 · 7 comments
Assignees
Labels
Area-Code Formatting Issue-Bug A bug to squash. Resolution-Fixed Will close automatically.

Comments

@RansomVO
Copy link

Prerequisites

  • I have written a descriptive issue title.
  • I have searched all open and closed issues to ensure it has not already been reported.
  • I have read the troubleshooting guide.
  • I am sure this issue is with the extension itself and does not reproduce in a standalone PowerShell instance.
  • I have verified that I am using the latest version of Visual Studio Code and the PowerShell extension.
  • If this is a security issue, I have read the security issue reporting guidance.

Summary

In Visual Studio Code, I have set Code Formatting settings to match my coding standards and have been using it successfully for a couple of years.
After an update I did a week or two ago, all of a sudden, when I save a file it reformats it, ignoring the settings:

  • New Line After Close Brace
  • New Line After Open Brace
  • Open Brace On Same Line

formatter

NOTE: Formatting is done correctly if I run it from a PowerShell window:

R:\>Invoke-Formatter -ScriptDefinition 'try {
>>     throw
>> }
>> catch {
>>     Write-Host "foobar"
>> }'
try {
    throw
}
catch {
    Write-Host "foobar"
}

PowerShell Version

PS R:\packer> $PSVersionTable

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

Visual Studio Code Version

PS R:\packer> code --version
1.73.1
6261075646f055b99068d3688932416f2346dd3b
x64

Extension Version

PS R:\packer> code --list-extensions --show-versions | Select-String powershell

[email protected]

Steps to Reproduce

In Visual Studio Code:

  1. Open file that was saved before I did the update so it is formatted correctly.
  2. Make a very simple modification. (E.G. add a space somewhere.)
  3. Save the file.

The file is re-formatted ignoring the settings

Visuals

formatter

Logs

EditorServices.1.log

@RansomVO RansomVO added the Issue-Bug A bug to squash. label Nov 28, 2022
@ghost ghost added the Needs: Triage Maintainer attention needed! label Nov 28, 2022
@andyleejordan
Copy link
Member

What do you have your powershell.codeFormatting.preset set to? If it's anything other than Custom (the default) then my understanding is that it will override the other settings.

@andyleejordan
Copy link
Member

This may be irrelevant to your issue but your log helpfully pointed out this new error to me:

2022-11-28 08:25:05.831 -08:00 [FTL] Failed to handle request textDocument/codeAction 1256
System.MissingMethodException: Method not found: 'Void OmniSharp.Extensions.LanguageServer.Protocol.Models.Command.set_Arguments(Newtonsoft.Json.Linq.JArray)'.

Which I'm pretty sure is caused by PowerShell/PowerShellEditorServices#1947.

@RansomVO
Copy link
Author

In the simplest case (See image above) I have left powershell.codeFormatting.preset unspecified so it is the default. I did double-check in Settings UI and it does show up as Custom.
I did try setting it explicitly to "powershell.codeFormatting.preset": "Custom" but still have the same results.

@andyleejordan
Copy link
Member

Hello! Can you please try the latest PowerShell Preview for VS Code and see if this is fixed?

@andyleejordan andyleejordan added Needs: Fix Verification Please verify the fix for us! and removed Needs: Triage Maintainer attention needed! labels Nov 29, 2022
@andyleejordan andyleejordan self-assigned this Nov 29, 2022
@RansomVO
Copy link
Author

RansomVO commented Nov 30, 2022

YEAH!!!
That fixes it!

@andyleejordan
Copy link
Member

Great, thank you for confirming!

@andyleejordan andyleejordan added Area-Code Formatting Resolution-Fixed Will close automatically. and removed Needs: Fix Verification Please verify the fix for us! labels Nov 30, 2022
@ghost ghost closed this as completed Nov 30, 2022
@ghost
Copy link

ghost commented Nov 30, 2022

This issue has been marked as fixed. It has been automatically closed for housekeeping purposes.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Code Formatting Issue-Bug A bug to squash. Resolution-Fixed Will close automatically.
Projects
None yet
Development

No branches or pull requests

2 participants