diff --git a/fixtures/completion/foreach.php b/fixtures/completion/foreach.php index c731684..df8b6df 100644 --- a/fixtures/completion/foreach.php +++ b/fixtures/completion/foreach.php @@ -32,10 +32,6 @@ foreach ($array3 as $key => $value) { $ } -foreach ($array1 as list($z, $y)) { - $ -} - foreach ($bar->test() as $value) { $ } diff --git a/src/DefinitionResolver.php b/src/DefinitionResolver.php index a22538e..f36588d 100644 --- a/src/DefinitionResolver.php +++ b/src/DefinitionResolver.php @@ -1107,8 +1107,10 @@ class DefinitionResolver return new Types\Mixed_(); } - // FOREACH VALUE - if ($node instanceof Node\ForeachValue || $node->getFirstAncestor(Node\ForeachValue::class)) { + // FOREACH VALUE/VARIABLE + if ($node instanceof Node\ForeachValue + || ($node instanceof Node\Expression\Variable && $node->parent instanceof Node\ForeachValue) + ) { $foreach = $node->getFirstAncestor(Node\Statement\ForeachStatement::class); $collectionType = $this->resolveExpressionNodeToType($foreach->forEachCollectionName); if ($collectionType instanceof Types\Array_) { diff --git a/tests/Server/TextDocument/CompletionTest.php b/tests/Server/TextDocument/CompletionTest.php index b28a5cb..ded5941 100644 --- a/tests/Server/TextDocument/CompletionTest.php +++ b/tests/Server/TextDocument/CompletionTest.php @@ -676,33 +676,8 @@ class CompletionTest extends TestCase ), ] ], - 'foreach with list()' => [ - new Position(35, 5), - [ - new CompletionItem( - '$z', - CompletionItemKind::VARIABLE, - '\\Foo\\Bar|\\stdClass', - null, - null, - null, - null, - new TextEdit(new Range(new Position(35, 5), new Position(35, 5)), 'z') - ), - new CompletionItem( - '$y', - CompletionItemKind::VARIABLE, - '\\Foo\\Bar|\\stdClass', - null, - null, - null, - null, - new TextEdit(new Range(new Position(35, 5), new Position(35, 5)), 'y') - ), - ] - ], 'foreach function call' => [ - new Position(39, 5), + new Position(35, 5), [ new CompletionItem( '$value', @@ -712,7 +687,7 @@ class CompletionTest extends TestCase null, null, null, - new TextEdit(new Range(new Position(39, 5), new Position(39, 5)), 'value') + new TextEdit(new Range(new Position(35, 5), new Position(35, 5)), 'value') ), ] ],