vscode-csharp icon indicating copy to clipboard operation
vscode-csharp copied to clipboard

C# code formatter ignores extension setting (always on)

Open Kirisoup opened this issue 8 months ago • 9 comments

Type: Bug

Issue Description

C# codes are auto-formatted even when csharp.format.enable (and other formatter related settings) are disabled.

The issue only occurs since version 2.69.25, and should have nothing to do with C# Dev Kit.

Steps to Reproduce

Install 2.69.25 or newer of the extension. You don't need C# Dev Kit.

Turn off csharp.format.enable (and maybe the vscode formater settings).

Edit a csharp file in a dotnet project.

Expected Behavior

Code should not be formatted when csharp.format.enable = false.

Actual Behavior

Is formatted even if so.

Logs

C# log

2025-05-21 15:36:37.304 [info] Locating .NET runtime version 9.0.1
2025-05-21 15:36:38.049 [info] Dotnet path: C:\Program Files\dotnet\dotnet.exe
2025-05-21 15:36:38.049 [info] Activating C# + C# Dev Kit...
2025-05-21 15:36:38.926 [info] [stdout] {"pipeName":"\\\\.\\pipe\\566821b3"}

2025-05-21 15:36:38.926 [info] received named pipe information from server
2025-05-21 15:36:38.927 [info] client has connected to server
2025-05-21 15:36:39.034 [info] [Info  - 3:36:39 PM] [Program] Language server initialized
2025-05-21 15:36:42.228 [info] [Info  - 3:36:42 PM] [serviceBroker/connect] [WorkspaceProjectFactoryService] Project D:\dev\csharp\***.csproj loaded by C# Dev Kit
2025-05-21 15:36:56.825 [info] [Info  - 3:36:56 PM] [serviceBroker/connect] [WorkspaceProjectFactoryService] Project D:\dev\csharp\***.csproj loaded by C# Dev Kit
2025-05-21 15:43:07.838 [info] Locating .NET runtime version 9.0.1
2025-05-21 15:43:08.847 [info] Dotnet path: C:\Program Files\dotnet\dotnet.exe
2025-05-21 15:43:08.847 [info] Activating C# + C# Dev Kit...
2025-05-21 15:43:10.036 [info] [stdout] {"pipeName":"\\\\.\\pipe\\a9361b94"}

2025-05-21 15:43:10.036 [info] received named pipe information from server
2025-05-21 15:43:10.036 [info] client has connected to server
2025-05-21 15:43:10.154 [info] [Info  - 3:43:10 PM] [Program] Language server initialized
2025-05-21 15:43:13.855 [info] [Info  - 3:43:13 PM] [serviceBroker/connect] [WorkspaceProjectFactoryService] Project D:\dev\csharp\***.csproj loaded by C# Dev Kit
2025-05-21 15:43:25.945 [info] [Info  - 3:43:25 PM] [serviceBroker/connect] [WorkspaceProjectFactoryService] Project D:\dev\csharp\***.csproj loaded by C# Dev Kit
2025-05-21 15:44:14.549 [info] Locating .NET runtime version 9.0.1
2025-05-21 15:44:15.961 [info] Dotnet path: C:\Program Files\dotnet\dotnet.exe
2025-05-21 15:44:15.961 [info] Activating C# + C# Dev Kit...
2025-05-21 15:44:16.961 [info] [stdout] {"pipeName":"\\\\.\\pipe\\4b0b0b16"}

2025-05-21 15:44:16.961 [info] received named pipe information from server
2025-05-21 15:44:16.961 [info] client has connected to server
2025-05-21 15:44:17.062 [info] [Info  - 3:44:17 PM] [Program] Language server initialized
2025-05-21 15:44:20.536 [info] [Info  - 3:44:20 PM] [serviceBroker/connect] [WorkspaceProjectFactoryService] Project D:\dev\csharp\***.csproj loaded by C# Dev Kit
2025-05-21 15:44:34.257 [info] [Info  - 3:44:34 PM] [serviceBroker/connect] [WorkspaceProjectFactoryService] Project D:\dev\csharp\***.csproj loaded by C# Dev Kit

C# LSP Trace Logs

Environment information

VSCode version: 1.100.2 C# Extension: 2.76.27 Using OmniSharp: false

Dotnet Information .NET SDK: Version: 10.0.100-preview.3.25201.16 Commit: 9dee3cf508 Workload version: 10.0.100-manifests.ef4f854f MSBuild version: 17.14.0-preview-25177-05+903614e16

Runtime Environment: OS Name: Windows OS Version: 10.0.19045 OS Platform: Windows RID: win-x64 Base Path: C:\Program Files\dotnet\sdk\10.0.100-preview.3.25201.16\

.NET workloads installed: There are no installed workloads to display. Configured to use workload sets when installing new manifests. Workloads are configured to install and update using workload versions, but none were found. Run "dotnet workload restore" to install a workload version.

Host: Version: 10.0.0-preview.3.25171.5 Architecture: x64 Commit: 0a33e18a0b

.NET SDKs installed: 5.0.408 [C:\Program Files\dotnet\sdk] 6.0.428 [C:\Program Files\dotnet\sdk] 7.0.317 [C:\Program Files\dotnet\sdk] 8.0.311 [C:\Program Files\dotnet\sdk] 9.0.203 [C:\Program Files\dotnet\sdk] 10.0.100-preview.3.25201.16 [C:\Program Files\dotnet\sdk]

.NET runtimes installed: Microsoft.AspNetCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.19 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 7.0.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 8.0.15 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 9.0.0-preview.6.24328.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 9.0.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 10.0.0-preview.3.25172.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 2.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.28 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.19 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 7.0.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 8.0.15 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 9.0.0-preview.6.24327.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 9.0.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 10.0.0-preview.3.25171.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.8 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.19 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 7.0.8 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 8.0.15 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 9.0.0-preview.6.24327.6 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 9.0.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 10.0.0-preview.3.25174.1 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found: x86 [C:\Program Files (x86)\dotnet]

Environment variables: Not set

global.json file: Not found

Learn more: https://aka.ms/dotnet/info

Download .NET: https://aka.ms/dotnet/download

Visual Studio Code Extensions
Extension Author Version Folder Name
archive-browser minifigone 0.3.2 minifigone.archive-browser-0.3.2
batch-rename-extension JannisX11 0.0.6 jannisx11.batch-rename-extension-0.0.6
codesnap adpyke 1.3.4 adpyke.codesnap-1.3.4-universal
csdevkit ms-dotnettools 1.19.63 ms-dotnettools.csdevkit-1.19.63-win32-x64
csharp ms-dotnettools 2.76.27 ms-dotnettools.csharp-2.76.27-win32-x64
custom-ui-style subframe7536 0.5.7 subframe7536.custom-ui-style-0.5.7
gruvbox-material-icon-theme JonathanHarty 1.1.5 jonathanharty.gruvbox-material-icon-theme-1.1.5
hexeditor ms-vscode 1.11.1 ms-vscode.hexeditor-1.11.1
markdown-all-in-one yzhang 3.6.3 yzhang.markdown-all-in-one-3.6.3
msbuild-solution-syntax deitry 0.0.1 deitry.msbuild-solution-syntax-0.0.1
output-colorizer IBM 0.1.2 ibm.output-colorizer-0.1.2
smartmulticursor idanp 0.0.4 idanp.smartmulticursor-0.0.4
snbt Tnze 0.1.0 tnze.snbt-0.1.0
vscode-dotnet-runtime ms-dotnettools 2.3.3 ms-dotnettools.vscode-dotnet-runtime-2.3.3
vscode-json5 mrmlnc 1.0.0 mrmlnc.vscode-json5-1.0.0
vscode-stardew-icon-theme klyap 0.0.7 klyap.vscode-stardew-icon-theme-0.0.7
yuyuko-vim-vsc hylwxqwq 0.2.1 hylwxqwq.yuyuko-vim-vsc-0.2.1

Extension version: 2.76.27 VS Code version: Code 1.100.2 (848b80aeb52026648a8ff9f7c45a9b0a80641e2e, 2025-05-14T21:47:40.416Z) OS version: Windows_NT x64 10.0.19045 Modes:

Kirisoup avatar May 21 '25 09:05 Kirisoup

Sorry accidentally closed

Kirisoup avatar May 21 '25 09:05 Kirisoup

A recording demonstrating the behavior

A recording demonstrating the behavior

Kirisoup avatar May 21 '25 09:05 Kirisoup

We started shipping the extension with formatOnType enabled for C# files. This improved the typing experience in certain cases (pressing enter after an opening brace for instance).

As a workaround while we collect more feedback about this change, you can use the query formatOnType @lang:csharp in Settings to disable it. Or, if you feel more comfortable editing the settings.json directly, you can add the following.

    "[csharp]": {
        "editor.formatOnType": false,
    },

JoeRobich avatar May 21 '25 13:05 JoeRobich

@JoeRobich should we potentially rename the csharp.format.enable setting? It is only applicable to O# (and is in the O# category). But maybe we should rename to omnisharp.format.enable?

dibarbet avatar May 21 '25 20:05 dibarbet

Probably need to deprecate it and the semanticHighlight.enable options. Now that there are ways to configure options per language.

JoeRobich avatar May 21 '25 20:05 JoeRobich

We started shipping the extension with formatOnType enabled for C# files. This improved the typing experience in certain cases (pressing enter after an opening brace for instance).

As a workaround while we collect more feedback about this change, you can use the query formatOnType @lang:csharp in Settings to disable it. Or, if you feel more comfortable editing the settings.json directly, you can add the following.

"[csharp]": {
    "editor.formatOnType": false,
},

I've lost some hairs as they were being pulled out because of this change and I could not figure out what was triggering a whole file auto format once setting this to false the file stopped changing on every hit of new line. Thanks for the workaround!

dalexsoto avatar Jul 03 '25 18:07 dalexsoto

Yeah this sucks.

laurenceokite avatar Aug 12 '25 22:08 laurenceokite

@JoeRobich We started shipping the extension with formatOnType enabled for C# files. This improved the typing experience in certain cases (pressing enter after an opening brace for instance).

As a workaround while we collect more feedback about this change, you can use the query formatOnType @lang:csharp in Settings to disable it. Or, if you feel more comfortable editing the settings.json directly, you can add the following.

"[csharp]": {
    "editor.formatOnType": false,
},

I just lost an hour finding this. Thanks for nothing shipping an utter troll of a feature. 🤬

I had editor.formatOnType disabled forever, since it's a major annoyance. An extension adding a language-specific override, overrides that user-preference. So now I had to override the override. Great. And literally no decent signaling that this was added. Or that this even can be a thing for VSCode!

I take it the team that decided on this is unaware of the term 'selector specificity wars' in the context of CSS? If so - I'd encourage them to look it up. Might be a good warning for why you shouldn't do stuff like this.

rjgotten avatar Oct 08 '25 14:10 rjgotten

We started shipping the extension with formatOnType enabled for C# files. This improved the typing experience in certain cases (pressing enter after an opening brace for instance).

As a workaround while we collect more feedback about this change, you can use the query formatOnType @lang:csharp in Settings to disable it. Or, if you feel more comfortable editing the settings.json directly, you can add the following.

"[csharp]": {
    "editor.formatOnType": false,
},

This was working for me at some point, but not anymore. I have thrown literally everything at the wall and nothing is sticking:

"editor.formatOnPaste": false,
"editor.formatOnSave": false,
"editor.formatOnType": false,
"[csharp]": {
  "editor.defaultFormatter": null,
  "editor.formatOnSave": false,
  "editor.formatOnType": false,
  "editor.formatOnPaste": false,
}
"[cs]": {
  "editor.defaultFormatter": null,
  "editor.formatOnSave": false,
  "editor.formatOnType": false,
  "editor.formatOnPaste": false,
},
"[c#]": {
  "editor.defaultFormatter": null,
  "editor.formatOnSave": false,
  "editor.formatOnType": false,
  "editor.formatOnPaste": false,
},
"csharp.format.enable": false,
"omnisharp.useEditorFormattingSettings": false,
"razor.format.enable": false,

And yeah, I know [cs] and [c#] are not the correct language IDs, but... pure desperation.

EDIT: Fixes when I manually download v2.90.60 and install that. EDIT 2: This looks like the most recent formatting-related commit. Just in case it's helpful at all.

dannymcgee avatar Oct 10 '25 19:10 dannymcgee