This is an archive of the discontinued LLVM Phabricator instance.

[clang-format] do not add existing includes.
ClosedPublic

Authored by ioeric on Jun 14 2016, 5:46 AM.

Diff Detail

Repository
rL LLVM

Event Timeline

ioeric updated this revision to Diff 60669.Jun 14 2016, 5:46 AM
ioeric retitled this revision from to [clang-format] do not add existing includes..
ioeric updated this object.
ioeric added a reviewer: djasper.
ioeric added a subscriber: cfe-commits.
djasper edited edge metadata.Jun 14 2016, 5:54 AM

I am happy to get this in for now, but I actually think the right solution might be to let clang-format de-duplicate #includes in general. What do you think?

It should be quite straight-forward to de-duplicate #includes in the same block in sortIncludes. I'm happy to add this into sortIncludes, but I'm not sure if this is a behavior users would expect from clang-format since it deletes code?

And maybe duplicated headers are not that common in the first place? I would rather rely on users (like #include_fixer) to make sure there is no duplicated #include.

Well, it is easy to not see duplicated #includes when they aren't properly sorted. When clang-format then goes in and sorts them, they end up next to each other. And I think no user really wants that.

Agreed. So, do we still want to skip existing #includes here or simply rely on sortIncludes to de-duplicate?

Lets get this in for now. We can always remove it if we think it is no longer useful.

unittests/Format/CleanupTest.cpp
692 ↗(On Diff #60669)

Please also add a test with quoted #includes as well as combined forms (inserting <vector> when there already is "vector" and vice versa).

ioeric updated this revision to Diff 60675.Jun 14 2016, 6:42 AM
ioeric marked an inline comment as done.
ioeric edited edge metadata.
  • Addressed reviewer's comments: test case added.
djasper added inline comments.Jun 14 2016, 6:47 AM
unittests/Format/CleanupTest.cpp
693 ↗(On Diff #60675)

Please add a line break after each "\n", i.e.:

... = "#include \"a.h\"\n"
      "#include <vector>";
701 ↗(On Diff #60675)

Is this really what we want?

ioeric updated this revision to Diff 60680.Jun 14 2016, 7:12 AM
ioeric marked 2 inline comments as done.
  • addressed reviewer's comments.
unittests/Format/CleanupTest.cpp
701 ↗(On Diff #60675)

I'm not sure... this might not be the best behavior. FIXME added.

djasper accepted this revision.Jun 14 2016, 7:14 AM
djasper edited edge metadata.

Looks good :-)

This revision is now accepted and ready to land.Jun 14 2016, 7:14 AM
This revision was automatically updated to reflect the committed changes.