Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 681
myWallJSON Avatar asked Sep 07 '13 00:09

myWallJSON


People also ask

How do I run a clang format in Visual Studio?

clang-format is a tool to format C/C++/Obj-C source code. This plugin provides a convenient way of using it in Visual Studio. It adds two new commands under the Tools menu: Clang Format Selection (CTRL+R, CTRL+F) and Clang Format Document (CTRl+R, CTRL+D).

How do I run a clang file format?

To automatically format a file according to Electron C++ code style, run clang-format -i path/to/electron/file.cc . It should work on macOS/Linux/Windows. The workflow to format your changed code: Make codes changes in Electron repository.

Where does clang format look for clang format?

Standalone Tool clang-format is located in clang/tools/clang-format and can be used to format C/C++/Java/JavaScript/JSON/Objective-C/Protobuf/C# code.


3 Answers

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.

like image 72
ComicSansMS Avatar answered Oct 20 '22 02:10

ComicSansMS


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

like image 24
MyDeveloperDay Avatar answered Oct 20 '22 02:10

MyDeveloperDay


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.

like image 3
Eph Avatar answered Oct 20 '22 04:10

Eph