travisjeffery / ClangFormat-Xcode

Xcode plug-in to to use clang-format from in Xcode and consistently format your code with Clang
https://twitter.com/travisjeffery
MIT License
2.89k stars 288 forks source link

Fix includes sorting #124

Closed skomik closed 7 years ago

skomik commented 7 years ago

Issue: when SortIncludes option is enabled, the plugin incorrectly sorts includes in .cpp files. This is caused by the fact that clang-format is invoked on a temporary file which is named by appending .trvs extension to the original file name. File name change prevents clang-format to correctly determine the main header for a source file and put it on top of includes list.

Fix: preserve original file name and copy the file to a temporary directory ClangFormatXcodeTmpDir inside original directory.