If an if statement uses braces for its then block, suggest braces for the else and else if completion blocks, Otherwise don't suggest them.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
I'm still unsure what is the best behaviour here.
Would suggesting both patterns, but sort them based on what the then branch uses be best
Example with:
if (...) { // Statements }
Suggestions:
- else { // Statements } - else if (...) { // Statements } - else // Statement - else if (...) // Statement
With:
if (...) // Statement }
Suggestions:
- else // Statement - else if (...) // Statement - else { // Statements } - else if (...) { // Statements }
Or is it best keeping with the behaviour of this patch where only 1 suggestion appears based on whether braces are used or not??
I like the behavior in this patch - I think multiple options is going to be distracting and crowd out other good results, and the heuristic seems pretty good.
This needs a test in e.g. llvm-project/clang/test/CodeCompletion/patterns.cpp.
clang/lib/Sema/SemaCodeComplete.cpp | ||
---|---|---|
5780 | name could be clearer here: AddElseBodyPattern? | |
5789 | Hmm, this is in clangd I guess, which ignores vertical space when rendering snippets. If we do keep it (also fine) you could switch the order of the vertical and horizontal space, which suggests indentation. Up to you though. | |
5791 | I'm not sure about this FIXME, I think it's pretty unlikely this will happen (this layer of clang is unlikely to retain enough info and know enough about style to do this, and if it's solved at another layer it's likely to be clang-format that doesn't require this hint) | |
5795 | do you want to insert the semicolon after "statement"? (i.e. the semicolon is not part of the placeholder) (I don't see much precedent one way or the other, there's only "statements" in blocks... the for-loop snippet obviously inserts semicolons though) |
name could be clearer here: AddElseBodyPattern?