Harl3
Harl3

Reputation: 43

Visual Studio 2022 editorconfig not applied on cleanup

I'm having a bit of trouble understanding how .editorconfig should work.

Am i understanding something wrong? shouldn't vs code cleanup refactor files based on .editorconfig rules?

moreover, if i try to open the .editorconfig file i get an empty UI in VS.

What am i missing?

Upvotes: 4

Views: 5232

Answers (3)

Sophie cai
Sophie cai

Reputation: 309

Currently when on Visual Studio v17.9.5, it needs to add Format Document into the Included Fixers under Configure Code Cleanup from the Tools -> Options... -> Code Cleanup -> Configure Code Cleanup And it will immediately works when Ctrl + S enter image description here

Upvotes: 0

Zyrca
Zyrca

Reputation: 43

I had a .editorconfig in a top-level directory from VS2019 that stopped working and wouldn't load correctly when I brought the solution to VS2022. In my case, it turned out that I needed to add

root = true

to the top of the .editorconfig file.

Upvotes: 1

Jimmy
Jimmy

Reputation: 28396

Visual Studio's Code Cleanup feature runs a set of predefined tasks, as configured in the Code Cleanup profile. Most of these tasks correspond to specific IDE settings, some of which may be configured by .editorconfig.

Among those is Format Document, which uses takes a lot of the .editorconfig settings into account when applying formatting all in one big operation. However, Format Document does not make refactoring changes to the existing code. It wouldn't change the overall structure of the document.

There is a Code Fix (or lightbulb, or suggested action, or... it goes by lots of names) that will appear on the namespace block. That will provide a gesture to make the edit in that file, or across the entire project or solution (each file will be modified as applicable, as .editorconfig applies to directory hierarchies, and may not be present for all projects in the solution).

moreover, if I try to open the .editorconfig file I get an empty UI in VS..

This sounds like a bug and should be reported using the VS Feedback tool.

Upvotes: 1

Related Questions