How to feed Visual Studio Clang-Format plugin with clang-format file?

橙三吉。 提交于 2019-11-29 16:21:51

问题


So I downloaded, installed, and inserted into path the clang formatting plugin. I also tested it and it works for Google (Mozilla, etc.) formatting options out of the box, yet I cannot get it working with my .clang-format file. (I've put my file into the same folder as my source file, changed its encoding into UTF-8, also tried to put it into clang install folder, add file into project, write its contents inside '{key:value}' yet formatting does not happen). So how do you feed formatting file to chrome-format extension?

My file contents:

 { BasedOnStyle: "LLVM",    IndentWidth: 4 }

My file name:nm.clang-format


回答1:


Go to Tools->Options->LLVM/Clang->ClangFormat and put file in the Style option field.

Then place your style file named .clang-format (this is the full filename, not an extension) either in the source file's directory or one of its parent directories. Windows Explorer won't let you create filenames with leading . so you need to go to the console for this.




回答2:


If like me you got confused later on where the .clang-format was living, use procmon to track the file reads of clang-format.exe




回答3:


For the record, it seems that if both "Fallback Style" and "Style" are set to "file", no formatting will happen even if the style file is at its correct location. Setting "Fallback Style" to something different than "file" (e.g. "none") helps.




回答4:


In VS2019 works if the clang-format file is named as .clang-format.

It must be .clang-format, not .clang-format.txt or clang-format.txt.



来源:https://stackoverflow.com/questions/18668517/how-to-feed-visual-studio-clang-format-plugin-with-clang-format-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!