Skip to content

Commit 7f8581f

Browse files
committed
[clang][CodeComplete] skip explicit obj param in SignatureHelp
1 parent 651c520 commit 7f8581f

File tree

3 files changed

+54
-6
lines changed

3 files changed

+54
-6
lines changed

clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3266,6 +3266,34 @@ TEST(SignatureHelpTest, VariadicType) {
32663266
}
32673267
}
32683268

3269+
TEST(SignatureHelpTest, SkipExplicitObjectParameter) {
3270+
Annotations Code(R"cpp(
3271+
struct A {
3272+
void foo(this auto&& self, int arg);
3273+
};
3274+
int main() {
3275+
A a {};
3276+
a.foo(^);
3277+
}
3278+
)cpp");
3279+
3280+
auto TU = TestTU::withCode(Code.code());
3281+
TU.ExtraArgs = {"-std=c++23"};
3282+
3283+
MockFS FS;
3284+
auto Inputs = TU.inputs(FS);
3285+
3286+
auto Preamble = TU.preamble();
3287+
ASSERT_TRUE(Preamble);
3288+
3289+
const auto Result = signatureHelp(testPath(TU.Filename), Code.point(),
3290+
*Preamble, Inputs, MarkupKind::PlainText);
3291+
3292+
EXPECT_EQ(1, Result.signatures.size());
3293+
3294+
EXPECT_THAT(Result.signatures[0], AllOf(sig("foo([[int arg]]) -> void")));
3295+
}
3296+
32693297
TEST(CompletionTest, IncludedCompletionKinds) {
32703298
Annotations Test(R"cpp(#include "^)cpp");
32713299
auto TU = TestTU::withCode(Test.code());

clang/lib/Sema/SemaCodeComplete.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4034,6 +4034,14 @@ static void AddOverloadParameterChunks(
40344034
return;
40354035
}
40364036

4037+
// C++23 introduces an explicit object parameter, a.k.a. "deducing this"
4038+
// Skip it for autocomplete and treat the next parameter as the first
4039+
// parameter
4040+
if (Function && FirstParameter &&
4041+
Function->getParamDecl(P)->isExplicitObjectParameter()) {
4042+
continue;
4043+
}
4044+
40374045
if (FirstParameter)
40384046
FirstParameter = false;
40394047
else

clang/test/CodeCompletion/skip-explicit-object-parameter.cpp

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,21 @@ int main() {
66
A a {};
77
a.
88
}
9-
// RUN: %clang_cc1 -cc1 -fsyntax-only -code-completion-at=%s:%(line-2):5 -std=c++23 %s | FileCheck %s
10-
// CHECK: COMPLETION: A : A::
11-
// CHECK-NEXT: COMPLETION: foo : [#void#]foo(<#int arg#>)
12-
// CHECK-NEXT: COMPLETION: operator= : [#A &#]operator=(<#const A &#>)
13-
// CHECK-NEXT: COMPLETION: operator= : [#A &#]operator=(<#A &&#>)
14-
// CHECK-NEXT: COMPLETION: ~A : [#void#]~A()
9+
// RUN: %clang_cc1 -cc1 -fsyntax-only -code-completion-at=%s:%(line-2):5 -std=c++23 %s | FileCheck -check-prefix=CHECK-CC1 %s
10+
// CHECK-CC1: COMPLETION: A : A::
11+
// CHECK-NEXT-CC1: COMPLETION: foo : [#void#]foo(<#int arg#>)
12+
// CHECK-NEXT-CC1: COMPLETION: operator= : [#A &#]operator=(<#const A &#>)
13+
// CHECK-NEXT-CC1: COMPLETION: operator= : [#A &#]operator=(<#A &&#>)
14+
// CHECK-NEXT-CC1: COMPLETION: ~A : [#void#]~A()
15+
16+
struct B {
17+
template <typename T>
18+
void foo(this T&& self, int arg);
19+
};
20+
21+
int main2() {
22+
B b {};
23+
b.foo();
24+
}
25+
// RUN: %clang_cc1 -cc1 -fsyntax-only -code-completion-at=%s:%(line-2):9 -std=c++23 %s | FileCheck -check-prefix=CHECK-CC2 %s
26+
// CHECK-CC2: OVERLOAD: [#void#]foo(int arg)

0 commit comments

Comments
 (0)