This is an archive of the discontinued LLVM Phabricator instance.

[clang-format-vs] Fix sort include main include: Use current path for the '-assume-filename'
ClosedPublic

Authored by jeanphilippeD on Jan 24 2016, 12:02 PM.

Details

Reviewers
klimek
hans
Summary

clang-format sort include use the source file name to determine the "main include" that will be the 1st include (category 0).
Because the clang-format visual studio extension does not pass the file name and use the standard input, sort include cannot find a "main include":

Testing fix on llvm\tools\clang\lib\Format\Format.cpp:
Original file:
#include "clang/Format/Format.h"
...
#include "clang/Basic/SourceManager.h"
#include "clang/Lex/Lexer.h"

Without fix, selecting the includes and running visual studio clang-format:
...
#include "clang/Basic/SourceManager.h"
#include "clang/Format/Format.h"
#include "clang/Lex/Lexer.h"

With fix, selecting the includes and running visual studio clang-format:
#include "clang/Format/Format.h"
...
#include "clang/Basic/SourceManager.h"
#include "clang/Lex/Lexer.h"

Test 2 with main header not at the start:
Original file:
...
#include "clang/Format/Format.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Lex/Lexer.h"

Without fix, selecting the includes and running visual studio clang-format:
...
#include "clang/Basic/SourceManager.h"
#include "clang/Format/Format.h"
#include "clang/Lex/Lexer.h"

With fix, selecting the includes and running visual studio clang-format:
#include "clang/Format/Format.h"
...
#include "clang/Basic/SourceManager.h"
#include "clang/Lex/Lexer.h"

Caveat: My setup is not ideal for test (Visual studio 2015 only), and I am not familiar with visual studio extension development, but I think the changes are straight forward enough.
I've tested this fix building it and running it on Visual Studio 2015, but I do not think there would be any compatibility issue since I am using API that are already used in the GetDocumentParent function.

Diff Detail

Event Timeline

jeanphilippeD retitled this revision from to [clang-format-vs] Fix sort include main include: Use current path for the '-assume-filename'.
jeanphilippeD updated this object.
jeanphilippeD added a reviewer: djasper.
jeanphilippeD added a subscriber: cfe-commits.

Ping,

Hi Daniel,

Sorry, should I have put someone else as reviewer, I see the previous committers for this file where Manuel Klimek, Hans Wennborg and Marek Kurdej.
Should have i added any or all of them.

I thought it made sense to put you originally since you updated the code for sort include in clang-format.

Kind Regards,
Jean-Philippe.

djasper edited reviewers, added: klimek, hans; removed: djasper.Feb 8 2016, 8:50 AM
klimek accepted this revision.Feb 9 2016, 7:02 AM
klimek edited edge metadata.

lg

This revision is now accepted and ready to land.Feb 9 2016, 7:02 AM

Hi Manuel,

Thank you very much for the review.
I do not have commit access, would you be able to commit this patch for me.

Kind Regards,
Jean-Philippe

djasper closed this revision.Feb 10 2016, 4:47 AM
djasper added a subscriber: djasper.

Submitted as r260378.