2016-08-22 20:40:16 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace LanguageServer\Protocol;
|
|
|
|
|
2017-06-09 18:25:30 +00:00
|
|
|
use Microsoft\PhpParser;
|
|
|
|
use Microsoft\PhpParser\Node;
|
2016-10-09 12:34:30 +00:00
|
|
|
|
2016-08-22 20:40:16 +00:00
|
|
|
/**
|
|
|
|
* A range in a text document expressed as (zero-based) start and end positions.
|
|
|
|
*/
|
|
|
|
class Range
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The range's start position.
|
|
|
|
*
|
|
|
|
* @var Position
|
|
|
|
*/
|
|
|
|
public $start;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The range's end position.
|
|
|
|
*
|
|
|
|
* @var Position
|
|
|
|
*/
|
|
|
|
public $end;
|
2016-08-25 13:27:14 +00:00
|
|
|
|
2016-10-09 12:34:30 +00:00
|
|
|
/**
|
|
|
|
* Returns the range the node spans
|
|
|
|
*
|
|
|
|
* @param Node $node
|
|
|
|
* @return self
|
|
|
|
*/
|
|
|
|
public static function fromNode(Node $node)
|
|
|
|
{
|
2017-06-09 18:25:30 +00:00
|
|
|
$range = PhpParser\PositionUtilities::getRangeFromPosition($node->getStart(), $node->getWidth(), $node->getFileContents());
|
|
|
|
|
2016-10-09 12:34:30 +00:00
|
|
|
return new self(
|
2017-06-09 18:25:30 +00:00
|
|
|
new Position($range->start->line, $range->start->character),
|
|
|
|
new Position($range->end->line, $range->end->character)
|
2016-10-09 12:34:30 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-08-25 13:27:14 +00:00
|
|
|
public function __construct(Position $start = null, Position $end = null)
|
|
|
|
{
|
|
|
|
$this->start = $start;
|
|
|
|
$this->end = $end;
|
|
|
|
}
|
2016-10-08 15:14:52 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if a position is within the range
|
|
|
|
*
|
|
|
|
* @param Position $position
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function includes(Position $position): bool
|
|
|
|
{
|
|
|
|
return $this->start->compare($position) <= 0 && $this->end->compare($position) >= 0;
|
|
|
|
}
|
2016-08-22 20:40:16 +00:00
|
|
|
}
|