1
0
Fork 0

Definition for use function (#116)

pull/117/head
Michal Niewrzal 2016-10-26 11:47:02 +02:00 committed by Felix Becker
parent 6806ba94e0
commit 8a354ba1af
6 changed files with 23 additions and 3 deletions

View File

@ -28,3 +28,5 @@ $fn = function() use ($var) {
};
echo TEST_CONST;
use function test_function;

View File

@ -28,3 +28,5 @@ $fn = function() use ($var) {
};
echo TEST_CONST;
use function TestNamespace\test_function;

View File

@ -45,6 +45,8 @@ function getReferencedFqn(Node $node)
$grandParent = $parent->getAttribute('parentNode');
if ($grandParent instanceof Node\Stmt\GroupUse) {
$name = $grandParent->prefix . '\\' . $name;
} else if ($grandParent instanceof Node\Stmt\Use_ && $grandParent->type === Node\Stmt\Use_::TYPE_FUNCTION) {
$name .= '()';
}
// Only the name node should be considered a reference, not the New_ node itself
} else if ($parent instanceof Node\Expr\New_) {

View File

@ -126,7 +126,8 @@ abstract class ServerTestCase extends TestCase
0 => new Location($referencesUri, new Range(new Position( 5, 0), new Position( 5, 18)))
],
'TestNamespace\\test_function()' => [
0 => new Location($referencesUri, new Range(new Position(10, 0), new Position(10, 13)))
0 => new Location($referencesUri, new Range(new Position(10, 0), new Position(10, 13))),
1 => new Location($referencesUri, new Range(new Position(31, 13), new Position(31, 40)))
],
// Global
@ -164,7 +165,8 @@ abstract class ServerTestCase extends TestCase
0 => new Location($globalReferencesUri, new Range(new Position( 5, 0), new Position( 5, 18)))
],
'test_function()' => [
0 => new Location($globalReferencesUri, new Range(new Position(10, 0), new Position(10, 13)))
0 => new Location($globalReferencesUri, new Range(new Position(10, 0), new Position(10, 13))),
1 => new Location($globalReferencesUri, new Range(new Position(31, 13), new Position(31, 40)))
]
];
// @codingStandardsIgnoreEnd

View File

@ -202,4 +202,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 testDefinitionForUseFunctions()
{
// use function test_function;
// Get definition for test_function
$reference = $this->getReferenceLocations('test_function()')[1];
$result = $this->textDocument->definition(new TextDocumentIdentifier($reference->uri), $reference->range->start);
$this->assertEquals($this->getDefinitionLocation('test_function()'), $result);
}
}

View File

@ -101,6 +101,9 @@ class GlobalTest extends ServerTestCase
$referencesUri = pathToUri(realpath(__DIR__ . '/../../../../fixtures/references.php'));
$symbolsUri = pathToUri(realpath(__DIR__ . '/../../../../fixtures/symbols.php'));
$result = $this->textDocument->references(new ReferenceContext, new TextDocumentIdentifier($symbolsUri), new Position(78, 16));
$this->assertEquals([new Location($referencesUri, new Range(new Position(10, 0), new Position(10, 13)))], $result);
$this->assertEquals([
new Location($referencesUri, new Range(new Position(10, 0), new Position(10, 13))),
new Location($referencesUri, new Range(new Position(31, 13), new Position(31, 40)))
], $result);
}
}