[PATCH] D51038: [clang] Make sure codecompletion is called for calls even when inside a token.
Kadir Cetinkaya via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Aug 22 08:16:10 PDT 2018
kadircet updated this revision to Diff 161966.
kadircet marked 2 inline comments as done.
kadircet added a comment.
- Resolve discussions.
- Add tests.
- Fix a bug noticed by lit tests.
Repository:
rC Clang
https://reviews.llvm.org/D51038
Files:
include/clang/Parse/Parser.h
lib/Parse/ParseExpr.cpp
test/CodeCompletion/function-overloads-inside-param.cpp
test/CodeCompletion/function-overloads.cpp
Index: test/CodeCompletion/function-overloads.cpp
===================================================================
--- /dev/null
+++ test/CodeCompletion/function-overloads.cpp
@@ -0,0 +1,8 @@
+void f(int i, int j = 2, int k = 5);
+void f(float x, float y...);
+
+void test() {
+ ::f(
+ // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:5:7 %s -o - | FileCheck -check-prefix=CHECK-CC1 %s
+ // CHECK-CC1: f(<#int i#>{#, <#int j = 2#>{#, <#int k = 5#>#}#})
+ // CHECK-CC1: f(<#float x#>, <#float y, ...#>)
Index: test/CodeCompletion/function-overloads-inside-param.cpp
===================================================================
--- /dev/null
+++ test/CodeCompletion/function-overloads-inside-param.cpp
@@ -0,0 +1,8 @@
+void f(int i, int j = 2, int k = 5);
+void f(float x, float y...);
+
+void test() {
+ ::f(1
+ // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:5:8 %s -o - | FileCheck -check-prefix=CHECK-CC1 %s
+ // CHECK-CC1: f(<#int i#>{#, <#int j = 2#>{#, <#int k = 5#>#}#})
+ // CHECK-CC1: f(<#float x#>, <#float y, ...#>)
Index: lib/Parse/ParseExpr.cpp
===================================================================
--- lib/Parse/ParseExpr.cpp
+++ lib/Parse/ParseExpr.cpp
@@ -1657,10 +1657,21 @@
if (OpKind == tok::l_paren || !LHS.isInvalid()) {
if (Tok.isNot(tok::r_paren)) {
- if (ParseExpressionList(ArgExprs, CommaLocs, [&] {
- Actions.CodeCompleteCall(getCurScope(), LHS.get(), ArgExprs);
- })) {
+ auto Completer = [&] {
+ Actions.CodeCompleteCall(getCurScope(), LHS.get(), ArgExprs);
+ CalledOverloadCompletion = true;
+ };
+ if (ParseExpressionList(ArgExprs, CommaLocs, Completer)) {
(void)Actions.CorrectDelayedTyposInExpr(LHS);
+ // If we got an error when parsing expression list, we don't call
+ // the CodeCompleteCall handler inside the parser. So call it here
+ // to make sure we get overload suggestions even when we are in the
+ // middle of a parameter. There is a different handling mechanism in
+ // ObjC for that type of completion, so don't call completion and
+ // let the parser do it instead.
+ if (!getLangOpts().ObjC1 && PP.isCodeCompletionReached() &&
+ !CalledOverloadCompletion)
+ Completer();
LHS = ExprError();
} else if (LHS.isInvalid()) {
for (auto &E : ArgExprs)
Index: include/clang/Parse/Parser.h
===================================================================
--- include/clang/Parse/Parser.h
+++ include/clang/Parse/Parser.h
@@ -214,6 +214,10 @@
/// should not be set directly.
bool InMessageExpression;
+ /// Gets set to true after calling CodeCompleteCall, it is for a hack to make
+ /// signature help working even when it is triggered inside a token.
+ bool CalledOverloadCompletion = false;
+
/// The "depth" of the template parameters currently being parsed.
unsigned TemplateParameterDepth;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D51038.161966.patch
Type: text/x-patch
Size: 3061 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180822/8b9a4073/attachment-0001.bin>
More information about the cfe-commits
mailing list