This is an archive of the discontinued LLVM Phabricator instance.

[clang-format] Reflow block comments when they're over the column limit
Needs ReviewPublic

Authored by bkramer on Dec 2 2015, 4:30 AM.

Details

Reviewers
klimek
djasper
Summary

/* aaaaaaaa a

  • a*/

Now becomes

/* aaaaaaaa

  • a a*/

instead of

/* aaaaaaaa

  • a
  • a*/

This is implemented by glueing the next line on while fixing whitespace
and adding another break if that brings us over the column limit again.
We also have heuristics to avoid making existing comments worse:

  1. Only reflow when the existing comment is already over the column limit
  2. Don't reflow when there's an empty line (to avoid breaking paragraphs)
  3. Don't reflow when there's a non-alphanumeric char at the beginning of the next line. This is a weak attempt to avoid mangling ASCII art.

I intend to do the same thing for line comments, but that will require
changes to other parts of clang-format first.

Diff Detail

Event Timeline

bkramer updated this revision to Diff 41610.Dec 2 2015, 4:30 AM
bkramer retitled this revision from to [clang-format] Reflow block comments when they're over the column limit.
bkramer updated this object.
bkramer added reviewers: djasper, klimek.
bkramer added a subscriber: cfe-commits.
klimek added inline comments.Dec 2 2015, 5:09 AM
lib/Format/BreakableToken.cpp
443

For posterity, from in-person chat:
Currently, this does the same as before when we're in DryRun mode, and only wraps when we apply the changes. Instead, we'll need to make this work with the DryRun mode for optimization.