csharpier icon indicating copy to clipboard operation
csharpier copied to clipboard

VSCode setting `editor.formatOnSaveMode` is not respected

Open SamuelT-Beslogic opened this issue 3 months ago • 2 comments

Setting editor.formatOnSaveMode to either "modifications" or "modificationsIfAvailable" in .vscode/settings.json still causes CSharpier to format the entire file on save.

After filling in the Environments information below, I realize that the CSharpier version installed by the VSCode extension seems to be quite old. According to https://github.com/belav/csharpier/issues/659#issuecomment-2495546313 and https://github.com/belav/csharpier/pull/1376, this feature was added in 0.30.2, maybe the version shipped with the VSCode extension should be updated? Given how this affects an Editor feature.

Environments

  • IDE Version: 1.104.0 (user setup)
  • Extension Version: 2.0.8
  • CSharpier Version: %LOCALAPPDATA%\CSharpier\0.21.0 (installed by the extension) will NOT be the same as the extension version
  • Operating System: Version 10.0.26100 Numéro 26100
  • .csharpierrc Settings: N/A
  • .editorconfig Settings: .editorconfig.txt

Log Output

Steps to reproduce

In VSCode settings (I did it in my workspace's .vscode/settings.json)

{
  "editor.formatOnSaveMode": "modifications",
}
namespace TestNameSpace
{
   
}

Save without formatting. Stage, commit.

Save. See the file change to

namespace TestNameSpace { }

Expected behavior

No file change (should only format modifications)

Actual behavior

Entire file is formatted.

SamuelT-Beslogic avatar Sep 12 '25 19:09 SamuelT-Beslogic

The version installed by the extension is dependent on the version of csharpier you have installed globally or the one you have installed in your project. You'll need to update the global and/or local version of the tool and then reload the project if it is open.

belav avatar Sep 12 '25 21:09 belav

I didn't remember installing CSharpier globally, I must've done so years ago when first looking into CSharp tooling (then didn't touch it until recently), so I just assumed I hadn't and the version came with the extension !

I uninstalled csharpier (dotnet tool uninstall --global csharpier), re-installed it (dotnet tool install --global csharpier). Manually deleted %LOCALAPPDATA%\CSharpier\0.21.0. Then restarted VSCode entirely. I'm now on 1.1.2 (as per csharpier --version) and I'm still getting the issue.

For reference, just to reduce possible issues, formatting with C# Dev Kit does respect "modifications only". (tested by disabling CSharpier for VSCode and setting "C#" as the default formatter)

CSharpier applies its modifications whether it is the default formatter or not (that behaviour is actually useful to me as it allows me to try out CSharpier w/o changing the default formatter for everyone, if only it didn't format entire files)

SamuelT-Beslogic avatar Sep 15 '25 16:09 SamuelT-Beslogic