Roslyn: Add editor config option to specify where usings should go by default

Created on 31 May 2018  路  7Comments  路  Source: dotnet/roslyn

Some people prefer usings inside namespaces. VS respects the location once it has been set, but there is no way to specify the initial behavior.

I foresee 2 options:

  • Outside namespace (default)
  • Inside namespace

Pinging @AArnott and @davkean FYI

I am happy to give it a spin and implement this, but might need some pointers once I start this.

Area-IDE

Most helpful comment

VS already formats new files from templates according to the current formatting settings, and there is work going on somewhere (@JieCarolHu?) to have that incorporate other code style items. So, someday when our code cleanup story is a little more developed, I would expect this to work for templates.

All 7 comments

@vweijsters has built a rather impressive analyzer and code fix for this setting that we may be able to leverage. It handles pretty much everything, including preprocessor directives, comments, optional separation of groups, and sorting with or without System directives first.

Comment from @AArnott on twitter:

"I suspect both of these can be specified via .editorconfig. Getting roslyn to honor it sounds interesting. I wish I could hope item templates would somehow honor them"

Maybe it's possible to apply code formatting (CTRL K, CTRL + D) after creating a template. Then only 2 things are needed to get a zillion birds with 2 stones:

  1. somehow get the logic created by @vweijsters into Roslyn
  2. post-run the code format logic after creating a template

VS already formats new files from templates according to the current formatting settings, and there is work going on somewhere (@JieCarolHu?) to have that incorporate other code style items. So, someday when our code cleanup story is a little more developed, I would expect this to work for templates.

Considering that corresponding option is added in 16.1.P3, probably this one should be closed.

@sharwell @jinujoseph Can we close this if this has been fixed?

Tagging @JoeRobich

This should be fixed via https://github.com/dotnet/roslyn/pull/35009
and should be available in 16.1.Preview3 onwards.

Was this page helpful?
0 / 5 - 0 ratings