1

I have tried exporting my C++ formatting settings into a .editorconfig but with the 2 methods I have attempted, the config is almost completely blank except for a brief comment header and the language file format selectors.

Using the method described here:

https://stackoverflow.com/a/51437947/2033725

Generates an editorconfig that simply has the following in it:

# Rules in this file were initially inferred by Visual Studio IntelliCode from the D:\ProjectName codebase based on best match to current usage at 12/4/2020
# You can modify the rules from these initially generated values to suit your own policies
# You can learn more about editorconfig here: https://learn.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference
[*.cs]

My project is c++ generated through cmake.

I have also tried navigating to the tools > options > Text Editor > C/C++ > CodeStyle and using the Generate .editorconfig file from settings. This gives me the following:

# Visual Studio generated .editorconfig file with C++ settings.

[*.{c++,cc,cpp,cppm,cxx,h,h++,hh,hpp,hxx,inl,ipp,ixx,tlh,tli}]
vc_generate_documentation_comments = doxygen_slash_star

If I use project -> add new item and select .editorconfig (default) I get this:

# All files
[*]
indent_style = space

# Xml files
[*.xml]
indent_size = 4

I have a number of changes to my c++ settings that vs definitely understands in .editorconfig land and even has keys for it:

https://learn.microsoft.com/en-us/visualstudio/ide/cpp-editorconfig-properties?view=vs-2019

cpp_indent_namespace_contents cpp_indent_case_labels cpp_indent_case_contents etc.

I was under the impression that the settings that visual studio is using for my formatting would be exported when no existing .editorconfig is present. Is that not correct?

This is Visual Studio Version 16.7.7 using Visual Studio Intellicode 2.2.123.30197

Klypto
  • 434
  • 1
  • 3
  • 14

2 Answers2

3

You could select the folder path to save .editorconfig in Tools->Text Editor->C/C++->Code Style->General->Generate .editorconfig file from settings. enter image description here

Then you need to compile this project. Then editorconfig will appear in the save path you just set.

enter image description here

Barrnet Chou
  • 1,738
  • 1
  • 4
  • 7
  • Thank you very much. compiling the project wasn't something I mentally associated with generating the content and the documentation doesn't list this as a requirement as far as I can find. – Klypto Dec 14 '20 at 23:34
1

FWIW: I had to update my Visual Studio before it worked. I apparently hadn't done it in a while, and on https://developercommunity.visualstudio.com/t/c-editorconfig-formatting-conventions-not-working/1186683 they were making reference to version 16.8.0 for this functionality.

Looks like many updates have been happening recently.

https://learn.microsoft.com/en-us/visualstudio/releases/2019/history

So for anyone else who sees this, check your version, check for updates. It got me. ;)

VonRansak
  • 21
  • 4
  • Can confirm that modern versions visual studio now generate the file with the modified configuration options without requiring a recompile of the solution. – Klypto Jun 03 '22 at 19:13