❔ 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:
void Foo(double x, double y)
{
}

Foo(1,
2);

var y = 42; var z = 1;
void Foo(double x, double y)
{
}

Foo(1,
2);

var y = 42; var z = 1;
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
Angius
Angius2y ago
If everything is set up properly, I guess the reason for the odd formatting would be just "vscode being vscode"
333fred
333fred2y ago
That was never a good or correct answer before, and it's not good now either
333fred
333fred2y ago
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.
kirillbobyrev
kirillbobyrevOP2y ago
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.
Accord
Accord2y ago
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.
Want results from more Discord servers?
Add your server