[all-commits] [llvm/llvm-project] 128ce7: [CodeCompletion] Avoid spurious signature help for...

Sam McCall via All-commits all-commits at lists.llvm.org
Tue Mar 16 04:47:05 PDT 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 128ce70eef9948b81e725fd0e2ed46a7c004a118
      https://github.com/llvm/llvm-project/commit/128ce70eef9948b81e725fd0e2ed46a7c004a118
  Author: Sam McCall <sam.mccall at gmail.com>
  Date:   2021-03-16 (Tue, 16 Mar 2021)

  Changed paths:
    M clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
    M clang/include/clang/Sema/Sema.h
    M clang/lib/Lex/PPDirectives.cpp
    M clang/lib/Lex/Preprocessor.cpp
    M clang/lib/Parse/ParseDecl.cpp
    M clang/lib/Parse/ParseDeclCXX.cpp
    M clang/lib/Parse/ParseExpr.cpp
    M clang/lib/Parse/ParseExprCXX.cpp
    M clang/lib/Parse/ParseInit.cpp
    M clang/lib/Parse/ParseObjc.cpp
    M clang/lib/Parse/ParseOpenMP.cpp
    M clang/lib/Parse/ParseStmt.cpp
    M clang/lib/Parse/Parser.cpp
    M clang/lib/Sema/SemaCodeComplete.cpp
    M clang/test/CodeCompletion/desig-init.cpp

  Log Message:
  -----------
  [CodeCompletion] Avoid spurious signature help for init-list args

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.

Differential Revision: https://reviews.llvm.org/D98488




More information about the All-commits mailing list