Remove more PhpParser\Node references
parent
442fc7ea02
commit
b4e77f2e9c
|
@ -158,7 +158,6 @@ class CompletionProvider
|
||||||
$node->parent->memberName === $node)
|
$node->parent->memberName === $node)
|
||||||
) {
|
) {
|
||||||
// Find variables, parameters and use statements in the scope
|
// Find variables, parameters and use statements in the scope
|
||||||
// If there was only a $ typed, $node will be instanceof Node\Error
|
|
||||||
$namePrefix = $node->getName() ?? '';
|
$namePrefix = $node->getName() ?? '';
|
||||||
foreach ($this->suggestVariablesAtNode($node, $namePrefix) as $var) {
|
foreach ($this->suggestVariablesAtNode($node, $namePrefix) as $var) {
|
||||||
$item = new CompletionItem;
|
$item = new CompletionItem;
|
||||||
|
@ -334,9 +333,9 @@ class CompletionProvider
|
||||||
* and at each level walk all previous siblings and their children to search for definitions
|
* and at each level walk all previous siblings and their children to search for definitions
|
||||||
* of that variable
|
* of that variable
|
||||||
*
|
*
|
||||||
* @param Node $node
|
* @param Tolerant\Node $node
|
||||||
* @param string $namePrefix Prefix to filter
|
* @param string $namePrefix Prefix to filter
|
||||||
* @return array <Node\Expr\Variable|Node\Param|Node\Expr\ClosureUse>
|
* @return array <Tolerant\Node\Expr\Variable|Tolerant\Node\Param|Tolerant\Node\Expr\ClosureUse>
|
||||||
*/
|
*/
|
||||||
private function suggestVariablesAtNode(Tolerant\Node $node, string $namePrefix = ''): array
|
private function suggestVariablesAtNode(Tolerant\Node $node, string $namePrefix = ''): array
|
||||||
{
|
{
|
||||||
|
@ -394,7 +393,7 @@ class CompletionProvider
|
||||||
*
|
*
|
||||||
* @param Node $node
|
* @param Node $node
|
||||||
* @param string $namePrefix Prefix to filter
|
* @param string $namePrefix Prefix to filter
|
||||||
* @return Node\Expr\Variable[]
|
* @return Tolerant\Node\Expression\Variable[]
|
||||||
*/
|
*/
|
||||||
private function findVariableDefinitionsInNode(Tolerant\Node $node, string $namePrefix = ''): array
|
private function findVariableDefinitionsInNode(Tolerant\Node $node, string $namePrefix = ''): array
|
||||||
{
|
{
|
||||||
|
|
|
@ -472,8 +472,8 @@ class DefinitionResolver
|
||||||
/**
|
/**
|
||||||
* Returns the assignment or parameter node where a variable was defined
|
* Returns the assignment or parameter node where a variable was defined
|
||||||
*
|
*
|
||||||
* @param Node\Expr\Variable|Node\Expr\ClosureUse $var The variable access
|
* @param Tolerant\Node\Expression\Variable | Tolerant\Node\Expression\ClosureUse $var The variable access
|
||||||
* @return Node\Expr\Assign|Node\Expr\AssignOp|Node\Param|Node\Expr\ClosureUse|null
|
* @return Tolerant\Node\Expression\Assign | Tolerant\Node\Expression\AssignOp|Node\Param | Tolerant\Node\Expression\ClosureUse|null
|
||||||
*/
|
*/
|
||||||
public function resolveVariableToNode($var)
|
public function resolveVariableToNode($var)
|
||||||
{
|
{
|
||||||
|
|
|
@ -7,24 +7,6 @@ use Microsoft\PhpParser as Tolerant;
|
||||||
|
|
||||||
class FqnUtilities
|
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
|
* Returns all possible FQNs in a type
|
||||||
*
|
*
|
||||||
|
|
|
@ -22,20 +22,16 @@ class Location
|
||||||
/**
|
/**
|
||||||
* Returns the location of the node
|
* Returns the location of the node
|
||||||
*
|
*
|
||||||
* @param Node | Tolerant\Node $node
|
* @param Tolerant\Node $node
|
||||||
* @return self
|
* @return self
|
||||||
*/
|
*/
|
||||||
public static function fromNode($node)
|
public static function fromNode($node)
|
||||||
{
|
{
|
||||||
if ($node instanceof Node) {
|
$range = Tolerant\PositionUtilities::getRangeFromPosition($node->getStart(), $node->getWidth(), $node->getFileContents());
|
||||||
return new self($node->getAttribute('ownerDocument')->getUri(), Range::fromNode($node));
|
return new self($node->getUri(), new Range(
|
||||||
} else {
|
new Position($range->start->line, $range->start->character),
|
||||||
$range = Tolerant\PositionUtilities::getRangeFromPosition($node->getStart(), $node->getWidth(), $node->getFileContents());
|
new Position($range->end->line, $range->end->character)
|
||||||
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)
|
public function __construct(string $uri = null, Range $range = null)
|
||||||
|
|
|
@ -208,7 +208,7 @@ class TextDocument
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Definition with a global FQN
|
// Definition with a global FQN
|
||||||
$fqn = FqnUtilities::getDefinedFqn($node);
|
$fqn = DefinitionResolver::getDefinedFqn($node);
|
||||||
// var_dump($fqn);
|
// var_dump($fqn);
|
||||||
// Wait until indexing finished
|
// Wait until indexing finished
|
||||||
if (!$this->index->isComplete()) {
|
if (!$this->index->isComplete()) {
|
||||||
|
@ -255,7 +255,7 @@ class TextDocument
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
// Handle definition nodes
|
// Handle definition nodes
|
||||||
$fqn = FqnUtilities::getDefinedFqn($node);
|
$fqn = DefinitionResolver::getDefinedFqn($node);
|
||||||
while (true) {
|
while (true) {
|
||||||
if ($fqn) {
|
if ($fqn) {
|
||||||
$def = $this->index->getDefinition($fqn);
|
$def = $this->index->getDefinition($fqn);
|
||||||
|
@ -296,7 +296,7 @@ class TextDocument
|
||||||
if ($node === null) {
|
if ($node === null) {
|
||||||
return new Hover([]);
|
return new Hover([]);
|
||||||
}
|
}
|
||||||
$definedFqn = FqnUtilities::getDefinedFqn($node);
|
$definedFqn = DefinitionResolver::getDefinedFqn($node);
|
||||||
while (true) {
|
while (true) {
|
||||||
if ($definedFqn) {
|
if ($definedFqn) {
|
||||||
// Support hover for definitions
|
// Support hover for definitions
|
||||||
|
|
|
@ -93,23 +93,6 @@ function waitForEvent(EmitterInterface $emitter, string $event): Promise
|
||||||
return $p;
|
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
|
* Returns the part of $b that is not overlapped by $a
|
||||||
* Example:
|
* Example:
|
||||||
|
|
|
@ -44,11 +44,7 @@ class PhpDocumentTest extends TestCase
|
||||||
}
|
}
|
||||||
|
|
||||||
private function assertQualifiedName($node) {
|
private function assertQualifiedName($node) {
|
||||||
if ($node instanceof Node) {
|
$this->assertInstanceOf(Tolerant\Node\QualifiedName::class, $node);
|
||||||
$this->assertInstanceOf(Node\Name\FullyQualified::class, $node);
|
|
||||||
} else {
|
|
||||||
$this->assertInstanceOf(Tolerant\Node\QualifiedName::class, $node);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testIsVendored()
|
public function testIsVendored()
|
||||||
|
|
Loading…
Reference in New Issue