[clang] [clang-tools-extra] [clang][CodeComplete] Omit ExplicitObject when completing code (PR #92743)
via cfe-commits
cfe-commits at lists.llvm.org
Mon May 20 05:22:20 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
@llvm/pr-subscribers-clangd
Author: zyctree (zyctree)
<details>
<summary>Changes</summary>
Fixes https://github.com/clangd/clangd/issues/2042
---
Full diff: https://github.com/llvm/llvm-project/pull/92743.diff
2 Files Affected:
- (modified) clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp (+5)
- (modified) clang/lib/Sema/SemaCodeComplete.cpp (+3)
``````````diff
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.
``````````
</details>
https://github.com/llvm/llvm-project/pull/92743
More information about the cfe-commits
mailing list