diff --git a/src/PhpDocument.php b/src/PhpDocument.php index 7279d44..eaf50d6 100644 --- a/src/PhpDocument.php +++ b/src/PhpDocument.php @@ -475,7 +475,7 @@ class PhpDocument { // Variables always stay in the boundary of the file and need to be searched inside their function scope // by traversing the AST - if ($node instanceof Node\Expr\Variable) { + if ($node instanceof Node\Expr\Variable || $node instanceof Node\Param) { if ($node->name instanceof Node\Expr) { return null; } diff --git a/tests/Server/TextDocument/References/NamespacedTest.php b/tests/Server/TextDocument/References/NamespacedTest.php index 3ff31ae..4d6c26e 100644 --- a/tests/Server/TextDocument/References/NamespacedTest.php +++ b/tests/Server/TextDocument/References/NamespacedTest.php @@ -320,43 +320,23 @@ class NamespacedTest extends TestCase ], json_decode(json_encode($result), true)); } - public function testReferencesForParams() + public function testReferencesForFunctionParams() { - $this->markTestIncomplete(); - // echo $param; - // Get definition for $param - $result = $this->textDocument->definition(new TextDocumentIdentifier($this->referencesUri), new Position(16, 13)); + // function whatever(TestClass $param): TestClass + // Get references for $param + $result = $this->textDocument->references(new ReferenceContext, new TextDocumentIdentifier($this->referencesUri), new Position(15, 32)); $this->assertEquals([ - 'uri' => $this->referencesUri, - 'range' => [ - 'start' => [ - 'line' => 15, - 'character' => 18 - ], - 'end' => [ - 'line' => 15, - 'character' => 33 - ] - ] - ], json_decode(json_encode($result), true)); - } - - public function testReferencesForUsedVariables() - { - $this->markTestIncomplete(); - // echo $var; - // Get definition for $var - $result = $this->textDocument->definition(new TextDocumentIdentifier($this->referencesUri), new Position(20, 11)); - $this->assertEquals([ - 'uri' => $this->referencesUri, - 'range' => [ - 'start' => [ - 'line' => 19, - 'character' => 22 - ], - 'end' => [ - 'line' => 19, - 'character' => 25 + [ + 'uri' => $this->referencesUri, + 'range' => [ + 'start' => [ + 'line' => 16, + 'character' => 9 + ], + 'end' => [ + 'line' => 16, + 'character' => 15 + ] ] ] ], json_decode(json_encode($result), true)); @@ -364,20 +344,21 @@ class NamespacedTest extends TestCase public function testReferencesForFunctions() { - $this->markTestIncomplete(); - // test_function(); - // Get definition for test_function - $result = $this->textDocument->definition(new TextDocumentIdentifier($this->referencesUri), new Position(10, 4)); + // function test_function() + // Get references for test_function + $result = $this->textDocument->references(new ReferenceContext, new TextDocumentIdentifier($this->symbolsUri), new Position(33, 16)); $this->assertEquals([ - 'uri' => $this->symbolsUri, - 'range' => [ - 'start' => [ - 'line' => 33, - 'character' => 0 - ], - 'end' => [ - 'line' => 36, - 'character' => 0 + [ + 'uri' => $this->referencesUri, + 'range' => [ + 'start' => [ + 'line' => 10, + 'character' => 0 + ], + 'end' => [ + 'line' => 10, + 'character' => 13 + ] ] ] ], json_decode(json_encode($result), true));