From a19d225a7aa0d89d9ceb76908e5ba11dfb2e2d69 Mon Sep 17 00:00:00 2001 From: Michal Niewrzal Date: Fri, 21 Oct 2016 16:51:11 +0200 Subject: [PATCH] Fix definition for method return type (#76) --- fixtures/global_symbols.php | 2 +- fixtures/symbols.php | 2 +- src/Fqn.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 e39bb0c..6eba8bb 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 { $this->testProperty = $testParameter; } diff --git a/fixtures/symbols.php b/fixtures/symbols.php index 7fee2d2..8911101 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 { $this->testProperty = $testParameter; } diff --git a/src/Fqn.php b/src/Fqn.php index 25e59ae..a361a7d 100644 --- a/src/Fqn.php +++ b/src/Fqn.php @@ -31,7 +31,7 @@ function getReferencedFqn(Node $node) $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 bb83534..6728a9f 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($symbolsUri, new Range(new Position(48, 13), new Position(48, 35))), // echo self::TEST_CLASS_CONSTANT @@ -141,7 +142,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($globalSymbolsUri, new Range(new Position(48, 13), new Position(48, 35))), // echo self::TEST_CLASS_CONSTANT diff --git a/tests/Server/TextDocument/Definition/GlobalTest.php b/tests/Server/TextDocument/Definition/GlobalTest.php index f58c35a..9fd325e 100644 --- a/tests/Server/TextDocument/Definition/GlobalTest.php +++ b/tests/Server/TextDocument/Definition/GlobalTest.php @@ -165,6 +165,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); }