From 9600211df876abc929bb75edd6ee542e8a0bbcf7 Mon Sep 17 00:00:00 2001 From: Michal Niewrzal Date: Wed, 19 Oct 2016 22:45:46 +0200 Subject: [PATCH] Go to definition doesn't work for method return type --- fixtures/global_symbols.php | 2 +- fixtures/symbols.php | 2 +- src/PhpDocument.php | 2 +- tests/Server/ServerTestCase.php | 6 ++++-- tests/Server/TextDocument/Definition/GlobalTest.php | 9 +++++++++ tests/Server/TextDocument/HoverTest.php | 2 +- 6 files changed, 17 insertions(+), 6 deletions(-) diff --git a/fixtures/global_symbols.php b/fixtures/global_symbols.php index 915dcfe..ed9ba61 100644 --- a/fixtures/global_symbols.php +++ b/fixtures/global_symbols.php @@ -55,7 +55,7 @@ class TestClass implements TestInterface * @param TestClass $testParameter Lorem sunt velit incididunt mollit * @return TestClass */ - public function testMethod($testParameter) + public function testMethod($testParameter): TestInterface { $testVariable = 123; } diff --git a/fixtures/symbols.php b/fixtures/symbols.php index 4904e07..238e62c 100644 --- a/fixtures/symbols.php +++ b/fixtures/symbols.php @@ -55,7 +55,7 @@ class TestClass implements TestInterface * @param TestClass $testParameter Lorem sunt velit incididunt mollit * @return TestClass */ - public function testMethod($testParameter) + public function testMethod($testParameter): TestInterface { $testVariable = 123; } diff --git a/src/PhpDocument.php b/src/PhpDocument.php index c208ae4..004301c 100644 --- a/src/PhpDocument.php +++ b/src/PhpDocument.php @@ -367,7 +367,7 @@ class PhpDocument $node instanceof Node\Name && ( $parent instanceof Node\Stmt\ClassLike || $parent instanceof Node\Param - || $parent instanceof Node\Stmt\Function_ + || $parent instanceof Node\FunctionLike || $parent instanceof Node\Expr\StaticCall || $parent instanceof Node\Expr\ClassConstFetch || $parent instanceof Node\Expr\StaticPropertyFetch diff --git a/tests/Server/ServerTestCase.php b/tests/Server/ServerTestCase.php index 47981b9..bdb83b1 100644 --- a/tests/Server/ServerTestCase.php +++ b/tests/Server/ServerTestCase.php @@ -104,7 +104,8 @@ abstract class ServerTestCase extends TestCase 6 => new Location($useUri, new Range(new Position( 4, 4), new Position( 4, 27))), // use TestNamespace\TestClass; ], 'TestNamespace\\TestInterface' => [ - 0 => new Location($symbolsUri, new Range(new Position(20, 27), new Position(20, 40))) // class TestClass implements TestInterface + 0 => new Location($symbolsUri, new Range(new Position(20, 27), new Position(20, 40))), // class TestClass implements TestInterface + 1 => new Location($symbolsUri, new Range(new Position(57, 48), new Position(57, 61))) // public function testMethod($testParameter): TestInterface ], 'TestNamespace\\TestClass::TEST_CLASS_CONST' => [ 0 => new Location($referencesUri, new Range(new Position( 9, 5), new Position( 9, 32))) @@ -139,7 +140,8 @@ abstract class ServerTestCase extends TestCase 5 => new Location($globalReferencesUri, new Range(new Position(21, 37), new Position(21, 46))), // function whatever(TestClass $param): TestClass ], 'TestInterface' => [ - 0 => new Location($globalSymbolsUri, new Range(new Position(20, 27), new Position(20, 40))) // class TestClass implements TestInterface + 0 => new Location($globalSymbolsUri, new Range(new Position(20, 27), new Position(20, 40))), // class TestClass implements TestInterface + 1 => new Location($globalSymbolsUri, new Range(new Position(57, 48), new Position(57, 61))) // public function testMethod($testParameter): TestInterface ], 'TestClass::TEST_CLASS_CONST' => [ 0 => new Location($globalReferencesUri, new Range(new Position( 9, 5), new Position( 9, 32))) diff --git a/tests/Server/TextDocument/Definition/GlobalTest.php b/tests/Server/TextDocument/Definition/GlobalTest.php index 5c854e2..a0c0f7d 100644 --- a/tests/Server/TextDocument/Definition/GlobalTest.php +++ b/tests/Server/TextDocument/Definition/GlobalTest.php @@ -147,6 +147,15 @@ class GlobalTest extends ServerTestCase $this->assertEquals($this->getDefinitionLocation('TestClass'), $result); } + public function testDefinitionForMethodReturnTypeHints() + { + // public function testMethod($testParameter): TestInterface + // Get definition for TestInterface + $reference = $this->getReferenceLocations('TestInterface')[1]; + $result = $this->textDocument->definition(new TextDocumentIdentifier($reference->uri), $reference->range->start); + $this->assertEquals($this->getDefinitionLocation('TestInterface'), $result); + } + public function testDefinitionForParams() { // echo $param; diff --git a/tests/Server/TextDocument/HoverTest.php b/tests/Server/TextDocument/HoverTest.php index ad7d3cf..20d59d0 100644 --- a/tests/Server/TextDocument/HoverTest.php +++ b/tests/Server/TextDocument/HoverTest.php @@ -30,7 +30,7 @@ class HoverTest extends ServerTestCase $reference = $this->getReferenceLocations('TestClass::testMethod()')[0]; $result = $this->textDocument->hover(new TextDocumentIdentifier($reference->uri), $reference->range->end); $this->assertEquals(new Hover([ - new MarkedString('php', "range), $result); }