Abort traversal in NodeAtPositionFinder (#305)
parent
5d2ab8f369
commit
cbfd70d398
|
@ -3,7 +3,7 @@ declare(strict_types = 1);
|
||||||
|
|
||||||
namespace LanguageServer\NodeVisitor;
|
namespace LanguageServer\NodeVisitor;
|
||||||
|
|
||||||
use PhpParser\{NodeVisitorAbstract, Node};
|
use PhpParser\{NodeVisitorAbstract, Node, NodeTraverser};
|
||||||
use LanguageServer\Protocol\{Position, Range};
|
use LanguageServer\Protocol\{Position, Range};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -15,7 +15,7 @@ class NodeAtPositionFinder extends NodeVisitorAbstract
|
||||||
/**
|
/**
|
||||||
* The node at the position, if found
|
* The node at the position, if found
|
||||||
*
|
*
|
||||||
* @var Node
|
* @var Node|null
|
||||||
*/
|
*/
|
||||||
public $node;
|
public $node;
|
||||||
|
|
||||||
|
@ -34,9 +34,12 @@ class NodeAtPositionFinder extends NodeVisitorAbstract
|
||||||
|
|
||||||
public function leaveNode(Node $node)
|
public function leaveNode(Node $node)
|
||||||
{
|
{
|
||||||
|
if ($this->node === null) {
|
||||||
$range = Range::fromNode($node);
|
$range = Range::fromNode($node);
|
||||||
if (!isset($this->node) && $range->includes($this->position)) {
|
if ($range->includes($this->position)) {
|
||||||
$this->node = $node;
|
$this->node = $node;
|
||||||
|
return NodeTraverser::STOP_TRAVERSAL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue