Resolve self, static, parent (#99)
parent
6bd1b10e4d
commit
e19670c141
|
@ -46,7 +46,7 @@ class TestClass implements TestInterface
|
||||||
*/
|
*/
|
||||||
public static function staticTestMethod()
|
public static function staticTestMethod()
|
||||||
{
|
{
|
||||||
|
echo self::TEST_CLASS_CONST;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -46,7 +46,7 @@ class TestClass implements TestInterface
|
||||||
*/
|
*/
|
||||||
public static function staticTestMethod()
|
public static function staticTestMethod()
|
||||||
{
|
{
|
||||||
|
echo self::TEST_CLASS_CONST;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -454,7 +454,29 @@ class PhpDocument
|
||||||
// Cannot get definition of dynamic names
|
// Cannot get definition of dynamic names
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
$name = (string)$node->class . '::' . $node->name;
|
$className = (string)$node->class;
|
||||||
|
if ($className === 'self' || $className === 'static' || $className === 'parent') {
|
||||||
|
// self and static are resolved to the containing class
|
||||||
|
$n = $node;
|
||||||
|
while ($n = $n->getAttribute('parentNode')) {
|
||||||
|
if ($n instanceof Node\Stmt\Class_) {
|
||||||
|
if ($n->isAnonymous()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if ($className === 'parent') {
|
||||||
|
// parent is resolved to the parent class
|
||||||
|
if (!isset($n->extends)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
$className = (string)$n->extends;
|
||||||
|
} else {
|
||||||
|
$className = (string)$n->namespacedName;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$name = (string)$className . '::' . $node->name;
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -107,7 +107,8 @@ abstract class ServerTestCase extends TestCase
|
||||||
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
|
||||||
],
|
],
|
||||||
'TestNamespace\\TestClass::TEST_CLASS_CONST' => [
|
'TestNamespace\\TestClass::TEST_CLASS_CONST' => [
|
||||||
0 => new Location($referencesUri, new Range(new Position( 9, 5), new Position( 9, 32)))
|
0 => new Location($symbolsUri, new Range(new Position(48, 13), new Position(48, 35))), // echo self::TEST_CLASS_CONSTANT
|
||||||
|
1 => new Location($referencesUri, new Range(new Position( 9, 5), new Position( 9, 32)))
|
||||||
],
|
],
|
||||||
'TestNamespace\\TestClass::testProperty' => [
|
'TestNamespace\\TestClass::testProperty' => [
|
||||||
0 => new Location($symbolsUri, new Range(new Position(59, 8), new Position(59, 27))), // $this->testProperty = $testParameter;
|
0 => new Location($symbolsUri, new Range(new Position(59, 8), new Position(59, 27))), // $this->testProperty = $testParameter;
|
||||||
|
@ -143,7 +144,8 @@ abstract class ServerTestCase extends TestCase
|
||||||
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
|
||||||
],
|
],
|
||||||
'TestClass::TEST_CLASS_CONST' => [
|
'TestClass::TEST_CLASS_CONST' => [
|
||||||
0 => new Location($globalReferencesUri, new Range(new Position( 9, 5), new Position( 9, 32)))
|
0 => new Location($globalSymbolsUri, new Range(new Position(48, 13), new Position(48, 35))), // echo self::TEST_CLASS_CONSTANT
|
||||||
|
1 => new Location($globalReferencesUri, new Range(new Position( 9, 5), new Position( 9, 32)))
|
||||||
],
|
],
|
||||||
'TestClass::testProperty' => [
|
'TestClass::testProperty' => [
|
||||||
0 => new Location($globalSymbolsUri, new Range(new Position(59, 8), new Position(59, 27))), // $this->testProperty = $testParameter;
|
0 => new Location($globalSymbolsUri, new Range(new Position(59, 8), new Position(59, 27))), // $this->testProperty = $testParameter;
|
||||||
|
|
|
@ -70,6 +70,15 @@ class GlobalTest extends ServerTestCase
|
||||||
{
|
{
|
||||||
// echo TestClass::TEST_CLASS_CONST;
|
// echo TestClass::TEST_CLASS_CONST;
|
||||||
// Get definition for TEST_CLASS_CONST
|
// Get definition for TEST_CLASS_CONST
|
||||||
|
$reference = $this->getReferenceLocations('TestClass::TEST_CLASS_CONST')[1];
|
||||||
|
$result = $this->textDocument->definition(new TextDocumentIdentifier($reference->uri), $reference->range->end);
|
||||||
|
$this->assertEquals($this->getDefinitionLocation('TestClass::TEST_CLASS_CONST'), $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testDefinitionForClassConstantsOnSelf()
|
||||||
|
{
|
||||||
|
// echo self::TEST_CLASS_CONST;
|
||||||
|
// Get definition for TEST_CLASS_CONST
|
||||||
$reference = $this->getReferenceLocations('TestClass::TEST_CLASS_CONST')[0];
|
$reference = $this->getReferenceLocations('TestClass::TEST_CLASS_CONST')[0];
|
||||||
$result = $this->textDocument->definition(new TextDocumentIdentifier($reference->uri), $reference->range->end);
|
$result = $this->textDocument->definition(new TextDocumentIdentifier($reference->uri), $reference->range->end);
|
||||||
$this->assertEquals($this->getDefinitionLocation('TestClass::TEST_CLASS_CONST'), $result);
|
$this->assertEquals($this->getDefinitionLocation('TestClass::TEST_CLASS_CONST'), $result);
|
||||||
|
|
Loading…
Reference in New Issue