This is an archive of the discontinued LLVM Phabricator instance.

[clang] Implement Override Suggestions in Sema.
ClosedPublic

Authored by kadircet on Sep 18 2018, 3:24 AM.

Details

Summary

In clangd we had a new type of completion suggestions for cpp
class/struct/unions that will show override signatures for virtual methods in
base classes. This patch implements it in sema because it is hard to deduce more
info about completion token outside of Sema and handle itchy cases.

See the patch D50898 for more info on the functionality.

In addition to above patch this one also converts the suggestion into a
CK_Pattern with whole insertion text as the name of the suggestion and factors
out CodeCompletionString generation for declerations so that it can be re-used
by others.

Diff Detail

Repository
rC Clang

Event Timeline

kadircet created this revision.Sep 18 2018, 3:24 AM

Could you move the corresponding tests from clangd to sema?

lib/Sema/SemaCodeComplete.cpp
3137

Could you put this definition before createCodeCompletionStringForDecl? I think it should make it easier to see unchanged lines.

kadircet updated this revision to Diff 167071.Sep 26 2018, 1:11 AM
  • Change order of fucntions for better diff.
  • Add tests.
kadircet marked an inline comment as done.Sep 26 2018, 1:12 AM
ioeric added inline comments.Oct 1 2018, 2:23 AM
lib/Sema/SemaCodeComplete.cpp
1603

Sema is available via Results.getSema()

1639

Could you add comments explaining what the following code does? The original code in clangd only has Results.emplace_back(Method, 0);, and it's non-trivial what the new code here is for.

1644

nit: /*Parameter-name=*/false

2940

nit: I think the contract would be clearer if this returns CodeCompletionString *. The empty returns below are a bit hard to follow.

test/CodeCompletion/overrides.cpp
21

nit: add {{$}} to the end of patterns.

21

nit: I think it's more common practice to put CHECKs for one completion in one group and after the completion command. I think it would be easier to read.

Please also add comment on what each case is testing.

kadircet updated this revision to Diff 167700.Oct 1 2018, 4:44 AM
kadircet marked 6 inline comments as done.
  • Address comments.
lib/Sema/SemaCodeComplete.cpp
1639

Yeah you are right added some comments, previously this was handled on CodeCompletionBuilder in clangd which converted the completion item into a override declaration to be inserted.

ioeric accepted this revision.Oct 1 2018, 4:55 AM

lg

lib/Sema/SemaCodeComplete.cpp
1639

Thanks! Could you elaborate on why you need to explicitly handle CCR and CCS, i.e. why was Results.emplace_back(Method, 0); not enough? I guess it's to avoid inserting return type when it's already typed, but it's not obvious from the code.

test/CodeCompletion/overrides.cpp
18

nit: add // completion ^void

23

add // completion at vo^id

28

add // completion at void ^

This revision is now accepted and ready to land.Oct 1 2018, 4:55 AM
kadircet updated this revision to Diff 167708.Oct 1 2018, 5:22 AM
kadircet marked 4 inline comments as done.
  • Fix a bug and address comments.
kadircet added inline comments.Oct 1 2018, 5:22 AM
lib/Sema/SemaCodeComplete.cpp
1639

Actually it is to generate a new CodeCompletionString with a single TypedText chunk that will include all of the declaration. Since you need to type whole declaration, which is also the part that has been used to filter completion candidates based on completion token.

It also helped me notice a bug relating optional params, I wasn't putting them into the typedtext chunk whereas I should've, fixed that one also.

kadircet updated this revision to Diff 167717.Oct 1 2018, 6:08 AM
  • Add a fixme on limitation.