Remove remaining 'use PhpParser\' statements and some dead code
parent
71d71a896c
commit
442fc7ea02
|
@ -1,25 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace LanguageServer;
|
|
||||||
|
|
||||||
use PhpParser;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Custom PHP Parser class configured for our needs
|
|
||||||
*/
|
|
||||||
class Parser extends PhpParser\Parser\Php7
|
|
||||||
{
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$lexer = new PhpParser\Lexer([
|
|
||||||
'usedAttributes' => [
|
|
||||||
'comments',
|
|
||||||
'startLine',
|
|
||||||
'endLine',
|
|
||||||
'startFilePos',
|
|
||||||
'endFilePos'
|
|
||||||
]
|
|
||||||
]);
|
|
||||||
parent::__construct($lexer);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -15,7 +15,7 @@ class PhpDocument
|
||||||
/**
|
/**
|
||||||
* The PHPParser instance
|
* The PHPParser instance
|
||||||
*
|
*
|
||||||
* @var Parser
|
* @var Tolerant\Parser
|
||||||
*/
|
*/
|
||||||
private $parser;
|
private $parser;
|
||||||
|
|
||||||
|
@ -91,7 +91,7 @@ class PhpDocument
|
||||||
* @param string $uri The URI of the document
|
* @param string $uri The URI of the document
|
||||||
* @param string $content The content of the document
|
* @param string $content The content of the document
|
||||||
* @param Index $index The Index to register definitions and references to
|
* @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 DocBlockFactory $docBlockFactory The DocBlockFactory instance to parse docblocks
|
||||||
* @param DefinitionResolver $definitionResolver The DefinitionResolver to resolve definitions to symbols in the workspace
|
* @param DefinitionResolver $definitionResolver The DefinitionResolver to resolve definitions to symbols in the workspace
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -2,8 +2,6 @@
|
||||||
|
|
||||||
namespace LanguageServer\Protocol;
|
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
|
* Represents a diagnostic, such as a compiler error or warning. Diagnostic objects are only valid in the scope of a
|
||||||
* resource.
|
* resource.
|
||||||
|
@ -47,26 +45,6 @@ class Diagnostic
|
||||||
*/
|
*/
|
||||||
public $message;
|
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 string $message The diagnostic's message
|
||||||
* @param Range $range The range at which the message applies
|
* @param Range $range The range at which the message applies
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
namespace LanguageServer\Protocol;
|
namespace LanguageServer\Protocol;
|
||||||
|
|
||||||
use PhpParser\{Error, Node};
|
|
||||||
use Microsoft\PhpParser as Tolerant;
|
use Microsoft\PhpParser as Tolerant;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -27,40 +26,17 @@ class Range
|
||||||
/**
|
/**
|
||||||
* Returns the range the node spans
|
* Returns the range the node spans
|
||||||
*
|
*
|
||||||
* @param Node | Tolerant\Node $node
|
* @param Tolerant\Node $node
|
||||||
* @return self
|
* @return self
|
||||||
*/
|
*/
|
||||||
public static function fromNode($node)
|
public static function fromNode($node)
|
||||||
{
|
{
|
||||||
if ($node instanceof Node) {
|
$range = Tolerant\PositionUtilities::getRangeFromPosition($node->getStart(), $node->getWidth(), $node->getFileContents());
|
||||||
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());
|
|
||||||
|
|
||||||
return new self(
|
return new self(
|
||||||
new Position($range->start->line, $range->start->character),
|
new Position($range->start->line, $range->start->character),
|
||||||
new Position($range->end->line, $range->end->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));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __construct(Position $start = null, Position $end = null)
|
public function __construct(Position $start = null, Position $end = null)
|
||||||
|
|
|
@ -5,8 +5,6 @@ namespace LanguageServer;
|
||||||
|
|
||||||
use LanguageServer\Protocol\{Diagnostic, DiagnosticSeverity, Range, Position, TextEdit};
|
use LanguageServer\Protocol\{Diagnostic, DiagnosticSeverity, Range, Position, TextEdit};
|
||||||
use LanguageServer\Index\Index;
|
use LanguageServer\Index\Index;
|
||||||
use PhpParser\{Error, ErrorHandler, Node, NodeTraverser, Parser};
|
|
||||||
use PhpParser\NodeVisitor\NameResolver;
|
|
||||||
use phpDocumentor\Reflection\DocBlockFactory;
|
use phpDocumentor\Reflection\DocBlockFactory;
|
||||||
use Sabre\Uri;
|
use Sabre\Uri;
|
||||||
use Microsoft\PhpParser as Tolerant;
|
use Microsoft\PhpParser as Tolerant;
|
||||||
|
|
|
@ -4,7 +4,6 @@ declare(strict_types = 1);
|
||||||
namespace LanguageServer\Tests\Server\TextDocument;
|
namespace LanguageServer\Tests\Server\TextDocument;
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use PhpParser\{Node};
|
|
||||||
use phpDocumentor\Reflection\DocBlockFactory;
|
use phpDocumentor\Reflection\DocBlockFactory;
|
||||||
use LanguageServer\{
|
use LanguageServer\{
|
||||||
DefinitionResolver, TreeAnalyzer
|
DefinitionResolver, TreeAnalyzer
|
||||||
|
@ -62,9 +61,8 @@ class DefinitionCollectorTest extends TestCase
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $path
|
* @param $path
|
||||||
* @return Node
|
|
||||||
*/
|
*/
|
||||||
private function collectDefinitions($path):array
|
private function collectDefinitions($path): array
|
||||||
{
|
{
|
||||||
$uri = pathToUri($path);
|
$uri = pathToUri($path);
|
||||||
$parser = new Tolerant\Parser();
|
$parser = new Tolerant\Parser();
|
||||||
|
|
Loading…
Reference in New Issue