Definition for use function (#116)
parent
6806ba94e0
commit
8a354ba1af
|
@ -28,3 +28,5 @@ $fn = function() use ($var) {
|
||||||
};
|
};
|
||||||
|
|
||||||
echo TEST_CONST;
|
echo TEST_CONST;
|
||||||
|
|
||||||
|
use function test_function;
|
||||||
|
|
|
@ -28,3 +28,5 @@ $fn = function() use ($var) {
|
||||||
};
|
};
|
||||||
|
|
||||||
echo TEST_CONST;
|
echo TEST_CONST;
|
||||||
|
|
||||||
|
use function TestNamespace\test_function;
|
||||||
|
|
|
@ -45,6 +45,8 @@ function getReferencedFqn(Node $node)
|
||||||
$grandParent = $parent->getAttribute('parentNode');
|
$grandParent = $parent->getAttribute('parentNode');
|
||||||
if ($grandParent instanceof Node\Stmt\GroupUse) {
|
if ($grandParent instanceof Node\Stmt\GroupUse) {
|
||||||
$name = $grandParent->prefix . '\\' . $name;
|
$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
|
// Only the name node should be considered a reference, not the New_ node itself
|
||||||
} else if ($parent instanceof Node\Expr\New_) {
|
} else if ($parent instanceof Node\Expr\New_) {
|
||||||
|
|
|
@ -126,7 +126,8 @@ abstract class ServerTestCase extends TestCase
|
||||||
0 => new Location($referencesUri, new Range(new Position( 5, 0), new Position( 5, 18)))
|
0 => new Location($referencesUri, new Range(new Position( 5, 0), new Position( 5, 18)))
|
||||||
],
|
],
|
||||||
'TestNamespace\\test_function()' => [
|
'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
|
// Global
|
||||||
|
@ -164,7 +165,8 @@ abstract class ServerTestCase extends TestCase
|
||||||
0 => new Location($globalReferencesUri, new Range(new Position( 5, 0), new Position( 5, 18)))
|
0 => new Location($globalReferencesUri, new Range(new Position( 5, 0), new Position( 5, 18)))
|
||||||
],
|
],
|
||||||
'test_function()' => [
|
'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
|
// @codingStandardsIgnoreEnd
|
||||||
|
|
|
@ -202,4 +202,13 @@ class GlobalTest extends ServerTestCase
|
||||||
$result = $this->textDocument->definition(new TextDocumentIdentifier($reference->uri), $reference->range->start);
|
$result = $this->textDocument->definition(new TextDocumentIdentifier($reference->uri), $reference->range->start);
|
||||||
$this->assertEquals($this->getDefinitionLocation('test_function()'), $result);
|
$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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -101,6 +101,9 @@ class GlobalTest extends ServerTestCase
|
||||||
$referencesUri = pathToUri(realpath(__DIR__ . '/../../../../fixtures/references.php'));
|
$referencesUri = pathToUri(realpath(__DIR__ . '/../../../../fixtures/references.php'));
|
||||||
$symbolsUri = pathToUri(realpath(__DIR__ . '/../../../../fixtures/symbols.php'));
|
$symbolsUri = pathToUri(realpath(__DIR__ . '/../../../../fixtures/symbols.php'));
|
||||||
$result = $this->textDocument->references(new ReferenceContext, new TextDocumentIdentifier($symbolsUri), new Position(78, 16));
|
$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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue