Skip to content

Commit

Permalink
Fix auto-completion with declared static method by DocBlock
Browse files Browse the repository at this point in the history
  • Loading branch information
issidorov committed Oct 27, 2023
1 parent d6faff2 commit 2f039f9
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/Psalm/Codebase.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
use UnexpectedValueException;

use function array_combine;
use function array_merge;
use function array_pop;
use function array_reverse;
use function array_values;
Expand Down Expand Up @@ -1883,9 +1884,12 @@ public function getCompletionItemsForClassishThing(
try {
$class_storage = $this->classlike_storage_provider->get($atomic_type->value);

foreach ($class_storage->appearing_method_ids as $declaring_method_id) {
$method_storage = $this->methods->getStorage($declaring_method_id);

$methods = array_merge(
$class_storage->methods,
$class_storage->pseudo_methods,
$class_storage->pseudo_static_methods,
);
foreach ($methods as $method_storage) {
if ($method_storage->is_static || $gap === '->') {
$completion_item = new CompletionItem(
$method_storage->cased_name,
Expand Down
32 changes: 32 additions & 0 deletions tests/LanguageServer/CompletionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1456,6 +1456,38 @@ static function add() : void {
$this->assertCount(2, $completion_items);
}

public function testCompletionStaticMethodOnDocBlock(): void
{
$codebase = $this->codebase;
$config = $codebase->config;
$config->throw_exception = false;

$this->addFile(
'somefile.php',
'<?php
namespace Bar;
/**
* @method static void foo()
*/
class Alpha {}
Alpha::',
);

$codebase->file_provider->openFile('somefile.php');
$codebase->scanFiles();
$this->analyzeFile('somefile.php', new Context());

$position = new Position(7, 23);
$completion_data = $codebase->getCompletionDataAtPosition('somefile.php', $position);

$this->assertSame(['Bar\Alpha', '::', 177], $completion_data);

$completion_items = $codebase->getCompletionItemsForClassishThing($completion_data[0], $completion_data[1], true);
$this->assertCount(1, $completion_items);
$this->assertSame('foo()', $completion_items[0]->insertText);
}

public function testCompletionOnClassInstanceReferenceWithAssignmentAfter(): void
{

Expand Down

0 comments on commit 2f039f9

Please sign in to comment.