Skip to content

Commit

Permalink
Definition for instanceof class (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
Michal Niewrzal authored and felixfbecker committed Oct 26, 2016
1 parent 8a354ba commit 867196b
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 2 deletions.
4 changes: 4 additions & 0 deletions fixtures/global_references.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,7 @@ function whatever(TestClass $param): TestClass {
echo TEST_CONST;

use function test_function;

if ($abc instanceof TestInterface) {

}
4 changes: 4 additions & 0 deletions fixtures/references.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,7 @@ function whatever(TestClass $param): TestClass {
echo TEST_CONST;

use function TestNamespace\test_function;

if ($abc instanceof TestInterface) {

}
1 change: 1 addition & 0 deletions src/Fqn.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions tests/Server/ServerTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ public function setUp()
],
'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
Expand Down Expand Up @@ -145,7 +146,8 @@ public function setUp()
],
'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
Expand Down
9 changes: 9 additions & 0 deletions tests/Server/TextDocument/Definition/GlobalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,4 +211,13 @@ public function testDefinitionForUseFunctions()
$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);
}
}

0 comments on commit 867196b

Please sign in to comment.