From 867196babff0892207ac720ae33c92f3905d6d8d Mon Sep 17 00:00:00 2001 From: Michal Niewrzal Date: Wed, 26 Oct 2016 20:56:02 +0200 Subject: [PATCH] Definition for instanceof class (#117) --- fixtures/global_references.php | 4 ++++ fixtures/references.php | 4 ++++ src/Fqn.php | 1 + tests/Server/ServerTestCase.php | 6 ++++-- tests/Server/TextDocument/Definition/GlobalTest.php | 9 +++++++++ 5 files changed, 22 insertions(+), 2 deletions(-) diff --git a/fixtures/global_references.php b/fixtures/global_references.php index e44955a..8346923 100644 --- a/fixtures/global_references.php +++ b/fixtures/global_references.php @@ -30,3 +30,7 @@ $fn = function() use ($var) { echo TEST_CONST; use function test_function; + +if ($abc instanceof TestInterface) { + +} diff --git a/fixtures/references.php b/fixtures/references.php index 11fcf7f..ca27443 100644 --- a/fixtures/references.php +++ b/fixtures/references.php @@ -30,3 +30,7 @@ $fn = function() use ($var) { echo TEST_CONST; use function TestNamespace\test_function; + +if ($abc instanceof TestInterface) { + +} diff --git a/src/Fqn.php b/src/Fqn.php index dbf670b..f5ef00d 100644 --- a/src/Fqn.php +++ b/src/Fqn.php @@ -35,6 +35,7 @@ function getReferencedFqn(Node $node) || $parent instanceof Node\Expr\StaticCall || $parent instanceof Node\Expr\ClassConstFetch || $parent instanceof Node\Expr\StaticPropertyFetch + || $parent instanceof Node\Expr\Instanceof_ ) ) { // For extends, implements, type hints and classes of classes of static calls use the name directly diff --git a/tests/Server/ServerTestCase.php b/tests/Server/ServerTestCase.php index 81196b0..cb4ed19 100644 --- a/tests/Server/ServerTestCase.php +++ b/tests/Server/ServerTestCase.php @@ -106,7 +106,8 @@ abstract class ServerTestCase extends TestCase ], 'TestNamespace\\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 + 1 => new Location($symbolsUri, new Range(new Position(57, 48), new Position(57, 61))), // public function testMethod($testParameter): TestInterface + 2 => new Location($referencesUri, new Range(new Position(33, 20), new Position(33, 33))) // if ($abc instanceof 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 @@ -145,7 +146,8 @@ abstract class ServerTestCase extends TestCase ], '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 + 1 => new Location($globalSymbolsUri, new Range(new Position(57, 48), new Position(57, 61))), // public function testMethod($testParameter): TestInterface + 2 => new Location($globalReferencesUri, new Range(new Position(33, 20), new Position(33, 33))) // if ($abc instanceof 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 527200e..ded6f38 100644 --- a/tests/Server/TextDocument/Definition/GlobalTest.php +++ b/tests/Server/TextDocument/Definition/GlobalTest.php @@ -211,4 +211,13 @@ class GlobalTest extends ServerTestCase $result = $this->textDocument->definition(new TextDocumentIdentifier($reference->uri), $reference->range->start); $this->assertEquals($this->getDefinitionLocation('test_function()'), $result); } + + public function testDefinitionForInstanceOf() + { + // if ($abc instanceof TestInterface) { + // Get definition for TestInterface + $reference = $this->getReferenceLocations('TestInterface')[2]; + $result = $this->textDocument->definition(new TextDocumentIdentifier($reference->uri), $reference->range->start); + $this->assertEquals($this->getDefinitionLocation('TestInterface'), $result); + } }