This is an archive of the discontinued LLVM Phabricator instance.

[CodeCompletion] Avoid spurious signature help for init-list args
ClosedPublic

Authored by sammccall on Mar 12 2021, 4:03 AM.

Details

Summary

Somewhat surprisingly, signature help is emitted as a side-effect of
computing the expected type of a function argument.
The reason is that both actions require enumerating the possible
function signatures and running partial overload resolution, and doing
this twice would be wasteful and complicated.

Change #1: document this, it's subtle :-)

However, sometimes we need to compute the expected type without having
reached the code completion cursor yet - in particular to allow
completion of designators.
eb4ab3358cd4dc834a761191b5531b38114f7b13 did this but introduced a
regression - it emits signature help in the wrong location as a side-effect.

Change #2: only emit signature help if the code completion cursor was reached.

Currently there is PP.isCodeCompletionReached(), but we can't use it
because it's set *after* running code completion.
It'd be nice to set this implicitly when the completion token is lexed,
but ConsumeCodeCompletionToken() makes this complicated.

Change #3: call cutOffParsing() *first* when seeing a completion token.

After this, the fact that the Sema::Produce*SignatureHelp() functions
are even more confusing, as they only sometimes do that.
I don't want to rename them in this patch as it's another large
mechanical change, but we should soon.

Change #4: prepare to rename ProduceSignatureHelp() to GuessArgumentType() etc.

Diff Detail

Event Timeline

sammccall created this revision.Mar 12 2021, 4:03 AM
sammccall requested review of this revision.Mar 12 2021, 4:03 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 12 2021, 4:03 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
sammccall updated this revision to Diff 330218.Mar 12 2021, 5:49 AM

oops, enable clangd test

kadircet accepted this revision.Mar 12 2021, 8:59 AM

thanks, lgtm!

clang/lib/Parse/Parser.cpp
2117

i know you are keeping it as is, but what about just calling cutoffparsing before entering the loop once, rather than in 3 places.

This revision is now accepted and ready to land.Mar 12 2021, 8:59 AM
This revision was landed with ongoing or failed builds.Mar 16 2021, 4:47 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptMar 16 2021, 4:47 AM