This is an archive of the discontinued LLVM Phabricator instance.

[clang-format] Fix comment aligning when there are changes within the comment
ClosedPublic

Authored by bkramer on Jan 11 2016, 5:05 AM.

Details

Summary

As soon as a comment had whitespace changes inside of the token, we
couldn't identify the whole comment as a trailing comment anymore and
alignment stopped working. Add a new boolean to Change for this special
case and fix trailing comment identification to use it.

Before this fix

int xy; a
int z;
b

became

int xy; a
int z;
b

with this patch we immediately get to:

int xy; a
int z;
b

Diff Detail

Repository
rL LLVM

Event Timeline

bkramer updated this revision to Diff 44466.Jan 11 2016, 5:05 AM
bkramer retitled this revision from to [clang-format] Fix comment aligning when there are changes within the comment.
bkramer updated this object.
bkramer added a reviewer: djasper.
bkramer added a subscriber: cfe-commits.
djasper added inline comments.Jan 11 2016, 5:10 AM
lib/Format/WhitespaceManager.h
145 ↗(On Diff #44466)

I find the term "continuation" a bit confusing here. How about something like "IsInsideToken"?

klimek added inline comments.Jan 11 2016, 5:13 AM
lib/Format/WhitespaceManager.h
145 ↗(On Diff #44466)

"Token" sounds like it could be true for things outside comments. Perhaps "InComment"?

bkramer updated this revision to Diff 44472.Jan 11 2016, 5:16 AM

Why not both?

djasper added inline comments.Jan 11 2016, 5:17 AM
lib/Format/WhitespaceManager.h
145 ↗(On Diff #44466)

So why not store the more generic information here? We already have the extra information whether this is a line comment or not stored in the token kind.

bkramer updated this revision to Diff 44508.Jan 11 2016, 7:39 AM
  • Renamed flag to IsInsideToken and enabled it for all in-token replacements.
  • TokenLength now gets updated to contain all changes on the same line if they're in the same token.
djasper accepted this revision.Jan 11 2016, 7:54 AM
djasper edited edge metadata.

I think this looks good, but I'd also like Manuel to take a look.

This revision is now accepted and ready to land.Jan 11 2016, 7:54 AM
bkramer updated this revision to Diff 44513.Jan 11 2016, 8:19 AM
bkramer edited edge metadata.
  • Moved newline check into replaceWhitespaceInToken
  • Removed duplicated TokenLength computation
klimek accepted this revision.Jan 11 2016, 8:24 AM
klimek added a reviewer: klimek.

lg

lib/Format/WhitespaceManager.h
113 ↗(On Diff #44513)

Forgot one replacement of the original name.

143 ↗(On Diff #44513)

... or starting a new line.

This revision was automatically updated to reflect the committed changes.