❔ Formatting C# code in VSCode doesn't look right
Hi everyone! I haven't written any C# code for quite a while and would like to get back to it. I set up .NET SDK and VSCode + C# extension pack and am trying to get it to work. Everything runs smoothly but I'm very confused about the formatting. Whenever I try to format code in VSCode, it only does "basic" things and doesn't touch very long lines or function arguments passed on different lines that don't really look right. Anything I could do to do more "strict" formatting?
E.g. this code doesn't get modified by the formatter at all:
I also made sure I have
Csharp > Format: Enable
set to true
in my VSCode settings and I do get messages from the Language Server (e.g. I can navigate the code, use Go To to jump to functions in Standard Library and in my code etc).5 Replies
If everything is set up properly, I guess the reason for the odd formatting would be just "vscode being vscode"
That was never a good or correct answer before, and it's not good now either
You can control how the formatting in VSCode works with an editorconfig: https://learn.microsoft.com/en-us/visualstudio/ide/create-portable-custom-editor-options
EditorConfig settings - Visual Studio (Windows)
Learn how to add an EditorConfig file to your project or codebase to enforce consistent coding styles for everyone that works in the codebase.
I see, thanks!
Yeah, I ended up installing CSharpier formatter plugin that has the formatting options that I like. I’m somewhat confused the default isn’t this way but I guess it’s the way it is.
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.