This is an archive of the discontinued LLVM Phabricator instance.

clang-format: [JS] merge requoting replacements.
ClosedPublic

Authored by mprobst on Sep 1 2016, 2:07 PM.

Details

Summary

When formatting source code that needs both requoting and reindentation,
merge the replacements to avoid erroring out for conflicting replacements.

Diff Detail

Repository
rL LLVM

Event Timeline

mprobst updated this revision to Diff 70066.Sep 1 2016, 2:07 PM
mprobst retitled this revision from to clang-format: [JS] merge requoting replacements..
mprobst updated this object.
mprobst added a reviewer: djasper.
mprobst added a subscriber: cfe-commits.
djasper accepted this revision.Sep 2 2016, 1:22 AM
djasper edited edge metadata.

Basically looks good.

lib/Format/Format.cpp
806 ↗(On Diff #70066)

Call this "RequoteChanges".

831 ↗(On Diff #70066)

Just

return RequoteChanges.merge(Whitespaces.generateReplacements());
This revision is now accepted and ready to land.Sep 2 2016, 1:22 AM
mprobst marked an inline comment as done.Sep 2 2016, 7:33 AM
mprobst added inline comments.
lib/Format/Format.cpp
806 ↗(On Diff #70066)

Done, went with RequoteReplaces (which is what we use in other places for the tooling::Replacements variable).

831 ↗(On Diff #70066)

Done.

Somewhat related, this API was very surprising – it passes down a Replacements object, but then the caller takes every item of the returned result and adds it back into the object, causing conflicts. So the only way to correctly use the API is to ignore the parameter, or return an empty dummy object. I've changed the API to not pass down the parameter to make this a bit less misleading.

This revision was automatically updated to reflect the committed changes.
mprobst marked an inline comment as done.