This is an archive of the discontinued LLVM Phabricator instance.

clangd: Add a break for every case in the PopulateSwitch tweak
AbandonedPublic

Authored by ckandeler on Feb 2 2022, 5:55 AM.

Details

Reviewers
sammccall
Summary

Fall-through is not the common case.

Diff Detail

Event Timeline

ckandeler created this revision.Feb 2 2022, 5:55 AM
ckandeler requested review of this revision.Feb 2 2022, 5:55 AM
ckandeler updated this revision to Diff 405240.Feb 2 2022, 5:57 AM

Fixed unintentional whitespace change.

njames93 added inline comments.
clang-tools-extra/clangd/refactor/tweaks/PopulateSwitch.cpp
208–209
ckandeler updated this revision to Diff 405893.Feb 4 2022, 1:54 AM

Improved code as per review comment.

ckandeler marked an inline comment as done.Feb 4 2022, 1:56 AM

FWIW I prefer the existing behaviour (reasons below). @kadircet, thoughts?

  • The output with break is harder to visually scan. (In styles where break goes on its own line)
  • The output is annoying to edit when you *do* want to deal with blocks of cases at once. When editing cases individually anyway, I don't find typing break a burden.
  • The goal isn't to provide a correct body, but to avoid having to remember/type all the cases. Any extra output is a distraction.

I agree with Sam on this one and remember having some (possibly offline) discussions around not having those breaks explicitly (we should've documented the reasoning, sorry).

As pointed out, I believe the main benefit is not spelling out each enum value (it's usually hard to figure out which ones are missing, requires constant switching between enum declaration and switch body, and then do some copy/paste or write them).
After those are spelled the developer needs to make a decision about how they'll be handled anyway and if some enum value requires special handling adding the extra break by hand is not too much of a burden, but deleting those when the intent is to have fall through, is extra burden and it might be unclear which ones are new labels.

ckandeler abandoned this revision.Feb 4 2022, 5:56 AM

Fair enough.

The only way I'd suggest supporting this is via an option in config(like we do with the add using tweak), but I don't think even then it would get much use.