Code formatting runs unexpected sometimes
Environment data
dotnet --info output:
.NET SDK:
Version: 9.0.202
Commit: 3a53853c30
Workload version: 9.0.200-manifests.21502d11
MSBuild version: 17.13.13+1c2026462
运行时环境: OS Name: Windows OS Version: 10.0.19045 OS Platform: Windows RID: win-x64 Base Path: C:\Program Files\dotnet\sdk\9.0.202\
已安装 .NET 工作负载: 没有要显示的已安装工作负载。 配置为在安装新清单时使用 loose manifests。
Host: Version: 9.0.3 Architecture: x64 Commit: 831d23e561
.NET SDKs installed: 6.0.405 [C:\Program Files\dotnet\sdk] 7.0.400 [C:\Program Files\dotnet\sdk] 8.0.302 [C:\Program Files\dotnet\sdk] 9.0.202 [C:\Program Files\dotnet\sdk]
.NET runtimes installed: Microsoft.AspNetCore.App 6.0.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.21 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 7.0.10 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 8.0.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 9.0.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 6.0.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.21 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 7.0.10 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 8.0.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 9.0.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 6.0.13 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.21 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 7.0.10 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 8.0.6 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 9.0.3 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Other architectures found: x86 [C:\Program Files (x86)\dotnet] registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]
Environment variables: Not set
global.json file: Not found
Learn more: https://aka.ms/dotnet/info
Download .NET: https://aka.ms/dotnet/download VS Code version:1.100.0 C# Extension version:2.72.34
C# logs
C# output window contents:Empty
See this page for collecting more detailed logs
Steps to reproduce
- Open a C# project
- Install C# extension
- Open a .cs file
- Right click and select source action
- Wait it to tell you "no code action avaliable" and see the file is unexpectly formatted
This also happend when using the extract interface and move to file refactor options
https://github.com/user-attachments/assets/9afc1cb0-1fad-40d2-a743-352d9ab877d5
Expected behavior
N/A
Actual behavior
N/A
Additional context
N/A
Have the same issue, vscode (1.100.1) started indenting the outer namespace recently (no more than a week).
It seems that an interaction between the C# (2.76.27) extension and vscode (1.100.1) is causing the problem.
In addition to the C# (2.76.27) extension, I'm using C# Dev Kit (1.19.63) and Unity (1.1.2).
The bug is not present:
- in C++
- When disabling the
C#extension and stuff depending on it;C# Dev KitandUnity
The bug is present:
- If the
C#extension is enabled, butC# Dev Kitand/orUnityare disabled. - When downgrading the
C#,C# Dev KitandUnityextensions (to versions from ~3 months ago). - When upgrading the
C#,C# Dev KitandUnityextensions to the pre-release. - When
C#,C# Dev KitandUnityare current, and "editor.autoIndent" is set "none".
I have not tried downgrading vscode itself.
Yeah, totally right, 5/7 days ago vsCode was running OK. With last version and latest versions of all extensions with GitHub Copilot enabled, this is a non sense.
I have a solution with 5 projects, almost 600 files.
Each time I press CTRL+S to save the file, it takes from 2 to 8 seconds to just format the document!!!
Also copilot suggestions take from 4 to 6 seconds to show up.
If there is a mistake on the c# syntax, it takes up to 30 seconds to mark it with the bottom red line.
I've been working on this very project for the last 12 months, and 5/7 days ago there was no problem, but the moment I've installed last version of vscode and upgrade all extensions, this is awful.
Can you confirm if VSCode 1.100.2 also reproduces the issue? If anyone has a project they can as well, please send it our way. I have not been able to trigger formatting to run unexpectedly.
Additionally, if you could collect the trace level Extension Host logs:
- Set the log level to 'Trace'
- Share the contents of the 'Extension Host' output window and the C# LSP trace logs (see https://github.com/dotnet/vscode-csharp/blob/main/SUPPORT.md#c-lsp-trace-logs) that may help us track down what is causing format to run when it shouldn't.
Can you confirm if VSCode 1.100.2 also reproduces the issue? If anyone has a project they can as well, please send it our way. I have not been able to trigger formatting to run unexpectedly.
Additionally, if you could collect the trace level
Extension Hostlogs:
- Set the log level to 'Trace'
![]()
- Share the contents of the 'Extension Host' output window and the C# LSP trace logs (see https://github.com/dotnet/vscode-csharp/blob/main/SUPPORT.md#c-lsp-trace-logs) that may help us track down what is causing format to run when it shouldn't.
Tested in 1.100.2 and still exists https://github.com/user-attachments/assets/0879e205-59a6-4294-adc1-06ab82e8d575
A newly created project like this can also trigger the unexpected formatting running so I dont think its related to project
These are extension host log. The C# log window is empty and nothing to send 扩展宿主.log
@L2750558108 You are invoking the Source Action command. The RoslynLSP does not use the "source" code action kinds, so I would expect this to always be empty. However, these lines in your extension host might be a clue as to what is going on.
2025-05-21 09:51:39.915 [trace] CommandsConverter#DISPOSE omnisharp.runCodeAction /72
2025-05-21 09:51:39.915 [trace] CommandsConverter#DISPOSE omnisharp.runCodeAction /73
2025-05-21 09:51:39.915 [trace] CommandsConverter#DISPOSE omnisharp.runCodeAction /74
2025-05-21 09:51:39.915 [trace] CommandsConverter#DISPOSE omnisharp.runCodeAction /75
2025-05-21 09:51:39.915 [trace] CommandsConverter#DISPOSE omnisharp.runCodeAction /76
2025-05-21 09:51:39.915 [trace] CommandsConverter#DISPOSE omnisharp.runCodeAction /77
2025-05-21 09:51:39.915 [trace] CommandsConverter#DISPOSE omnisharp.runCodeAction /78
2025-05-21 09:51:39.915 [trace] CommandsConverter#DISPOSE omnisharp.runCodeAction /79
2025-05-21 09:51:39.915 [trace] CommandsConverter#DISPOSE omnisharp.runCodeAction /80
2025-05-21 09:51:39.915 [trace] CommandsConverter#DISPOSE omnisharp.runCodeAction /81
2025-05-21 09:51:39.915 [trace] CommandsConverter#DISPOSE omnisharp.runCodeAction /82
2025-05-21 09:51:39.915 [trace] CommandsConverter#DISPOSE omnisharp.runCodeAction /83
2025-05-21 09:51:39.915 [trace] CommandsConverter#DISPOSE omnisharp.runCodeAction /84
Are you using OmniSharp? OmniSharp supports a source.fixAll.csharp code action which will apply all code actions for the open document.
If you are using OmniSharp, can you also check your VS Code settings to ensure you don't have configuration like the following.
"editor.codeActionsOnSave": {
"source.fixAll.csharp": true
}
Are you using OmniSharp? OmniSharp supports a code action which will apply all code actions for the open document.
source.fixAll.csharp
Yes
If you are using OmniSharp, can you also check your VS Code settings to ensure you don't have configuration like the following.
"editor.codeActionsOnSave": { "source.fixAll.csharp": true }
I checked and didnt find config like this
Does this only happen when you use the "Source Action" context menu?
No, also happens when i use "Extract Interface" or "Move to file" refactor options. But these cases seems different, the unexpected formatting trigger by "Source Action" wont respect the format config in omnisharp.json file, but these two cases will