1
0
Fork 0

Abort traversal in NodeAtPositionFinder (#305)

pull/324/head
Matthew Brown 2017-02-17 18:28:10 -05:00 committed by Felix Becker
parent 5d2ab8f369
commit cbfd70d398
1 changed files with 8 additions and 5 deletions

View File

@ -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)
{ {
$range = Range::fromNode($node); if ($this->node === null) {
if (!isset($this->node) && $range->includes($this->position)) { $range = Range::fromNode($node);
$this->node = $node; if ($range->includes($this->position)) {
$this->node = $node;
return NodeTraverser::STOP_TRAVERSAL;
}
} }
} }
} }