[clang] [clang][CodeComplete] Omit ExplicitObject when completing code (PR #92743)

via cfe-commits cfe-commits at lists.llvm.org
Mon May 27 05:44:37 PDT 2024


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

>From 7fe1ea0dd38d70515bd2075d572539823931b692 Mon Sep 17 00:00:00 2001
From: zyctree <appletree2479 at outlook.com>
Date: Mon, 27 May 2024 20:44:13 +0800
Subject: [PATCH] [clang][CodeComplete] Omit ExplicitObject when completing
 code

Fixes https://github.com/clangd/clangd/issues/2042
---
 clang/lib/Sema/SemaCodeComplete.cpp         |  3 +++
 clang/test/CodeCompletion/member-access.cpp | 17 +++++++++++++++++
 2 files changed, 20 insertions(+)

diff --git a/clang/lib/Sema/SemaCodeComplete.cpp b/clang/lib/Sema/SemaCodeComplete.cpp
index cd1c5f9391ccd..c2c01dd20b826 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.
diff --git a/clang/test/CodeCompletion/member-access.cpp b/clang/test/CodeCompletion/member-access.cpp
index 912f269db6c1a..6a73fc49aceae 100644
--- a/clang/test/CodeCompletion/member-access.cpp
+++ b/clang/test/CodeCompletion/member-access.cpp
@@ -384,3 +384,20 @@ void Foo() {
 // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:382:5 %s -o - | FileCheck -check-prefix=CHECK-DEREF-DEPENDENT %s
 // CHECK-DEREF-DEPENDENT: [#void#]Add()
 }
+
+namespace explicit_object {
+struct A {
+  void foo1(this const A& self, int);
+  template <class Self>
+  void foo2(this Self&& self, long);
+  void foo3(this auto&& self, float);
+};
+
+void test(A& a) {
+  a.foo
+// RUN: %clang_cc1 -std=c++23 -fsyntax-only -code-completion-at=%s:397:7 %s -o - | FileCheck -check-prefix=CHECK-EXPLICIT-OBJECT %s
+// CHECK-EXPLICIT-OBJECT: [#void#]foo1(<#int#>)
+// CHECK-EXPLICIT-OBJECT: [#void#]foo2(<#long#>)
+// CHECK-EXPLICIT-OBJECT: [#void#]foo3(<#float#>)
+}
+}



More information about the cfe-commits mailing list