1
0
Fork 0

fix scoped expression definition resolution

pull/357/head
Sara Itani 2017-03-06 11:01:10 -08:00
parent c18bec0d50
commit 1316761e5e
2 changed files with 14 additions and 9 deletions

View File

@ -209,11 +209,8 @@ class TolerantDefinitionResolver implements DefinitionResolverInterface
public function resolveReferenceNodeToDefinition($node) public function resolveReferenceNodeToDefinition($node)
{ {
$parent = $node->getParent(); $parent = $node->getParent();
if ($parent instanceof Tolerant\Node\Expression\ScopedPropertyAccessExpression) {
$node = $parent;
}
// Variables are not indexed globally, as they stay in the file scope anyway // Variables are not indexed globally, as they stay in the file scope anyway
if ($node instanceof Tolerant\Node\Expression\Variable) { if ($node instanceof Tolerant\Node\Expression\Variable && !($parent instanceof Tolerant\Node\Expression\ScopedPropertyAccessExpression)) {
// Resolve $this // Resolve $this
if ($node->getName() === 'this' && $fqn = $this->getContainingClassFqn($node)) { if ($node->getName() === 'this' && $fqn = $this->getContainingClassFqn($node)) {
return $this->index->getDefinition($fqn, false); return $this->index->getDefinition($fqn, false);
@ -374,14 +371,15 @@ class TolerantDefinitionResolver implements DefinitionResolverInterface
$name = (string)($node->getNamespacedName()); $name = (string)($node->getNamespacedName());
} }
else if ( else if (
($scoped = $node) instanceof Tolerant\Node\Expression\ScopedPropertyAccessExpression ($scoped = $node) instanceof Tolerant\Node\Expression\ScopedPropertyAccessExpression ||
|| ($node instanceof Tolerant\Node\Expression\CallExpression && ($scoped = $node->callableExpression) instanceof Tolerant\Node\Expression\ScopedPropertyAccessExpression) ($scoped = $node->parent) instanceof Tolerant\Node\Expression\ScopedPropertyAccessExpression
|| ($node->parent instanceof Tolerant\Node\Expression\CallExpression && ($scoped = $node->parent->callableExpression) instanceof Tolerant\Node\Expression\ScopedPropertyAccessExpression)
) { ) {
// if ($scoped->memberName instanceof Tolerant\Node\Expression) { // if ($scoped->memberName instanceof Tolerant\Node\Expression) {
// Cannot get definition of dynamic names // Cannot get definition of dynamic names
// return null; // return null;
// } // }
$className = (string)$scoped->scopeResolutionQualifier->getText(); $className = $scoped->scopeResolutionQualifier->getText();
if ($className === 'self' || $className === 'static' || $className === 'parent') { if ($className === 'self' || $className === 'static' || $className === 'parent') {
// self and static are resolved to the containing class // self and static are resolved to the containing class
$classNode = $node->getFirstAncestor(Tolerant\Node\Statement\ClassDeclaration::class); $classNode = $node->getFirstAncestor(Tolerant\Node\Statement\ClassDeclaration::class);
@ -393,16 +391,23 @@ class TolerantDefinitionResolver implements DefinitionResolverInterface
if (!isset($node->extends)) { if (!isset($node->extends)) {
return null; return null;
} }
$className = (string)$classNode->extends; $className = (string)$classNode->extends->getResolvedName();
} else { } else {
$className = (string)$classNode->getNamespacedName(); $className = (string)$classNode->getNamespacedName();
} }
} elseif ($scoped->scopeResolutionQualifier instanceof Tolerant\Node\QualifiedName) {
$className = $scoped->scopeResolutionQualifier->getResolvedName();
} }
if ($scoped->memberName instanceof Tolerant\Node\Expression\Variable) { if ($scoped->memberName instanceof Tolerant\Node\Expression\Variable) {
$name = (string)$className . '::$' . $scoped->memberName->getName(); $name = (string)$className . '::$' . $scoped->memberName->getName();
} else { } else {
$name = (string)$className . '::' . $scoped->memberName->getText($node->getFileContents()); $name = (string)$className . '::' . $scoped->memberName->getText($node->getFileContents());
} }
if ($scoped->parent instanceof Tolerant\Node\Expression\CallExpression) {
$name .= '()';
}
return $name;
} }
else { else {
return null; return null;

View File

@ -199,7 +199,7 @@ abstract class ServerTestCase extends TestCase
1 => new Location($globalReferencesUri, new Range(new Position(39, 0), new Position(39, 30))) // TestClass::$staticTestProperty[123]->testProperty; 1 => new Location($globalReferencesUri, new Range(new Position(39, 0), new Position(39, 30))) // TestClass::$staticTestProperty[123]->testProperty;
], ],
'TestClass::staticTestMethod()' => [ 'TestClass::staticTestMethod()' => [
0 => new Location($globalReferencesUri, new Range(new Position( 7, 0), new Position( 7, 29))) 0 => new Location($globalReferencesUri, new Range(new Position( 7, 0), new Position( 7, 27)))
], ],
'TestClass::testMethod()' => [ 'TestClass::testMethod()' => [
0 => new Location($globalReferencesUri, new Range(new Position( 5, 0), new Position( 5, 18))), // $obj->testMethod(); 0 => new Location($globalReferencesUri, new Range(new Position( 5, 0), new Position( 5, 18))), // $obj->testMethod();