Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Code formatter does not respect csharp_space_after_keywords_in_control_flow_statements editorconfig setting #1564

Open
johan-gorter opened this issue Oct 28, 2024 · 5 comments
Labels
area-roslyn bug Something isn't working

Comments

@johan-gorter
Copy link

Describe the Issue

When (auto)formatting our code, the setting csharp_space_after_keywords_in_control_flow_statements = false is ignored and spaces are added after if and foreach statements. According to the documentation, the .editorconfig file is used for formatting.

Steps To Reproduce

Have a .editorconfig file with the following contents:

[*.cs]
csharp_space_after_keywords_in_control_flow_statements = false

And a simple Program.cs

if(true)
{
  Console.WriteLine("Hello, World!");
}

Execute the action format document, and observe the space appearing after if, although the .editorconfig specifies it shouldn't.

Expected Behavior

I expect the space not to be added by the code formatter.

Environment Information

OS: Windows
VSCode version: 1.94.2
C# Dev Kit version v1.11.14

@johan-gorter johan-gorter added the bug Something isn't working label Oct 28, 2024
@dibarbet
Copy link
Member

dibarbet commented Dec 5, 2024

Apologies for the delay here - @johan-gorter can you confirm this is still not working on the latest versions of the c# extension (2.59.14 prerelease)? It seems to be working as expected for me:
Image

If it isn't working - can you confirm if the .editorconfig is shown in the sln explorer correctly and next to or above the cs file?
Image

@dibarbet dibarbet added the needs-more-info Needing more information, waiting on OP label Dec 5, 2024
@johan-gorter
Copy link
Author

I updated to pre-release versions (C# 2.60.26, C# Dev Kit 1.15.13) And still the .editorconfig setting is still ignored. My .editorconfig looks like this:

root = true

[*.cs]
csharp_space_after_keywords_in_control_flow_statements = false

Could you give me yours, to see if another editorconfig setting is influencing this one?

@github-actions github-actions bot removed the needs-more-info Needing more information, waiting on OP label Dec 16, 2024
Copy link

@dibarbet, the 'needs-more-info' label has been removed upon receiving further response from the original bug filer.

@johan-gorter
Copy link
Author

@dibarbet sorry for the late reply by the way

@dibarbet
Copy link
Member

dibarbet commented Jan 2, 2025

@johan-gorter no worries - I have been OOF for a bit as well. I'm able to see the setting work with the same editorconfig:

root = true

[*.cs]
csharp_space_after_keywords_in_control_flow_statements = false

Image

I suspect there is some issue with either the project loading or the location of the editorconfig file. Are you able to share what you see in the solution explorer, and where the .editorconfig file is in relation to the file being formatted?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-roslyn bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants