Skip to content

Commit cbfd70d

Browse files
muglugfelixfbecker
authored andcommitted
Abort traversal in NodeAtPositionFinder (#305)
1 parent 5d2ab8f commit cbfd70d

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/NodeVisitor/NodeAtPositionFinder.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace LanguageServer\NodeVisitor;
55

6-
use PhpParser\{NodeVisitorAbstract, Node};
6+
use PhpParser\{NodeVisitorAbstract, Node, NodeTraverser};
77
use LanguageServer\Protocol\{Position, Range};
88

99
/**
@@ -15,7 +15,7 @@ class NodeAtPositionFinder extends NodeVisitorAbstract
1515
/**
1616
* The node at the position, if found
1717
*
18-
* @var Node
18+
* @var Node|null
1919
*/
2020
public $node;
2121

@@ -34,9 +34,12 @@ public function __construct(Position $position)
3434

3535
public function leaveNode(Node $node)
3636
{
37-
$range = Range::fromNode($node);
38-
if (!isset($this->node) && $range->includes($this->position)) {
39-
$this->node = $node;
37+
if ($this->node === null) {
38+
$range = Range::fromNode($node);
39+
if ($range->includes($this->position)) {
40+
$this->node = $node;
41+
return NodeTraverser::STOP_TRAVERSAL;
42+
}
4043
}
4144
}
4245
}

0 commit comments

Comments
 (0)