diff --git a/src/Parser.php b/src/Parser.php deleted file mode 100644 index d6d6d13..0000000 --- a/src/Parser.php +++ /dev/null @@ -1,25 +0,0 @@ - [ - 'comments', - 'startLine', - 'endLine', - 'startFilePos', - 'endFilePos' - ] - ]); - parent::__construct($lexer); - } -} diff --git a/src/PhpDocument.php b/src/PhpDocument.php index b755dea..77c9aac 100644 --- a/src/PhpDocument.php +++ b/src/PhpDocument.php @@ -15,7 +15,7 @@ class PhpDocument /** * The PHPParser instance * - * @var Parser + * @var Tolerant\Parser */ private $parser; @@ -91,7 +91,7 @@ class PhpDocument * @param string $uri The URI of the document * @param string $content The content of the document * @param Index $index The Index to register definitions and references to - * @param Parser $parser The PHPParser instance + * @param Tolerant\Parser $parser The PhpParser instance * @param DocBlockFactory $docBlockFactory The DocBlockFactory instance to parse docblocks * @param DefinitionResolver $definitionResolver The DefinitionResolver to resolve definitions to symbols in the workspace */ diff --git a/src/Protocol/Diagnostic.php b/src/Protocol/Diagnostic.php index 44a24c1..7bf9895 100644 --- a/src/Protocol/Diagnostic.php +++ b/src/Protocol/Diagnostic.php @@ -2,8 +2,6 @@ namespace LanguageServer\Protocol; -use PhpParser\Error; - /** * Represents a diagnostic, such as a compiler error or warning. Diagnostic objects are only valid in the scope of a * resource. @@ -47,26 +45,6 @@ class Diagnostic */ public $message; - /** - * Creates a diagnostic from a PhpParser Error - * - * @param Error $error Message and code will be used - * @param string $content The file content to calculate the column info - * @param int $severity DiagnosticSeverity - * @param string $source A human-readable string describing the source of this diagnostic - * @return self - */ - public static function fromError(Error $error, string $content, int $severity = null, string $source = null): self - { - return new self( - $error->getRawMessage(), // Do not include "on line ..." in the error message - Range::fromError($error, $content), - $error->getCode(), - $severity, - $source - ); - } - /** * @param string $message The diagnostic's message * @param Range $range The range at which the message applies diff --git a/src/Protocol/Range.php b/src/Protocol/Range.php index 908dd67..de2011b 100644 --- a/src/Protocol/Range.php +++ b/src/Protocol/Range.php @@ -2,7 +2,6 @@ namespace LanguageServer\Protocol; -use PhpParser\{Error, Node}; use Microsoft\PhpParser as Tolerant; /** @@ -27,40 +26,17 @@ class Range /** * Returns the range the node spans * - * @param Node | Tolerant\Node $node + * @param Tolerant\Node $node * @return self */ public static function fromNode($node) { - if ($node instanceof Node) { - return new self( - new Position($node->getAttribute('startLine') - 1, $node->getAttribute('startColumn') - 1), - new Position($node->getAttribute('endLine') - 1, $node->getAttribute('endColumn')) - ); - } else { - $range = Tolerant\PositionUtilities::getRangeFromPosition($node->getStart(), $node->getWidth(), $node->getFileContents()); + $range = Tolerant\PositionUtilities::getRangeFromPosition($node->getStart(), $node->getWidth(), $node->getFileContents()); - return new self( - new Position($range->start->line, $range->start->character), - new Position($range->end->line, $range->end->character) - ); - } - } - - /** - * Returns the range where an error occured - * - * @param \PhpParser\Error $error - * @param string $content - * @return self - */ - public static function fromError(Error $error, string $content) - { - $startLine = max($error->getStartLine() - 1, 0); - $endLine = max($error->getEndLine() - 1, $startLine); - $startColumn = $error->hasColumnInfo() ? $error->getStartColumn($content) - 1 : 0; - $endColumn = $error->hasColumnInfo() ? $error->getEndColumn($content) : 0; - return new self(new Position($startLine, $startColumn), new Position($endLine, $endColumn)); + return new self( + new Position($range->start->line, $range->start->character), + new Position($range->end->line, $range->end->character) + ); } public function __construct(Position $start = null, Position $end = null) diff --git a/src/TreeAnalyzer.php b/src/TreeAnalyzer.php index f5cfbaf..e4cd788 100644 --- a/src/TreeAnalyzer.php +++ b/src/TreeAnalyzer.php @@ -5,8 +5,6 @@ namespace LanguageServer; use LanguageServer\Protocol\{Diagnostic, DiagnosticSeverity, Range, Position, TextEdit}; use LanguageServer\Index\Index; -use PhpParser\{Error, ErrorHandler, Node, NodeTraverser, Parser}; -use PhpParser\NodeVisitor\NameResolver; use phpDocumentor\Reflection\DocBlockFactory; use Sabre\Uri; use Microsoft\PhpParser as Tolerant; diff --git a/tests/NodeVisitor/DefinitionCollectorTest.php b/tests/NodeVisitor/DefinitionCollectorTest.php index 0b50781..8e8b9e1 100644 --- a/tests/NodeVisitor/DefinitionCollectorTest.php +++ b/tests/NodeVisitor/DefinitionCollectorTest.php @@ -4,7 +4,6 @@ declare(strict_types = 1); namespace LanguageServer\Tests\Server\TextDocument; use PHPUnit\Framework\TestCase; -use PhpParser\{Node}; use phpDocumentor\Reflection\DocBlockFactory; use LanguageServer\{ DefinitionResolver, TreeAnalyzer @@ -62,9 +61,8 @@ class DefinitionCollectorTest extends TestCase /** * @param $path - * @return Node */ - private function collectDefinitions($path):array + private function collectDefinitions($path): array { $uri = pathToUri($path); $parser = new Tolerant\Parser();