From cbfd70d398d1fb3d90e81812ab4953b61aca874f Mon Sep 17 00:00:00 2001 From: Matthew Brown Date: Fri, 17 Feb 2017 18:28:10 -0500 Subject: [PATCH] Abort traversal in NodeAtPositionFinder (#305) --- src/NodeVisitor/NodeAtPositionFinder.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/NodeVisitor/NodeAtPositionFinder.php b/src/NodeVisitor/NodeAtPositionFinder.php index 521d940..cb17801 100644 --- a/src/NodeVisitor/NodeAtPositionFinder.php +++ b/src/NodeVisitor/NodeAtPositionFinder.php @@ -3,7 +3,7 @@ declare(strict_types = 1); namespace LanguageServer\NodeVisitor; -use PhpParser\{NodeVisitorAbstract, Node}; +use PhpParser\{NodeVisitorAbstract, Node, NodeTraverser}; use LanguageServer\Protocol\{Position, Range}; /** @@ -15,7 +15,7 @@ class NodeAtPositionFinder extends NodeVisitorAbstract /** * The node at the position, if found * - * @var Node + * @var Node|null */ public $node; @@ -34,9 +34,12 @@ class NodeAtPositionFinder extends NodeVisitorAbstract public function leaveNode(Node $node) { - $range = Range::fromNode($node); - if (!isset($this->node) && $range->includes($this->position)) { - $this->node = $node; + if ($this->node === null) { + $range = Range::fromNode($node); + if ($range->includes($this->position)) { + $this->node = $node; + return NodeTraverser::STOP_TRAVERSAL; + } } } }