@@ -3267,6 +3267,56 @@ TEST(SignatureHelpTest, VariadicType) {
3267
3267
}
3268
3268
}
3269
3269
3270
+ TEST (SignatureHelpTest, SkipExplicitObjectParameter) {
3271
+ Annotations Code (R"cpp(
3272
+ struct A {
3273
+ void foo(this auto&& self, int arg);
3274
+ void bar(this A self, int arg);
3275
+ };
3276
+ int main() {
3277
+ A a {};
3278
+ a.foo($c1^);
3279
+ (&A::bar)($c2^);
3280
+ (&A::foo)($c3^);
3281
+ }
3282
+ )cpp" );
3283
+
3284
+ auto TU = TestTU::withCode (Code.code ());
3285
+ TU.ExtraArgs = {" -std=c++23" };
3286
+
3287
+ MockFS FS;
3288
+ auto Inputs = TU.inputs (FS);
3289
+
3290
+ auto Preamble = TU.preamble ();
3291
+ ASSERT_TRUE (Preamble);
3292
+
3293
+ {
3294
+ const auto Result = signatureHelp (testPath (TU.Filename ), Code.point (" c1" ),
3295
+ *Preamble, Inputs, MarkupKind::PlainText);
3296
+
3297
+ EXPECT_EQ (1U , Result.signatures .size ());
3298
+
3299
+ EXPECT_THAT (Result.signatures [0 ], AllOf (sig (" foo([[int arg]]) -> void" )));
3300
+ }
3301
+ {
3302
+ const auto Result = signatureHelp (testPath (TU.Filename ), Code.point (" c2" ),
3303
+ *Preamble, Inputs, MarkupKind::PlainText);
3304
+
3305
+ EXPECT_EQ (1U , Result.signatures .size ());
3306
+
3307
+ EXPECT_THAT (Result.signatures [0 ], AllOf (sig (" ([[A]], [[int]]) -> void" )));
3308
+ }
3309
+ {
3310
+ // TODO: llvm/llvm-project/146649
3311
+ const auto Result = signatureHelp (testPath (TU.Filename ), Code.point (" c3" ),
3312
+ *Preamble, Inputs, MarkupKind::PlainText);
3313
+ // TODO: We expect 1 signature here, with this signature
3314
+ EXPECT_EQ (0U , Result.signatures .size ());
3315
+ // EXPECT_THAT(Result.signatures[0], AllOf(sig("([[auto&&]], [[int]]) ->
3316
+ // void")));
3317
+ }
3318
+ }
3319
+
3270
3320
TEST (CompletionTest, IncludedCompletionKinds) {
3271
3321
Annotations Test (R"cpp( #include "^)cpp" );
3272
3322
auto TU = TestTU::withCode (Test.code ());
@@ -4369,14 +4419,24 @@ TEST(CompletionTest, SkipExplicitObjectParameter) {
4369
4419
Annotations Code (R"cpp(
4370
4420
struct A {
4371
4421
void foo(this auto&& self, int arg);
4422
+ void bar(this A self, int arg);
4372
4423
};
4373
4424
4374
4425
int main() {
4375
4426
A a {};
4376
- a.^
4427
+ a.$c1^;
4428
+ (&A::fo$c2^;
4429
+ (&A::ba$c3^;
4377
4430
}
4378
4431
)cpp" );
4379
4432
4433
+ // TODO: llvm/llvm-project/146649
4434
+ // This is incorrect behavior. Correct Result should be a variant of,
4435
+ // c2: signature = (auto&& self, int arg)
4436
+ // snippet = (${1: auto&& self}, ${2: int arg})
4437
+ // c3: signature = (A self, int arg)
4438
+ // snippet = (${1: A self}, ${2: int arg})
4439
+
4380
4440
auto TU = TestTU::withCode (Code.code ());
4381
4441
TU.ExtraArgs = {" -std=c++23" };
4382
4442
@@ -4387,12 +4447,31 @@ TEST(CompletionTest, SkipExplicitObjectParameter) {
4387
4447
4388
4448
MockFS FS;
4389
4449
auto Inputs = TU.inputs (FS);
4390
- auto Result = codeComplete (testPath (TU.Filename ), Code.point (),
4391
- Preamble.get (), Inputs, Opts);
4392
-
4393
- EXPECT_THAT (Result.Completions ,
4394
- ElementsAre (AllOf (named (" foo" ), signature (" (int arg)" ),
4395
- snippetSuffix (" (${1:int arg})" ))));
4450
+ {
4451
+ auto Result = codeComplete (testPath (TU.Filename ), Code.point (" c1" ),
4452
+ Preamble.get (), Inputs, Opts);
4453
+
4454
+ EXPECT_THAT (Result.Completions ,
4455
+ UnorderedElementsAre (AllOf (named (" foo" ), signature (" (int arg)" ),
4456
+ snippetSuffix (" (${1:int arg})" )),
4457
+ AllOf (named (" bar" ), signature (" (int arg)" ),
4458
+ snippetSuffix (" (${1:int arg})" ))));
4459
+ }
4460
+ {
4461
+ auto Result = codeComplete (testPath (TU.Filename ), Code.point (" c2" ),
4462
+ Preamble.get (), Inputs, Opts);
4463
+ EXPECT_THAT (
4464
+ Result.Completions ,
4465
+ ElementsAre (AllOf (named (" foo" ), signature (" <class self:auto>(int arg)" ),
4466
+ snippetSuffix (" <${1:class self:auto}>" ))));
4467
+ }
4468
+ {
4469
+ auto Result = codeComplete (testPath (TU.Filename ), Code.point (" c3" ),
4470
+ Preamble.get (), Inputs, Opts);
4471
+ EXPECT_THAT (Result.Completions ,
4472
+ ElementsAre (AllOf (named (" bar" ), signature (" (int arg)" ),
4473
+ snippetSuffix (" " ))));
4474
+ }
4396
4475
}
4397
4476
} // namespace
4398
4477
} // namespace clangd
0 commit comments