2016-08-22 20:40:16 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace LanguageServer\Protocol;
|
|
|
|
|
2017-03-05 04:56:01 +00:00
|
|
|
use Microsoft\PhpParser as Tolerant;
|
2016-10-09 12:34:30 +00:00
|
|
|
|
2016-08-22 20:40:16 +00:00
|
|
|
/**
|
|
|
|
* Represents a location inside a resource, such as a line inside a text file.
|
|
|
|
*/
|
|
|
|
class Location
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
public $uri;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var Range
|
|
|
|
*/
|
|
|
|
public $range;
|
2016-08-25 13:27:14 +00:00
|
|
|
|
2016-10-09 12:34:30 +00:00
|
|
|
/**
|
|
|
|
* Returns the location of the node
|
|
|
|
*
|
2017-03-05 04:56:01 +00:00
|
|
|
* @param Node | Tolerant\Node $node
|
2016-10-09 12:34:30 +00:00
|
|
|
* @return self
|
|
|
|
*/
|
2017-03-05 04:56:01 +00:00
|
|
|
public static function fromNode($node)
|
2016-10-09 12:34:30 +00:00
|
|
|
{
|
2017-03-05 04:56:01 +00:00
|
|
|
if ($node instanceof Node) {
|
|
|
|
return new self($node->getAttribute('ownerDocument')->getUri(), Range::fromNode($node));
|
|
|
|
} else {
|
|
|
|
$range = Tolerant\PositionUtilities::getRangeFromPosition($node->getStart(), $node->getWidth(), $node->getFileContents());
|
|
|
|
return new self($node->getUri(), new Range(
|
|
|
|
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(string $uri = null, Range $range = null)
|
|
|
|
{
|
|
|
|
$this->uri = $uri;
|
|
|
|
$this->range = $range;
|
|
|
|
}
|
2016-08-22 20:40:16 +00:00
|
|
|
}
|