This is an archive of the discontinued LLVM Phabricator instance.

[clang-format] Don't reflow across comment pragmas.
ClosedPublic

Authored by krasimir on Feb 2 2017, 6:29 AM.

Details

Summary

The comment reflower wasn't taking comment pragmas as reflow stoppers. This patch fixes that.

source:

// long long long long
// IWYU pragma:

format with column limit = 20 before:

// long long long
// long IWYU pragma:

format with column limit = 20 after:

// long long long
// long 
// IWYU pragma:

Diff Detail

Repository
rL LLVM

Event Timeline

krasimir created this revision.Feb 2 2017, 6:29 AM
krasimir edited the summary of this revision. (Show Details)Feb 2 2017, 6:31 AM
krasimir added a reviewer: djasper.
krasimir added a subscriber: cfe-commits.
djasper edited edge metadata.Feb 2 2017, 6:46 AM

I am bit unsure about the design here. Could we instead match against the CommentPragmas and then not even create a BreakableToken (or reflow) if that matches?

I guess that would make us unable to reflow if only part of the comment is a pragma, but that seems ok (for now at least).

That sounds reasonable. However it won't work with comment pragmas in newlines in block comments.
The root issue that I was looking at was a taze directive inside a block comment in a random typescript file, like:

/* random stuff
  * long long long long
  * taze directive
  */

Ideally, we may try doing both: break a line comment section token steam and keep this too. What do you think?

djasper accepted this revision.Feb 2 2017, 6:59 AM

Makes sense.

This revision is now accepted and ready to land.Feb 2 2017, 6:59 AM
krasimir updated this revision to Diff 86813.Feb 2 2017, 7:36 AM
krasimir edited the summary of this revision. (Show Details)
  • Add a break in line comment sections by pragmas
krasimir updated this revision to Diff 86814.Feb 2 2017, 7:40 AM
  • Merge branch 'master' into arcpatch-D29450_1
This revision was automatically updated to reflect the committed changes.