[clang] 24364cd - [clang][CodeComplete] Make completion work after initializer lists
Kadir Cetinkaya via cfe-commits
cfe-commits at lists.llvm.org
Thu Jan 23 06:32:54 PST 2020
Author: Kadir Cetinkaya
Date: 2020-01-23T15:32:46+01:00
New Revision: 24364cd12bbfa2e58fa74bfb49d4ea85c64c0951
URL: https://github.com/llvm/llvm-project/commit/24364cd12bbfa2e58fa74bfb49d4ea85c64c0951
DIFF: https://github.com/llvm/llvm-project/commit/24364cd12bbfa2e58fa74bfb49d4ea85c64c0951.diff
LOG: [clang][CodeComplete] Make completion work after initializer lists
Summary:
CodeCompletion was not being triggered after successfully parsed
initializer lists, e.g.
```cpp
void foo(int, bool);
void bar() {
foo({1}^, false);
}
```
CodeCompletion would suggest the function foo as an overload candidate up until
the point marked with `^` but after that point we do not trigger signature help
since parsing succeeds.
This patch handles that case by failing in parsing expression lists whenever we
see a codecompletion token, in addition to getting an invalid subexpression.
Reviewers: sammccall
Subscribers: cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D73177
Added:
Modified:
clang/lib/Parse/ParseExpr.cpp
clang/test/CodeCompletion/call.cpp
Removed:
################################################################################
diff --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp
index df8388926db1..ba7525ecf527 100644
--- a/clang/lib/Parse/ParseExpr.cpp
+++ b/clang/lib/Parse/ParseExpr.cpp
@@ -3128,6 +3128,16 @@ bool Parser::ParseExpressionList(SmallVectorImpl<Expr *> &Exprs,
if (Tok.is(tok::ellipsis))
Expr = Actions.ActOnPackExpansion(Expr.get(), ConsumeToken());
+ else if (Tok.is(tok::code_completion)) {
+ // There's nothing to suggest in here as we parsed a full expression.
+ // Instead fail and propogate the error since caller might have something
+ // the suggest, e.g. signature help in function call. Note that this is
+ // performed before pushing the \p Expr, so that signature help can report
+ // current argument correctly.
+ SawError = true;
+ cutOffParsing();
+ break;
+ }
if (Expr.isInvalid()) {
SkipUntil(tok::comma, tok::r_paren, StopBeforeMatch);
SawError = true;
diff --git a/clang/test/CodeCompletion/call.cpp b/clang/test/CodeCompletion/call.cpp
index c57c339cd130..9cba6ae100b3 100644
--- a/clang/test/CodeCompletion/call.cpp
+++ b/clang/test/CodeCompletion/call.cpp
@@ -25,4 +25,10 @@ void test() {
// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:19:13 %s -o - | FileCheck -check-prefix=CHECK-CC2 %s
// CHECK-CC2-NOT: f(Y y, int ZZ)
// CHECK-CC2: f(int i, int j, <#int k#>)
+ f({}, 0, 0);
+ // RUN: %clang_cc1 -fsyntax-only -code-completion-patterns -code-completion-at=%s:28:7 %s -o - | FileCheck -check-prefix=CHECK-CC3 %s
+ // CHECK-CC3: OVERLOAD: [#void#]f()
+ // CHECK-CC3-NEXT: OVERLOAD: [#void#]f(<#X#>)
+ // CHECK-CC3-NEXT: OVERLOAD: [#void#]f(<#int i#>, int j, int k)
+ // CHECK-CC3-NEXT: OVERLOAD: [#void#]f(<#float x#>, float y)
}
More information about the cfe-commits
mailing list