https://github.com/zyctree created 
https://github.com/llvm/llvm-project/pull/92743

Fixes https://github.com/clangd/clangd/issues/2042

>From 6b1a52b17559f2d7a93b1fc95207e5706039956f Mon Sep 17 00:00:00 2001
From: zyctree <appletree2...@outlook.com>
Date: Mon, 20 May 2024 20:12:56 +0800
Subject: [PATCH] [clang][CodeComplete] Omit ExplicitObject when completing
 code

Fixes https://github.com/clangd/clangd/issues/2042
---
 clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp | 5 +++++
 clang/lib/Sema/SemaCodeComplete.cpp                      | 3 +++
 2 files changed, 8 insertions(+)

diff --git a/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp 
b/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
index 96d1ee1f0add7..7292f14ecd3c2 100644
--- a/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
+++ b/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
@@ -534,6 +534,7 @@ TEST(CompletionTest, HeuristicsForMemberFunctionCompletion) 
{
         int method(int) const;
         template <typename T, typename U, typename V = int>
         T generic(U, V);
+        int explicitObject(this Foo&, int);
         template <typename T, int U>
         static T staticGeneric();
         Foo() {
@@ -580,6 +581,7 @@ TEST(CompletionTest, HeuristicsForMemberFunctionCompletion) 
{
       }
       )cpp");
   auto TU = TestTU::withCode(Code.code());
+  TU.ExtraArgs.push_back("-std=c++23");
 
   for (const auto &P : Code.points("canNotBeCall")) {
     auto Results = completions(TU, P, /*IndexSymbols*/ {}, Opts);
@@ -604,6 +606,9 @@ TEST(CompletionTest, HeuristicsForMemberFunctionCompletion) 
{
         Results.Completions,
         Contains(AllOf(named("generic"), signature("<typename T>(U, V)"),
                        snippetSuffix("<${1:typename T}>(${2:U}, ${3:V})"))));
+    EXPECT_THAT(Results.Completions,
+                Contains(AllOf(named("explicitObject"), signature("(int)"),
+                               snippetSuffix("(${1:int})"))));
   }
 
   // static method will always keep the snippet
diff --git a/clang/lib/Sema/SemaCodeComplete.cpp 
b/clang/lib/Sema/SemaCodeComplete.cpp
index ad3ca4cc94ca6..8cdb5d7c19c3b 100644
--- a/clang/lib/Sema/SemaCodeComplete.cpp
+++ b/clang/lib/Sema/SemaCodeComplete.cpp
@@ -3119,6 +3119,9 @@ static void AddFunctionParameterChunks(Preprocessor &PP,
   for (unsigned P = Start, N = Function->getNumParams(); P != N; ++P) {
     const ParmVarDecl *Param = Function->getParamDecl(P);
 
+    if (Param->isExplicitObjectParameter())
+      continue;
+
     if (Param->hasDefaultArg() && !InOptional) {
       // When we see an optional default argument, put that argument and
       // the remaining default arguments into a new, optional string.

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to