1
0
Fork 0

implement rename of class member fields

pull/768/head
Florian Schunk 2019-11-01 20:28:13 +01:00
parent 207c6a2a68
commit 1f157d7424
1 changed files with 31 additions and 10 deletions

View File

@ -192,7 +192,7 @@ class TextDocument
// by traversing the AST
if (
($node instanceof Node\Expression\Variable && !($node->getParent()->getParent() instanceof Node\PropertyDeclaration))
($node instanceof Node\Expression\Variable && !($node->getParent()->getParent() instanceof Node\PropertyDeclaration) && !($node->getParent()->getParent()->getParent() instanceof Node\PropertyDeclaration))
|| $node instanceof Node\Parameter
|| $node instanceof Node\UseVariableName
) {
@ -212,10 +212,14 @@ class TextDocument
if ($descendantNode instanceof Node\Expression\Variable &&
$descendantNode->getName() === $node->getName()
) {
$locations[] = LocationFactory::fromNode($descendantNode);
$location = LocationFactory::fromNode($descendantNode);
$location->range->start->character++;
$locations[] = $location;
} else if (($descendantNode instanceof Node\Parameter)
&& $context->includeDeclaration && $descendantNode->getName() === $node->getName() ) {
$locations[] = LocationFactory::fromToken($descendantNode, $descendantNode->variableName);
$location = LocationFactory::fromToken($descendantNode, $descendantNode->variableName);
$location->range->start->character++;
$locations[] = $location;
}
}
} else {
@ -241,10 +245,33 @@ class TextDocument
$refs = $document->getReferenceNodesByFqn($fqn);
if ($refs !== null) {
foreach ($refs as $ref) {
if ($ref instanceof Node\Expression\MemberAccessExpression) {
$locations[] = LocationFactory::fromToken($ref, $ref -> memberName);
} else {
$locations[] = LocationFactory::fromNode($ref);
}
}
}
if ($context->includeDeclaration) {
$refs = $document->getDefinitionNodeByFqn($fqn);
if ($refs !== null){
foreach ($refs as $ref) {
if ($ref !== null){
if ($ref instanceof Node\Expression\AssignmentExpression) {
$location = LocationFactory::fromNode($ref->leftOperand);
$location->range->start->character++;
$locations[] = $location;
}elseif ($ref instanceof Node\DelimitedList\ExpressionList) {
$location = LocationFactory::fromNode($ref);
$location->range->start->character++;
$locations[] = $location;
}
}
}
}
}
}
}
return $locations;
});
@ -266,12 +293,6 @@ class TextDocument
return coroutine( function () use ($textDocument, $position, $newName) {
$document = yield $this->documentLoader->getOrLoad($textDocument->uri);
$node = $document->getNodeAtPosition($position);
if (
$node instanceof Node\Expression\Variable ||
$node instanceof Node\Parameter
) {
$newName = '$' . $newName;
}
$locations = yield $this->references(new ReferenceContext(true), $textDocument, $position);
$edits = [$textDocument->uri => [] ];
foreach ($locations as $location) {