phpantom_lsp 0.7.0

Fast PHP language server with deep type intelligence. Generics, Laravel, PHPStan annotations. Ready in an instant.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
use crate::common::{create_psr4_workspace, create_test_backend};
use tower_lsp::LanguageServer;
use tower_lsp::lsp_types::*;

/// Helper: open a document and trigger completion at the given line/column.
async fn complete_at(
    backend: &phpantom_lsp::Backend,
    uri: &Url,
    src: &str,
    line: u32,
    character: u32,
) -> Vec<CompletionItem> {
    let open_params = DidOpenTextDocumentParams {
        text_document: TextDocumentItem {
            uri: uri.clone(),
            language_id: "php".to_string(),
            version: 1,
            text: src.to_string(),
        },
    };
    backend.did_open(open_params).await;

    let completion_params = CompletionParams {
        text_document_position: TextDocumentPositionParams {
            text_document: TextDocumentIdentifier { uri: uri.clone() },
            position: Position { line, character },
        },
        work_done_progress_params: WorkDoneProgressParams::default(),
        partial_result_params: PartialResultParams::default(),
        context: None,
    };

    match backend.completion(completion_params).await.unwrap() {
        Some(CompletionResponse::Array(items)) => items,
        Some(CompletionResponse::List(list)) => list.items,
        None => vec![],
    }
}

fn method_names(items: &[CompletionItem]) -> Vec<&str> {
    items
        .iter()
        .filter(|i| i.kind == Some(CompletionItemKind::METHOD))
        .map(|i| i.filter_text.as_deref().unwrap_or(&i.label))
        .collect()
}

fn property_names(items: &[CompletionItem]) -> Vec<&str> {
    items
        .iter()
        .filter(|i| i.kind == Some(CompletionItemKind::PROPERTY))
        .map(|i| i.filter_text.as_deref().unwrap_or(&i.label))
        .collect()
}

// ─── Closure literal with native return type hint ───────────────────────────

#[tokio::test]
async fn test_closure_literal_return_type() {
    let backend = create_test_backend();
    let uri = Url::parse("file:///test/closure_invoke.php").unwrap();

    let src = concat!(
        "<?php\n",
        "class User {\n",
        "    public function getName(): string { return ''; }\n",
        "    public function getEmail(): string { return ''; }\n",
        "}\n",
        "class Service {\n",
        "    public function run(): void {\n",
        "        $fn = function(): User { return new User(); };\n",
        "        $fn()->\n",
        "    }\n",
        "}\n",
    );

    // Line 8: `        $fn()->`  cursor after `->`
    let items = complete_at(&backend, &uri, src, 8, 15).await;
    let names = method_names(&items);
    assert!(
        names.contains(&"getName"),
        "Expected getName in {:?}",
        names,
    );
    assert!(
        names.contains(&"getEmail"),
        "Expected getEmail in {:?}",
        names,
    );
}

#[tokio::test]
async fn test_arrow_function_literal_return_type() {
    let backend = create_test_backend();
    let uri = Url::parse("file:///test/arrow_invoke.php").unwrap();

    let src = concat!(
        "<?php\n",
        "class Product {\n",
        "    public function getPrice(): float { return 0.0; }\n",
        "    public function getTitle(): string { return ''; }\n",
        "}\n",
        "class Service {\n",
        "    public function run(): void {\n",
        "        $factory = fn(): Product => new Product();\n",
        "        $factory()->\n",
        "    }\n",
        "}\n",
    );

    // Line 8: `        $factory()->` cursor after `->`
    let items = complete_at(&backend, &uri, src, 8, 20).await;
    let names = method_names(&items);
    assert!(
        names.contains(&"getPrice"),
        "Expected getPrice in {:?}",
        names,
    );
    assert!(
        names.contains(&"getTitle"),
        "Expected getTitle in {:?}",
        names,
    );
}

// ─── Docblock callable return type annotation ───────────────────────────────

#[tokio::test]
async fn test_docblock_closure_return_type() {
    let backend = create_test_backend();
    let uri = Url::parse("file:///test/docblock_closure.php").unwrap();

    let src = concat!(
        "<?php\n",
        "class Order {\n",
        "    public function getTotal(): float { return 0.0; }\n",
        "    public function getStatus(): string { return ''; }\n",
        "}\n",
        "class Service {\n",
        "    public function run(): void {\n",
        "        /** @var \\Closure(): Order $fn */\n",
        "        $fn = getCallback();\n",
        "        $fn()->\n",
        "    }\n",
        "}\n",
    );

    // Line 9: `        $fn()->`  cursor after `->`
    let items = complete_at(&backend, &uri, src, 9, 15).await;
    let names = method_names(&items);
    assert!(
        names.contains(&"getTotal"),
        "Expected getTotal in {:?}",
        names,
    );
    assert!(
        names.contains(&"getStatus"),
        "Expected getStatus in {:?}",
        names,
    );
}

#[tokio::test]
async fn test_docblock_callable_return_type() {
    let backend = create_test_backend();
    let uri = Url::parse("file:///test/docblock_callable.php").unwrap();

    let src = concat!(
        "<?php\n",
        "class Response {\n",
        "    public function getBody(): string { return ''; }\n",
        "    public function getStatusCode(): int { return 200; }\n",
        "}\n",
        "class Handler {\n",
        "    /**\n",
        "     * @param callable(): Response $handler\n",
        "     */\n",
        "    public function process($handler): void {\n",
        "        $handler()->\n",
        "    }\n",
        "}\n",
    );

    // Line 10: `        $handler()->`  cursor after `->`
    let items = complete_at(&backend, &uri, src, 10, 21).await;
    let names = method_names(&items);
    assert!(
        names.contains(&"getBody"),
        "Expected getBody in {:?}",
        names,
    );
    assert!(
        names.contains(&"getStatusCode"),
        "Expected getStatusCode in {:?}",
        names,
    );
}

#[tokio::test]
async fn test_callable_with_params_return_type() {
    let backend = create_test_backend();
    let uri = Url::parse("file:///test/callable_params.php").unwrap();

    let src = concat!(
        "<?php\n",
        "class Config {\n",
        "    public function get(string $key): string { return ''; }\n",
        "    public function set(string $key, $val): void {}\n",
        "}\n",
        "class App {\n",
        "    /**\n",
        "     * @param callable(string,int): Config $builder\n",
        "     */\n",
        "    public function init($builder): void {\n",
        "        $builder('test', 1)->\n",
        "    }\n",
        "}\n",
    );

    // Line 10: `        $builder('test', 1)->`  cursor after `->`
    let items = complete_at(&backend, &uri, src, 10, 30).await;
    let names = method_names(&items);
    assert!(names.contains(&"get"), "Expected get in {:?}", names,);
    assert!(names.contains(&"set"), "Expected set in {:?}", names,);
}

// ─── Variable assignment from closure invocation ────────────────────────────

#[tokio::test]
async fn test_variable_assigned_from_closure_invocation() {
    let backend = create_test_backend();
    let uri = Url::parse("file:///test/var_closure_result.php").unwrap();

    let src = concat!(
        "<?php\n",
        "class Customer {\n",
        "    public function getId(): int { return 1; }\n",
        "    public function getFullName(): string { return ''; }\n",
        "}\n",
        "class Service {\n",
        "    public function run(): void {\n",
        "        $factory = function(): Customer { return new Customer(); };\n",
        "        $result = $factory();\n",
        "        $result->\n",
        "    }\n",
        "}\n",
    );

    // Line 9: `        $result->`  cursor after `->`
    let items = complete_at(&backend, &uri, src, 9, 17).await;
    let names = method_names(&items);
    assert!(names.contains(&"getId"), "Expected getId in {:?}", names,);
    assert!(
        names.contains(&"getFullName"),
        "Expected getFullName in {:?}",
        names,
    );
}

#[tokio::test]
async fn test_variable_assigned_from_docblock_callable_invocation() {
    let backend = create_test_backend();
    let uri = Url::parse("file:///test/var_callable_result.php").unwrap();

    let src = concat!(
        "<?php\n",
        "class Item {\n",
        "    public function getWeight(): float { return 0.0; }\n",
        "}\n",
        "class Processor {\n",
        "    /**\n",
        "     * @param Closure(): Item $loader\n",
        "     */\n",
        "    public function handle($loader): void {\n",
        "        $item = $loader();\n",
        "        $item->\n",
        "    }\n",
        "}\n",
    );

    // Line 10: `        $item->`  cursor after `->`
    let items = complete_at(&backend, &uri, src, 10, 15).await;
    let names = method_names(&items);
    assert!(
        names.contains(&"getWeight"),
        "Expected getWeight in {:?}",
        names,
    );
}

// ─── Closure with `use` clause ──────────────────────────────────────────────

#[tokio::test]
async fn test_closure_with_use_clause_return_type() {
    let backend = create_test_backend();
    let uri = Url::parse("file:///test/closure_use.php").unwrap();

    let src = concat!(
        "<?php\n",
        "class Logger {\n",
        "    public function log(string $msg): void {}\n",
        "    public function getLevel(): int { return 0; }\n",
        "}\n",
        "class Service {\n",
        "    public function run(): void {\n",
        "        $prefix = 'INFO';\n",
        "        $fn = function() use ($prefix): Logger { return new Logger(); };\n",
        "        $fn()->\n",
        "    }\n",
        "}\n",
    );

    // Line 9: `        $fn()->`  cursor after `->`
    let items = complete_at(&backend, &uri, src, 9, 15).await;
    let names = method_names(&items);
    assert!(names.contains(&"log"), "Expected log in {:?}", names,);
    assert!(
        names.contains(&"getLevel"),
        "Expected getLevel in {:?}",
        names,
    );
}

// ─── Top-level (outside class) ──────────────────────────────────────────────

#[tokio::test]
async fn test_closure_invocation_top_level() {
    let backend = create_test_backend();
    let uri = Url::parse("file:///test/closure_toplevel.php").unwrap();

    let src = concat!(
        "<?php\n",
        "class Widget {\n",
        "    public function render(): string { return ''; }\n",
        "    public function hide(): void {}\n",
        "}\n",
        "$maker = function(): Widget { return new Widget(); };\n",
        "$maker()->\n",
    );

    // Line 6: `$maker()->`  cursor after `->`
    let items = complete_at(&backend, &uri, src, 6, 10).await;
    let names = method_names(&items);
    assert!(names.contains(&"render"), "Expected render in {:?}", names,);
    assert!(names.contains(&"hide"), "Expected hide in {:?}", names,);
}

// ─── Nullable return type ───────────────────────────────────────────────────

#[tokio::test]
async fn test_closure_nullable_return_type() {
    let backend = create_test_backend();
    let uri = Url::parse("file:///test/closure_nullable.php").unwrap();

    let src = concat!(
        "<?php\n",
        "class Session {\n",
        "    public function getId(): string { return ''; }\n",
        "    public function destroy(): void {}\n",
        "}\n",
        "class App {\n",
        "    public function run(): void {\n",
        "        $getter = function(): ?Session { return null; };\n",
        "        $getter()->\n",
        "    }\n",
        "}\n",
    );

    // Line 8: `        $getter()->`  cursor after `->`
    let items = complete_at(&backend, &uri, src, 8, 19).await;
    let names = method_names(&items);
    assert!(names.contains(&"getId"), "Expected getId in {:?}", names,);
    assert!(
        names.contains(&"destroy"),
        "Expected destroy in {:?}",
        names,
    );
}

// ─── Chaining after callable invocation ─────────────────────────────────────

#[tokio::test]
async fn test_callable_invocation_chain() {
    let backend = create_test_backend();
    let uri = Url::parse("file:///test/callable_chain.php").unwrap();

    let src = concat!(
        "<?php\n",
        "class Builder {\n",
        "    public function setName(string $n): self { return $this; }\n",
        "    public function build(): void {}\n",
        "}\n",
        "class Factory {\n",
        "    public function run(): void {\n",
        "        $make = function(): Builder { return new Builder(); };\n",
        "        $make()->setName('test')->\n",
        "    }\n",
        "}\n",
    );

    // Line 8: `        $make()->setName('test')->`  cursor after `->`
    let items = complete_at(&backend, &uri, src, 8, 37).await;
    let names = method_names(&items);
    assert!(
        names.contains(&"setName"),
        "Expected setName in {:?}",
        names,
    );
    assert!(names.contains(&"build"), "Expected build in {:?}", names,);
}

// ─── Cross-file PSR-4 ──────────────────────────────────────────────────────

#[tokio::test]
async fn test_callable_invocation_cross_file() {
    let (backend, _dir) = create_psr4_workspace(
        r#"{
            "autoload": {
                "psr-4": {
                    "App\\": "src/"
                }
            }
        }"#,
        &[(
            "src/Models/Entity.php",
            concat!(
                "<?php\n",
                "namespace App\\Models;\n",
                "\n",
                "class Entity {\n",
                "    public function save(): bool { return true; }\n",
                "    public function delete(): void {}\n",
                "}\n",
            ),
        )],
    );

    // The "current" file references Entity via FQN in the closure return type
    let uri = Url::parse("file:///app.php").unwrap();
    let text = concat!(
        "<?php\n",
        "class Repo {\n",
        "    public function handle(): void {\n",
        "        $factory = function(): \\App\\Models\\Entity { return new \\App\\Models\\Entity(); };\n",
        "        $factory()->\n",
        "    }\n",
        "}\n",
    );
    let open_params = DidOpenTextDocumentParams {
        text_document: TextDocumentItem {
            uri: uri.clone(),
            language_id: "php".to_string(),
            version: 1,
            text: text.to_string(),
        },
    };
    backend.did_open(open_params).await;

    // Cursor right after `$factory()->` on line 4
    let completion_params = CompletionParams {
        text_document_position: TextDocumentPositionParams {
            text_document: TextDocumentIdentifier { uri },
            position: Position {
                line: 4,
                character: 20,
            },
        },
        work_done_progress_params: WorkDoneProgressParams::default(),
        partial_result_params: PartialResultParams::default(),
        context: None,
    };

    let result = backend.completion(completion_params).await.unwrap();
    assert!(result.is_some(), "Completion should resolve $factory()->");

    match result.unwrap() {
        CompletionResponse::Array(items) => {
            let names: Vec<&str> = items
                .iter()
                .filter(|i| i.kind == Some(CompletionItemKind::METHOD))
                .map(|i| i.filter_text.as_deref().unwrap_or(&i.label))
                .collect();
            assert!(names.contains(&"save"), "Expected save in {:?}", names,);
            assert!(names.contains(&"delete"), "Expected delete in {:?}", names,);
        }
        _ => panic!("Expected CompletionResponse::Array"),
    }
}

// ─── Docblock Closure with backslash prefix ─────────────────────────────────

#[tokio::test]
async fn test_docblock_fqn_closure_return_type() {
    let backend = create_test_backend();
    let uri = Url::parse("file:///test/fqn_closure.php").unwrap();

    let src = concat!(
        "<?php\n",
        "class Database {\n",
        "    public function query(): void {}\n",
        "    public function disconnect(): void {}\n",
        "}\n",
        "class App {\n",
        "    /**\n",
        "     * @param \\Closure(): Database $connector\n",
        "     */\n",
        "    public function boot($connector): void {\n",
        "        $connector()->\n",
        "    }\n",
        "}\n",
    );

    // Line 10: `        $connector()->`  cursor after `->`
    let items = complete_at(&backend, &uri, src, 10, 22).await;
    let names = method_names(&items);
    assert!(names.contains(&"query"), "Expected query in {:?}", names,);
    assert!(
        names.contains(&"disconnect"),
        "Expected disconnect in {:?}",
        names,
    );
}

// ─── Properties on callable return type ─────────────────────────────────────

#[tokio::test]
async fn test_callable_return_type_properties() {
    let backend = create_test_backend();
    let uri = Url::parse("file:///test/callable_props.php").unwrap();

    let src = concat!(
        "<?php\n",
        "class Point {\n",
        "    public float $x;\n",
        "    public float $y;\n",
        "    public function distanceTo(Point $other): float { return 0.0; }\n",
        "}\n",
        "class Geo {\n",
        "    public function run(): void {\n",
        "        /** @var callable(): Point $maker */\n",
        "        $maker = getMaker();\n",
        "        $maker()->\n",
        "    }\n",
        "}\n",
    );

    // Line 10: `        $maker()->`  cursor after `->`
    let items = complete_at(&backend, &uri, src, 10, 19).await;
    let names = method_names(&items);
    let props = property_names(&items);
    assert!(
        names.contains(&"distanceTo"),
        "Expected distanceTo in {:?}",
        names,
    );
    assert!(props.contains(&"x"), "Expected property x in {:?}", props,);
    assert!(props.contains(&"y"), "Expected property y in {:?}", props,);
}

// ─── Inline @var override for callable ──────────────────────────────────────

#[tokio::test]
async fn test_inline_var_callable_return_type() {
    let backend = create_test_backend();
    let uri = Url::parse("file:///test/inline_var_callable.php").unwrap();

    let src = concat!(
        "<?php\n",
        "class Mailer {\n",
        "    public function send(): bool { return true; }\n",
        "    public function setSubject(string $s): self { return $this; }\n",
        "}\n",
        "class Notifier {\n",
        "    public function notify(): void {\n",
        "        /** @var Closure(): Mailer $fn */\n",
        "        $fn = getMailerFactory();\n",
        "        $fn()->\n",
        "    }\n",
        "}\n",
    );

    // Line 9: `        $fn()->`  cursor after `->`
    let items = complete_at(&backend, &uri, src, 9, 15).await;
    let names = method_names(&items);
    assert!(names.contains(&"send"), "Expected send in {:?}", names,);
    assert!(
        names.contains(&"setSubject"),
        "Expected setSubject in {:?}",
        names,
    );
}

// ── __invoke() return type resolution ──────────────────────────

/// `$f = new Invokable(); $f()->` resolves via __invoke() return type.
#[tokio::test]
async fn test_invoke_return_type_simple() {
    let backend = create_test_backend();
    let uri = Url::parse("file:///test/invoke_simple.php").unwrap();

    let src = concat!(
        "<?php\n",
        "class Result { public function getValue(): string {} }\n",
        "class Invokable {\n",
        "    public function __invoke(): Result {}\n",
        "}\n",
        "$f = new Invokable();\n",
        "$f()->\n",
    );

    let items = complete_at(&backend, &uri, src, 6, 6).await;
    let methods = method_names(&items);
    assert!(
        methods.contains(&"getValue"),
        "Expected getValue from __invoke() return type, got: {methods:?}"
    );
}

/// `$f = new Invokable(); $f()->method()->` chains through __invoke().
#[tokio::test]
async fn test_invoke_return_type_chain() {
    let backend = create_test_backend();
    let uri = Url::parse("file:///test/invoke_chain.php").unwrap();

    let src = concat!(
        "<?php\n",
        "class Builder {\n",
        "    public function build(): Product {}\n",
        "}\n",
        "class Product { public function getTitle(): string {} }\n",
        "class Factory {\n",
        "    public function __invoke(): Builder {}\n",
        "}\n",
        "$f = new Factory();\n",
        "$f()->build()->\n",
    );

    let items = complete_at(&backend, &uri, src, 9, 15).await;
    let methods = method_names(&items);
    assert!(
        methods.contains(&"getTitle"),
        "Expected getTitle from chained __invoke()->build(), got: {methods:?}"
    );
}

/// __invoke() on a variable assigned from a method returning an invokable.
#[tokio::test]
async fn test_invoke_return_type_from_method() {
    let backend = create_test_backend();
    let uri = Url::parse("file:///test/invoke_method.php").unwrap();

    let src = concat!(
        "<?php\n",
        "class Output { public function render(): void {} }\n",
        "class Renderer {\n",
        "    public function __invoke(): Output {}\n",
        "}\n",
        "class App {\n",
        "    public function getRenderer(): Renderer {}\n",
        "}\n",
        "$app = new App();\n",
        "$r = $app->getRenderer();\n",
        "$r()->\n",
    );

    let items = complete_at(&backend, &uri, src, 10, 6).await;
    let methods = method_names(&items);
    assert!(
        methods.contains(&"render"),
        "Expected render from method-returned __invoke(), got: {methods:?}"
    );
}

/// Variable assigned an invokable via `new` at top level: `$h = new Handler(); $h()->...`
#[tokio::test]
async fn test_invoke_return_type_assigned_new() {
    let backend = create_test_backend();
    let uri = Url::parse("file:///test/invoke_new.php").unwrap();

    let src = concat!(
        "<?php\n",
        "class Response { public function getStatus(): int {} }\n",
        "class Handler {\n",
        "    public function __invoke(): Response {}\n",
        "}\n",
        "$h = new Handler();\n",
        "$h()->\n",
    );

    let items = complete_at(&backend, &uri, src, 6, 6).await;
    let methods = method_names(&items);
    assert!(
        methods.contains(&"getStatus"),
        "Expected getStatus from $h = new Handler(); $h(), got: {methods:?}"
    );
}

/// __invoke() with docblock return type richer than native hint.
#[tokio::test]
async fn test_invoke_docblock_return_type() {
    let backend = create_test_backend();
    let uri = Url::parse("file:///test/invoke_docblock.php").unwrap();

    let src = concat!(
        "<?php\n",
        "class Item { public function getLabel(): string {} }\n",
        "class Fetcher {\n",
        "    /** @return Item[] */\n",
        "    public function __invoke(): array {}\n",
        "}\n",
        "$f = new Fetcher();\n",
        "foreach ($f() as $item) {\n",
        "    $item->\n",
        "}\n",
    );

    let items = complete_at(&backend, &uri, src, 8, 11).await;
    let methods = method_names(&items);
    assert!(
        methods.contains(&"getLabel"),
        "Expected getLabel from __invoke() docblock @return Item[], got: {methods:?}"
    );
}

/// `($this->prop)()->` resolves through the property's __invoke() method.
#[tokio::test]
async fn test_invoke_parenthesized_property() {
    let backend = create_test_backend();
    let uri = Url::parse("file:///test/invoke_paren_prop.php").unwrap();

    let src = concat!(
        "<?php\n",
        "class InvPen4 { public function write(): void {} }\n",
        "class MyInvoker4 {\n",
        "    public function __invoke(): InvPen4 {}\n",
        "}\n",
        "class InvApp4 {\n",
        "    private MyInvoker4 $invoker;\n",
        "    public function demo(): void {\n",
        "        ($this->invoker)()->\n",
        "    }\n",
        "}\n",
    );

    let items = complete_at(&backend, &uri, src, 8, 28).await;
    let methods = method_names(&items);
    assert!(
        methods.contains(&"write"),
        "Expected write from ($this->invoker)() __invoke(), got: {methods:?}"
    );
}