1

I've installed the latest clang-format plugin for Visual Studio from http://llvm.org/builds/ and I'm trying to use it with a VS solution file that's generated from CMake. I've got the following directory structure:

./
├──project/
│  ├──.clang-format
│  └──source.cpp  #all sourcefiles are here
└──build/  # cmake build files

When I open the cmake-generated .sln file and press CTRL+R, CTRL+F, no formatting happens. When I set Tools->Options->LLVM/Clang->ClangFormat->Fallback Style to anything (e.g. 'LLVM') then it formats (to the default style), but not if I set fallback to 'none' - which means my .clang-format file doesn't get loaded.

I tried copying the .clang-format file all over the project directories, i.e. putting it in the project dir, sub-directories, next to the source files, in the build directory, in the build/x64 directory, etc. - but it just doesn't get picked up.

Where do I have to put the file so that it gets picked up by the plugin?

rocambille
  • 15,398
  • 12
  • 50
  • 68
Ela782
  • 5,041
  • 5
  • 53
  • 66
  • Obviously I've read http://stackoverflow.com/questions/18668517/how-to-feed-visual-studio-clang-format-plugin-with-clang-format-file?rq=1 but the default advice there didn't help, as outlined in my question. – Ela782 Dec 26 '16 at 11:33

1 Answers1

3

I solved this, and it had nothing to do with where you put the .clang-format file. It's fine to just put it in the root of the source directory, as I did it.

Why it didn't format at all was that a .clang-format requires either the line BasedOnStyle: LLVM (or any other default style) or to define all required parameters.

If you just have a .clang-format file with a few lines, like for example:

---
ColumnLimit: '120'
IndentWidth: '4'
Language: Cpp
Standard: Cpp11
UseTab: Never

...

then it will not do any formatting whatsoever. Probably it can't work without a full set of rules, and in this case, it doesn't know to which default settings whatsoever it should fall back to.

Ela782
  • 5,041
  • 5
  • 53
  • 66