diff --git a/src/CompletionProvider.php b/src/CompletionProvider.php index e355ea2..2b08496 100644 --- a/src/CompletionProvider.php +++ b/src/CompletionProvider.php @@ -158,7 +158,6 @@ class CompletionProvider $node->parent->memberName === $node) ) { // Find variables, parameters and use statements in the scope - // If there was only a $ typed, $node will be instanceof Node\Error $namePrefix = $node->getName() ?? ''; foreach ($this->suggestVariablesAtNode($node, $namePrefix) as $var) { $item = new CompletionItem; @@ -334,9 +333,9 @@ class CompletionProvider * and at each level walk all previous siblings and their children to search for definitions * of that variable * - * @param Node $node + * @param Tolerant\Node $node * @param string $namePrefix Prefix to filter - * @return array + * @return array */ private function suggestVariablesAtNode(Tolerant\Node $node, string $namePrefix = ''): array { @@ -394,7 +393,7 @@ class CompletionProvider * * @param Node $node * @param string $namePrefix Prefix to filter - * @return Node\Expr\Variable[] + * @return Tolerant\Node\Expression\Variable[] */ private function findVariableDefinitionsInNode(Tolerant\Node $node, string $namePrefix = ''): array { diff --git a/src/DefinitionResolver.php b/src/DefinitionResolver.php index e4b0021..8cec289 100644 --- a/src/DefinitionResolver.php +++ b/src/DefinitionResolver.php @@ -472,8 +472,8 @@ class DefinitionResolver /** * Returns the assignment or parameter node where a variable was defined * - * @param Node\Expr\Variable|Node\Expr\ClosureUse $var The variable access - * @return Node\Expr\Assign|Node\Expr\AssignOp|Node\Param|Node\Expr\ClosureUse|null + * @param Tolerant\Node\Expression\Variable | Tolerant\Node\Expression\ClosureUse $var The variable access + * @return Tolerant\Node\Expression\Assign | Tolerant\Node\Expression\AssignOp|Node\Param | Tolerant\Node\Expression\ClosureUse|null */ public function resolveVariableToNode($var) { diff --git a/src/FqnUtilities.php b/src/FqnUtilities.php index 74e809b..a569d9b 100644 --- a/src/FqnUtilities.php +++ b/src/FqnUtilities.php @@ -7,24 +7,6 @@ use Microsoft\PhpParser as Tolerant; class FqnUtilities { - /** - * Returns the fully qualified name (FQN) that is defined by a node - * Returns null if the node does not declare any symbol that can be referenced by an FQN - * - * @param Node | Tolerant\Node $node - * @return string|null - */ - public static function getDefinedFqn($node) - { - if ($node instanceof Node) { - return DefinitionResolver::getDefinedFqn($node); - } elseif ($node instanceof Tolerant\Node) { - return DefinitionResolver::getDefinedFqn($node); - } - - throw new \TypeError("Unspported Node class"); - } - /** * Returns all possible FQNs in a type * diff --git a/src/Protocol/Location.php b/src/Protocol/Location.php index b838102..0de3c38 100644 --- a/src/Protocol/Location.php +++ b/src/Protocol/Location.php @@ -22,20 +22,16 @@ class Location /** * Returns the location of the node * - * @param Node | Tolerant\Node $node + * @param Tolerant\Node $node * @return self */ public static function fromNode($node) { - if ($node instanceof Node) { - return new self($node->getAttribute('ownerDocument')->getUri(), Range::fromNode($node)); - } else { - $range = Tolerant\PositionUtilities::getRangeFromPosition($node->getStart(), $node->getWidth(), $node->getFileContents()); - return new self($node->getUri(), new Range( - new Position($range->start->line, $range->start->character), - new Position($range->end->line, $range->end->character) - )); - } + $range = Tolerant\PositionUtilities::getRangeFromPosition($node->getStart(), $node->getWidth(), $node->getFileContents()); + return new self($node->getUri(), new Range( + new Position($range->start->line, $range->start->character), + new Position($range->end->line, $range->end->character) + )); } public function __construct(string $uri = null, Range $range = null) diff --git a/src/Server/TextDocument.php b/src/Server/TextDocument.php index 7a2b062..97a1781 100644 --- a/src/Server/TextDocument.php +++ b/src/Server/TextDocument.php @@ -208,7 +208,7 @@ class TextDocument } } else { // Definition with a global FQN - $fqn = FqnUtilities::getDefinedFqn($node); + $fqn = DefinitionResolver::getDefinedFqn($node); // var_dump($fqn); // Wait until indexing finished if (!$this->index->isComplete()) { @@ -255,7 +255,7 @@ class TextDocument return []; } // Handle definition nodes - $fqn = FqnUtilities::getDefinedFqn($node); + $fqn = DefinitionResolver::getDefinedFqn($node); while (true) { if ($fqn) { $def = $this->index->getDefinition($fqn); @@ -296,7 +296,7 @@ class TextDocument if ($node === null) { return new Hover([]); } - $definedFqn = FqnUtilities::getDefinedFqn($node); + $definedFqn = DefinitionResolver::getDefinedFqn($node); while (true) { if ($definedFqn) { // Support hover for definitions diff --git a/src/utils.php b/src/utils.php index 4018455..ec69a5b 100644 --- a/src/utils.php +++ b/src/utils.php @@ -93,23 +93,6 @@ function waitForEvent(EmitterInterface $emitter, string $event): Promise return $p; } -/** - * Returns the closest node of a specific type - * - * @param Node $node - * @param string $type The node class name - * @return Node|null $type - */ -function getClosestNode(Node $node, string $type) -{ - $n = $node; - while ($n = $n->getAttribute('parentNode')) { - if ($n instanceof $type) { - return $n; - } - } -} - /** * Returns the part of $b that is not overlapped by $a * Example: diff --git a/tests/PhpDocumentTest.php b/tests/PhpDocumentTest.php index eedc32b..926cb9d 100644 --- a/tests/PhpDocumentTest.php +++ b/tests/PhpDocumentTest.php @@ -44,11 +44,7 @@ class PhpDocumentTest extends TestCase } private function assertQualifiedName($node) { - if ($node instanceof Node) { - $this->assertInstanceOf(Node\Name\FullyQualified::class, $node); - } else { - $this->assertInstanceOf(Tolerant\Node\QualifiedName::class, $node); - } + $this->assertInstanceOf(Tolerant\Node\QualifiedName::class, $node); } public function testIsVendored()