[PATCH] D53072: [clang-format] Create a new tool for IDEs based on clang-format

Sam McCall via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 25 05:45:17 PDT 2019

sammccall added a comment.

You may be interested in D60605 <https://reviews.llvm.org/D60605>, which is a related idea (adding incremental format-and-indent-on-type to clangd).

These are opposite extremes in some sense: this patch integrates deeply into clang-format and that patch entirely layers on top of it, by transforming the source code (in hacky ways, in some cases).

I think the cleanest approach is probably some combination: in particular a "preserve line break at point" primitive does seem useful, and even if source code transforms are used, putting a nice API on this in clang-format would be nice. (I'm not sure a separate command-line-tool is justified, though).

If you haven't run into these yet, here are some fun issues I ran into:

- clang-format bails out when brackets aren't sufficiently matched, incremental formatting needs to work in such cases
- incremental formatting sometimes wants to make edits both immediately before and after the cursor. `tooling::Replacements` can't represent this, they will be merged and destroy precise cursor position information.
- user expectations when breaking between `()` are fairly clear. `{}` is the same when it acts as a list, but not when it acts as a block!



More information about the cfe-commits mailing list