[cfe-dev] Alternative FixItHints

Benjamin Kramer via cfe-dev cfe-dev at lists.llvm.org
Wed May 25 08:24:12 PDT 2016


Hi all,

one of the longer-term goals for the include fixer tool is integration
into the editor. This could piggy-back on the existing support for
FixIts but there is one big missing feature. It is often not perfectly
clear what #include a user wants or if it's just a typo that needs
correcting, we cannot express that with the current FixIts. A Clang
diagnostic can have multiple FixIts but they are meant to be applied
together, for this case we'd need alternative groups of FixIts.

There's also a fair number of existing clang warnings that could
benefit from this, typo correction is an obvious one but there's also
a bunch of disambiguation warnings that can have fix-its in both
directions, for example '= in if statement' (turn into '==' or add
double parens) or '&& within ||' where parens can be added both ways.
The functionality-preserving FixIt is the canonical one for those
warnings but having an alternative would be useful, too.

Of course this won't work on the terminal. FixIts are already hardly
usable there, so this will be a feature for IDEs, code review tools
etc.

My current plan is:
  1. Have DiagnosticEngine and friends keep a vector of vector of
FixItHint instead of a flat FixIt vector
  2. Thread the change through clang, using alternative '0' in most
places to avoid breaking existing functionality.
  3. Add methods to add alternative FixItHints to a diagnostic
  4. Expose this via a new libclang API. Any diagnostic rendering code
in clang will stay the same.

There's interest from YouCompleteMe for providing an interface for
this that lets the user pick a fix out of multiple ones, and I guess
other IDEs can put it to great use too.

Any input on this approach or concerns?



More information about the cfe-dev mailing list