1
0
Fork 0

Remove original DefinitionResolver, remove "Tolerant" on file names

pull/357/head
roblou 2017-05-19 13:39:16 -07:00
parent a9be548cb1
commit 5e9dfa104b
30 changed files with 994 additions and 2086 deletions

View File

@ -7,7 +7,7 @@ use Exception;
use LanguageServer\Index\Index; use LanguageServer\Index\Index;
use LanguageServer\ParserKind; use LanguageServer\ParserKind;
use LanguageServer\PhpDocument; use LanguageServer\PhpDocument;
use LanguageServer\TolerantDefinitionResolver; use LanguageServer\DefinitionResolver;
use Microsoft\PhpParser as Tolerant; use Microsoft\PhpParser as Tolerant;
use phpDocumentor\Reflection\DocBlockFactory; use phpDocumentor\Reflection\DocBlockFactory;
use RecursiveDirectoryIterator; use RecursiveDirectoryIterator;
@ -57,7 +57,7 @@ foreach($frameworks as $framework) {
$maxRecursion = []; $maxRecursion = [];
$definitions = []; $definitions = [];
$definitionResolver = new TolerantDefinitionResolver($index); $definitionResolver = new DefinitionResolver($index);
$parser = new Tolerant\Parser(); $parser = new Tolerant\Parser();
try { try {

View File

@ -90,7 +90,7 @@ class CompletionProvider
]; ];
/** /**
* @var TolerantDefinitionResolver * @var DefinitionResolver
*/ */
private $definitionResolver; private $definitionResolver;
@ -105,10 +105,10 @@ class CompletionProvider
private $index; private $index;
/** /**
* @param TolerantDefinitionResolver $definitionResolver * @param DefinitionResolver $definitionResolver
* @param ReadableIndex $index * @param ReadableIndex $index
*/ */
public function __construct(TolerantDefinitionResolver $definitionResolver, ReadableIndex $index) public function __construct(DefinitionResolver $definitionResolver, ReadableIndex $index)
{ {
$this->definitionResolver = $definitionResolver; $this->definitionResolver = $definitionResolver;
$this->index = $index; $this->index = $index;
@ -228,7 +228,7 @@ class CompletionProvider
} }
} }
} }
} elseif (TolerantParserHelpers::isConstantFetch($node) || } elseif (ParserHelpers::isConstantFetch($node) ||
($creation = $node->parent) instanceof Tolerant\Node\Expression\ObjectCreationExpression || ($creation = $node->parent) instanceof Tolerant\Node\Expression\ObjectCreationExpression ||
(($creation = $node) instanceof Tolerant\Node\Expression\ObjectCreationExpression)) { (($creation = $node) instanceof Tolerant\Node\Expression\ObjectCreationExpression)) {
@ -298,7 +298,7 @@ class CompletionProvider
$list->items[] = $item; $list->items[] = $item;
} }
} }
} elseif (TolerantParserHelpers::isConstantFetch($node)) { } elseif (ParserHelpers::isConstantFetch($node)) {
$prefix = (string) ($node->getResolvedName() ?? Tolerant\ResolvedName::buildName($node->nameParts, $node->getFileContents())); $prefix = (string) ($node->getResolvedName() ?? Tolerant\ResolvedName::buildName($node->nameParts, $node->getFileContents()));
foreach (self::KEYWORDS as $keyword) { foreach (self::KEYWORDS as $keyword) {
$item = new CompletionItem($keyword, CompletionItemKind::KEYWORD); $item = new CompletionItem($keyword, CompletionItemKind::KEYWORD);
@ -355,7 +355,7 @@ class CompletionProvider
// Walk the AST upwards until a scope boundary is met // Walk the AST upwards until a scope boundary is met
$level = $node; $level = $node;
while ($level && !TolerantParserHelpers::isFunctionLike($level)) { while ($level && !ParserHelpers::isFunctionLike($level)) {
// Walk siblings before the node // Walk siblings before the node
$sibling = $level; $sibling = $level;
while ($sibling = $sibling->getPreviousSibling()) { while ($sibling = $sibling->getPreviousSibling()) {
@ -369,7 +369,7 @@ class CompletionProvider
// If the traversal ended because a function was met, // If the traversal ended because a function was met,
// also add its parameters and closure uses to the result list // also add its parameters and closure uses to the result list
if ($level && TolerantParserHelpers::isFunctionLike($level) && $level->parameters !== null) { if ($level && ParserHelpers::isFunctionLike($level) && $level->parameters !== null) {
foreach ($level->parameters->getValues() as $param) { foreach ($level->parameters->getValues() as $param) {
$paramName = $param->getName(); $paramName = $param->getName();
if (empty($namePrefix) || strpos($paramName, $namePrefix) !== false) { if (empty($namePrefix) || strpos($paramName, $namePrefix) !== false) {
@ -409,7 +409,7 @@ class CompletionProvider
}; };
$isNotFunctionLike = function($node) { $isNotFunctionLike = function($node) {
return !( return !(
TolerantParserHelpers::isFunctionLike($node) || ParserHelpers::isFunctionLike($node) ||
$node instanceof Tolerant\Node\Statement\ClassDeclaration || $node instanceof Tolerant\Node\Statement\ClassDeclaration ||
$node instanceof Tolerant\Node\Statement\InterfaceDeclaration || $node instanceof Tolerant\Node\Statement\InterfaceDeclaration ||
$node instanceof Tolerant\Node\Statement\TraitDeclaration $node instanceof Tolerant\Node\Statement\TraitDeclaration

View File

@ -31,7 +31,7 @@ class ComposerScripts
$contentRetriever = new FileSystemContentRetriever; $contentRetriever = new FileSystemContentRetriever;
$docBlockFactory = DocBlockFactory::createInstance(); $docBlockFactory = DocBlockFactory::createInstance();
$parser = new Tolerant\Parser(); $parser = new Tolerant\Parser();
$definitionResolver = new TolerantDefinitionResolver($index); $definitionResolver = new DefinitionResolver($index);
$stubsLocation = null; $stubsLocation = null;
foreach ([__DIR__ . '/../../../jetbrains/phpstorm-stubs', __DIR__ . '/../vendor/jetbrains/phpstorm-stubs'] as $dir) { foreach ([__DIR__ . '/../../../jetbrains/phpstorm-stubs', __DIR__ . '/../vendor/jetbrains/phpstorm-stubs'] as $dir) {

File diff suppressed because it is too large Load Diff

View File

@ -20,7 +20,7 @@ class FqnUtilities
if ($node instanceof Node) { if ($node instanceof Node) {
return DefinitionResolver::getDefinedFqn($node); return DefinitionResolver::getDefinedFqn($node);
} elseif ($node instanceof Tolerant\Node) { } elseif ($node instanceof Tolerant\Node) {
return TolerantDefinitionResolver::getDefinedFqn($node); return DefinitionResolver::getDefinedFqn($node);
} }
throw new \TypeError("Unspported Node class"); throw new \TypeError("Unspported Node class");

View File

@ -101,7 +101,7 @@ class LanguageServer extends AdvancedJsonRpc\Dispatcher
protected $projectIndex; protected $projectIndex;
/** /**
* @var TolerantDefinitionResolver * @var DefinitionResolver
*/ */
protected $definitionResolver; protected $definitionResolver;
@ -187,7 +187,7 @@ class LanguageServer extends AdvancedJsonRpc\Dispatcher
$this->globalIndex = new GlobalIndex($stubsIndex, $this->projectIndex); $this->globalIndex = new GlobalIndex($stubsIndex, $this->projectIndex);
// The DefinitionResolver should look in stubs, the project source and dependencies // The DefinitionResolver should look in stubs, the project source and dependencies
$this->definitionResolver = new TolerantDefinitionResolver($this->globalIndex); $this->definitionResolver = new DefinitionResolver($this->globalIndex);
$this->documentLoader = new PhpDocumentLoader( $this->documentLoader = new PhpDocumentLoader(
$this->contentRetriever, $this->contentRetriever,

View File

@ -5,7 +5,7 @@ namespace LanguageServer\NodeVisitor;
use PhpParser\{NodeVisitorAbstract, Node}; use PhpParser\{NodeVisitorAbstract, Node};
use LanguageServer\{ use LanguageServer\{
Definition, FqnUtilities, TolerantDefinitionResolver Definition, FqnUtilities, DefinitionResolver
}; };
/** /**
@ -30,7 +30,7 @@ class DefinitionCollector extends NodeVisitorAbstract
private $definitionResolver; private $definitionResolver;
public function __construct(TolerantDefinitionResolver $definitionResolver) public function __construct(DefinitionResolver $definitionResolver)
{ {
$this->definitionResolver = $definitionResolver; $this->definitionResolver = $definitionResolver;
} }

View File

@ -22,14 +22,14 @@ class ReferencesCollector extends NodeVisitorAbstract
public $nodes = []; public $nodes = [];
/** /**
* @var TolerantDefinitionResolver * @var DefinitionResolver
*/ */
private $definitionResolver; private $definitionResolver;
/** /**
* @param TolerantDefinitionResolver $definitionResolver The definition resolver to resolve reference nodes to definitions * @param DefinitionResolver $definitionResolver The definition resolver to resolve reference nodes to definitions
*/ */
public function __construct(TolerantDefinitionResolver $definitionResolver) public function __construct(DefinitionResolver $definitionResolver)
{ {
$this->definitionResolver = $definitionResolver; $this->definitionResolver = $definitionResolver;
} }

View File

@ -5,7 +5,7 @@ namespace LanguageServer;
use Microsoft\PhpParser as Tolerant; use Microsoft\PhpParser as Tolerant;
class TolerantParserHelpers { class ParserHelpers {
public static function isConstantFetch(Tolerant\Node $node) : bool { public static function isConstantFetch(Tolerant\Node $node) : bool {
$parent = $node->parent; $parent = $node->parent;
return return

View File

@ -35,7 +35,7 @@ class PhpDocument
/** /**
* The DefinitionResolver instance to resolve reference nodes to definitions * The DefinitionResolver instance to resolve reference nodes to definitions
* *
* @var TolerantDefinitionResolver * @var DefinitionResolver
*/ */
private $definitionResolver; private $definitionResolver;
@ -99,7 +99,7 @@ class PhpDocument
* @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 Parser $parser The PHPParser instance
* @param DocBlockFactory $docBlockFactory The DocBlockFactory instance to parse docblocks * @param DocBlockFactory $docBlockFactory The DocBlockFactory instance to parse docblocks
* @param TolerantDefinitionResolver $definitionResolver The DefinitionResolver to resolve definitions to symbols in the workspace * @param DefinitionResolver $definitionResolver The DefinitionResolver to resolve definitions to symbols in the workspace
*/ */
public function __construct( public function __construct(
string $uri, string $uri,
@ -107,7 +107,7 @@ class PhpDocument
Index $index, Index $index,
$parser, $parser,
DocBlockFactory $docBlockFactory, DocBlockFactory $docBlockFactory,
TolerantDefinitionResolver $definitionResolver DefinitionResolver $definitionResolver
) { ) {
$this->uri = $uri; $this->uri = $uri;
$this->index = $index; $this->index = $index;
@ -158,7 +158,7 @@ class PhpDocument
$this->definitions = null; $this->definitions = null;
$this->definitionNodes = null; $this->definitionNodes = null;
$treeAnalyzer = new TolerantTreeAnalyzer($this->parser, $content, $this->docBlockFactory, $this->definitionResolver, $this->uri); $treeAnalyzer = new TreeAnalyzer($this->parser, $content, $this->docBlockFactory, $this->definitionResolver, $this->uri);
$this->diagnostics = $treeAnalyzer->getDiagnostics(); $this->diagnostics = $treeAnalyzer->getDiagnostics();

View File

@ -48,20 +48,20 @@ class PhpDocumentLoader
private $docBlockFactory; private $docBlockFactory;
/** /**
* @var TolerantDefinitionResolver * @var DefinitionResolver
*/ */
private $definitionResolver; private $definitionResolver;
/** /**
* @param ContentRetriever $contentRetriever * @param ContentRetriever $contentRetriever
* @param ProjectIndex $projectIndex * @param ProjectIndex $projectIndex
* @param TolerantDefinitionResolver $definitionResolver * @param DefinitionResolver $definitionResolver
* @internal param ProjectIndex $project * @internal param ProjectIndex $project
*/ */
public function __construct( public function __construct(
ContentRetriever $contentRetriever, ContentRetriever $contentRetriever,
ProjectIndex $projectIndex, ProjectIndex $projectIndex,
TolerantDefinitionResolver $definitionResolver DefinitionResolver $definitionResolver
) { ) {
$this->contentRetriever = $contentRetriever; $this->contentRetriever = $contentRetriever;
$this->projectIndex = $projectIndex; $this->projectIndex = $projectIndex;

View File

@ -3,6 +3,7 @@
namespace LanguageServer\Protocol; namespace LanguageServer\Protocol;
use PhpParser\Node; use PhpParser\Node;
use Microsoft\PhpParser as Tolerant;
use Exception; use Exception;
/** /**
@ -42,53 +43,65 @@ class SymbolInformation
/** /**
* Converts a Node to a SymbolInformation * Converts a Node to a SymbolInformation
* *
* @param Node $node * @param Tolerant\Node $node
* @param string $fqn If given, $containerName will be extracted from it * @param string $fqn If given, $containerName will be extracted from it
* @return self|null * @return SymbolInformation|null
*/ */
public static function fromNode($node, string $fqn = null) public static function fromNode($node, string $fqn = null)
{ {
$parent = $node->getAttribute('parentNode');
$symbol = new self; $symbol = new self;
if ($node instanceof Node\Stmt\Class_) { if ($node instanceof Tolerant\Node\Statement\ClassDeclaration) {
$symbol->kind = SymbolKind::CLASS_; $symbol->kind = SymbolKind::CLASS_;
} else if ($node instanceof Node\Stmt\Trait_) { } else if ($node instanceof Tolerant\Node\Statement\TraitDeclaration) {
$symbol->kind = SymbolKind::CLASS_; $symbol->kind = SymbolKind::CLASS_;
} else if ($node instanceof Node\Stmt\Interface_) { } else if ($node instanceof Tolerant\Node\Statement\InterfaceDeclaration) {
$symbol->kind = SymbolKind::INTERFACE; $symbol->kind = SymbolKind::INTERFACE;
} else if ($node instanceof Node\Name && $parent instanceof Node\Stmt\Namespace_) { } else if ($node instanceof Tolerant\Node\Statement\NamespaceDefinition) {
$symbol->kind = SymbolKind::NAMESPACE; $symbol->kind = SymbolKind::NAMESPACE;
} else if ($node instanceof Node\Stmt\Function_) { } else if ($node instanceof Tolerant\Node\Statement\FunctionDeclaration) {
$symbol->kind = SymbolKind::FUNCTION; $symbol->kind = SymbolKind::FUNCTION;
} else if ($node instanceof Node\Stmt\ClassMethod) { } else if ($node instanceof Tolerant\Node\MethodDeclaration) {
$symbol->kind = SymbolKind::METHOD; $symbol->kind = SymbolKind::METHOD;
} else if ($node instanceof Node\Stmt\PropertyProperty) { } else if ($node instanceof Tolerant\Node\Expression\Variable && $node->getFirstAncestor(Tolerant\Node\PropertyDeclaration::class) !== null) {
$symbol->kind = SymbolKind::PROPERTY; $symbol->kind = SymbolKind::PROPERTY;
} else if ($node instanceof Node\Const_) { } else if ($node instanceof Tolerant\Node\ConstElement) {
$symbol->kind = SymbolKind::CONSTANT; $symbol->kind = SymbolKind::CONSTANT;
} else if ( }
else if (
( (
($node instanceof Node\Expr\Assign || $node instanceof Node\Expr\AssignOp) ($node instanceof Tolerant\Node\Expression\AssignmentExpression)
&& $node->var instanceof Node\Expr\Variable && $node->leftOperand instanceof Tolerant\Node\Expression\Variable
) )
|| $node instanceof Node\Expr\ClosureUse || $node instanceof Tolerant\Node\UseVariableName
|| $node instanceof Node\Param || $node instanceof Tolerant\Node\Parameter
) { ) {
$symbol->kind = SymbolKind::VARIABLE; $symbol->kind = SymbolKind::VARIABLE;
} else { } else {
return null; return null;
} }
if ($node instanceof Node\Name) {
$symbol->name = (string)$node; if ($node instanceof Tolerant\Node\Expression\AssignmentExpression) {
} else if ($node instanceof Node\Expr\Assign || $node instanceof Node\Expr\AssignOp) { if ($node->leftOperand instanceof Tolerant\Node\Expression\Variable) {
$symbol->name = $node->var->name; $symbol->name = $node->leftOperand->getName();
} else if ($node instanceof Node\Expr\ClosureUse) { } elseif ($node->leftOperand instanceof Tolerant\Token) {
$symbol->name = $node->var; $symbol->name = trim($node->leftOperand->getText($node->getFileContents()), "$");
}
} else if ($node instanceof Tolerant\Node\UseVariableName) {
$symbol->name = $node->getName();
} else if (isset($node->name)) { } else if (isset($node->name)) {
$symbol->name = (string)$node->name; if ($node->name instanceof Tolerant\Node\QualifiedName) {
$symbol->name = (string)Tolerant\ResolvedName::buildName($node->name->nameParts, $node->getFileContents());
} else {
$symbol->name = ltrim((string)$node->name->getText($node->getFileContents()), "$");
}
} else if (isset($node->variableName)) {
$symbol->name = $node->variableName->getText($node);
} else { } else {
return null; return null;
} }
$symbol->location = Location::fromNode($node); $symbol->location = Location::fromNode($node);
if ($fqn !== null) { if ($fqn !== null) {
$parts = preg_split('/(::|->|\\\\)/', $fqn); $parts = preg_split('/(::|->|\\\\)/', $fqn);

View File

@ -1,85 +0,0 @@
<?php
namespace LanguageServer\Protocol;
use PhpParser\Node;
use Microsoft\PhpParser as Tolerant;
use Exception;
/**
* Represents information about programming constructs like variables, classes,
* interfaces etc.
*/
class TolerantSymbolInformation
{
/**
* Converts a Node to a SymbolInformation
*
* @param Tolerant\Node $node
* @param string $fqn If given, $containerName will be extracted from it
* @return SymbolInformation|null
*/
public static function fromNode($node, string $fqn = null)
{
$symbol = new SymbolInformation();
if ($node instanceof Tolerant\Node\Statement\ClassDeclaration) {
$symbol->kind = SymbolKind::CLASS_;
} else if ($node instanceof Tolerant\Node\Statement\TraitDeclaration) {
$symbol->kind = SymbolKind::CLASS_;
} else if ($node instanceof Tolerant\Node\Statement\InterfaceDeclaration) {
$symbol->kind = SymbolKind::INTERFACE;
} else if ($node instanceof Tolerant\Node\Statement\NamespaceDefinition) {
$symbol->kind = SymbolKind::NAMESPACE;
} else if ($node instanceof Tolerant\Node\Statement\FunctionDeclaration) {
$symbol->kind = SymbolKind::FUNCTION;
} else if ($node instanceof Tolerant\Node\MethodDeclaration) {
$symbol->kind = SymbolKind::METHOD;
} else if ($node instanceof Tolerant\Node\Expression\Variable && $node->getFirstAncestor(Tolerant\Node\PropertyDeclaration::class) !== null) {
$symbol->kind = SymbolKind::PROPERTY;
} else if ($node instanceof Tolerant\Node\ConstElement) {
$symbol->kind = SymbolKind::CONSTANT;
}
else if (
(
($node instanceof Tolerant\Node\Expression\AssignmentExpression)
&& $node->leftOperand instanceof Tolerant\Node\Expression\Variable
)
|| $node instanceof Tolerant\Node\UseVariableName
|| $node instanceof Tolerant\Node\Parameter
) {
$symbol->kind = SymbolKind::VARIABLE;
} else {
return null;
}
if ($node instanceof Tolerant\Node\Expression\AssignmentExpression) {
if ($node->leftOperand instanceof Tolerant\Node\Expression\Variable) {
$symbol->name = $node->leftOperand->getName();
} elseif ($node->leftOperand instanceof Tolerant\Token) {
$symbol->name = trim($node->leftOperand->getText($node->getFileContents()), "$");
}
} else if ($node instanceof Tolerant\Node\UseVariableName) {
$symbol->name = $node->getName();
} else if (isset($node->name)) {
if ($node->name instanceof Tolerant\Node\QualifiedName) {
$symbol->name = (string)Tolerant\ResolvedName::buildName($node->name->nameParts, $node->getFileContents());
} else {
$symbol->name = ltrim((string)$node->name->getText($node->getFileContents()), "$");
}
} else if (isset($node->variableName)) {
$symbol->name = $node->variableName->getText($node);
} else {
return null;
}
$symbol->location = Location::fromNode($node);
if ($fqn !== null) {
$parts = preg_split('/(::|->|\\\\)/', $fqn);
array_pop($parts);
$symbol->containerName = implode('\\', $parts);
}
return $symbol;
}
}

View File

@ -4,7 +4,7 @@ declare(strict_types = 1);
namespace LanguageServer\Server; namespace LanguageServer\Server;
use LanguageServer\{ use LanguageServer\{
CompletionProvider, FqnUtilities, LanguageClient, PhpDocument, PhpDocumentLoader, TolerantDefinitionResolver CompletionProvider, FqnUtilities, LanguageClient, PhpDocument, PhpDocumentLoader, DefinitionResolver
}; };
use LanguageServer\Index\ReadableIndex; use LanguageServer\Index\ReadableIndex;
use LanguageServer\Protocol\{ use LanguageServer\Protocol\{
@ -36,7 +36,7 @@ class TextDocument
protected $project; protected $project;
/** /**
* @var TolerantDefinitionResolver * @var DefinitionResolver
*/ */
protected $definitionResolver; protected $definitionResolver;
@ -62,7 +62,7 @@ class TextDocument
/** /**
* @param PhpDocumentLoader $documentLoader * @param PhpDocumentLoader $documentLoader
* @param TolerantDefinitionResolver $definitionResolver * @param DefinitionResolver $definitionResolver
* @param LanguageClient $client * @param LanguageClient $client
* @param ReadableIndex $index * @param ReadableIndex $index
* @param \stdClass $composerJson * @param \stdClass $composerJson
@ -70,7 +70,7 @@ class TextDocument
*/ */
public function __construct( public function __construct(
PhpDocumentLoader $documentLoader, PhpDocumentLoader $documentLoader,
TolerantDefinitionResolver $definitionResolver, DefinitionResolver $definitionResolver,
LanguageClient $client, LanguageClient $client,
ReadableIndex $index, ReadableIndex $index,
\stdClass $composerJson = null, \stdClass $composerJson = null,

File diff suppressed because it is too large Load Diff

View File

@ -1,186 +0,0 @@
<?php
declare(strict_types = 1);
namespace LanguageServer;
use LanguageServer\Protocol\{Diagnostic, DiagnosticSeverity, Range, Position, TextEdit};
use LanguageServer\NodeVisitor\{
NodeAtPositionFinder,
ReferencesAdder,
DocBlockParser,
DefinitionCollector,
ColumnCalculator,
ReferencesCollector
};
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;
class TolerantTreeAnalyzer implements TreeAnalyzerInterface {
private $parser;
/** @var Tolerant\Node */
private $stmts;
private $diagnostics;
private $content;
/**
* TolerantTreeAnalyzer constructor.
* @param Tolerant\Parser $parser
* @param $content
* @param $docBlockFactory
* @param TolerantDefinitionResolver $definitionResolver
* @param $uri
*/
public function __construct($parser, $content, $docBlockFactory, $definitionResolver, $uri) {
$this->uri = $uri;
$this->parser = $parser;
$this->docBlockFactory = $docBlockFactory;
$this->definitionResolver = $definitionResolver;
$this->content = $content;
$this->stmts = $this->parser->parseSourceFile($content, $uri);
// TODO - docblock errors
$this->collectDefinitionsAndReferences($this->stmts);
}
public function collectDefinitionsAndReferences(Tolerant\Node $stmts) {
foreach ($stmts::CHILD_NAMES as $name) {
$node = $stmts->$name;
if ($node === null) {
continue;
}
if (\is_array($node)) {
foreach ($node as $child) {
if ($child instanceof Tolerant\Node) {
$this->update($child);
}
}
continue;
}
if ($node instanceof Tolerant\Node) {
$this->update($node);
}
if (($_error = Tolerant\DiagnosticsProvider::checkDiagnostics($node)) !== null) {
$range = Tolerant\PositionUtilities::getRangeFromPosition($_error->start, $_error->length, $this->content);
$this->diagnostics[] = new Diagnostic(
$_error->message,
new Range(
new Position($range->start->line, $range->start->character),
new Position($range->end->line, $range->start->character)
),
null,
DiagnosticSeverity::ERROR,
'php'
);
}
}
}
public function update($node) {
$fqn = ($this->definitionResolver)::getDefinedFqn($node);
// Only index definitions with an FQN (no variables)
if ($fqn !== null) {
$this->definitionNodes[$fqn] = $node;
$this->definitions[$fqn] = $this->definitionResolver->createDefinitionFromNode($node, $fqn);
} else {
$parent = $node->parent;
if (!(
(
// $node->parent instanceof Tolerant\Node\Expression\ScopedPropertyAccessExpression ||
($node instanceof Tolerant\Node\Expression\ScopedPropertyAccessExpression ||
$node instanceof Tolerant\Node\Expression\MemberAccessExpression)
&& !(
$node->parent instanceof Tolerant\Node\Expression\CallExpression ||
$node->memberName instanceof Tolerant\Token
))
|| ($parent instanceof Tolerant\Node\Statement\NamespaceDefinition && $parent->name !== null && $parent->name->getStart() === $node->getStart()))
) {
$fqn = $this->definitionResolver->resolveReferenceNodeToFqn($node);
if ($fqn !== null) {
$this->addReference($fqn, $node);
if (
$node instanceof Tolerant\Node\QualifiedName
&& ($node->isQualifiedName() || $node->parent instanceof Tolerant\Node\NamespaceUseClause)
&& !($parent instanceof Tolerant\Node\Statement\NamespaceDefinition && $parent->name->getStart() === $node->getStart()
)
) {
// Add references for each referenced namespace
$ns = $fqn;
while (($pos = strrpos($ns, '\\')) !== false) {
$ns = substr($ns, 0, $pos);
$this->addReference($ns, $node);
}
}
// Namespaced constant access and function calls also need to register a reference
// to the global version because PHP falls back to global at runtime
// http://php.net/manual/en/language.namespaces.fallback.php
if (TolerantParserHelpers::isConstantFetch($node) ||
($parent instanceof Tolerant\Node\Expression\CallExpression
&& !(
$node instanceof Tolerant\Node\Expression\ScopedPropertyAccessExpression ||
$node instanceof Tolerant\Node\Expression\MemberAccessExpression
))) {
$parts = explode('\\', $fqn);
if (count($parts) > 1) {
$globalFqn = end($parts);
$this->addReference($globalFqn, $node);
}
}
}
}
}
$this->collectDefinitionsAndReferences($node);
}
public function getDiagnostics() {
return $this->diagnostics ?? [];
}
private function addReference(string $fqn, Tolerant\Node $node)
{
if (!isset($this->referenceNodes[$fqn])) {
$this->referenceNodes[$fqn] = [];
}
$this->referenceNodes[$fqn][] = $node;
}
public function getDefinitions() {
return $this->definitions ?? [];
}
public function getDefinitionNodes() {
return $this->definitionNodes ?? [];
}
public function getReferenceNodes() {
return $this->referenceNodes ?? [];
}
public function getStmts() {
return $this->stmts;
}
/**
* Returns the URI of the document
*
* @return string
*/
public function getUri(): string
{
return $this->uri;
}
}

View File

@ -19,83 +19,144 @@ use phpDocumentor\Reflection\DocBlockFactory;
use Sabre\Uri; use Sabre\Uri;
use Microsoft\PhpParser as Tolerant; use Microsoft\PhpParser as Tolerant;
class TreeAnalyzer implements TreeAnalyzerInterface { class TreeAnalyzer {
private $parser; private $parser;
/** @var Tolerant\Node */
private $stmts; private $stmts;
private $errorHandler;
private $diagnostics; private $diagnostics;
private $content;
/**
* TreeAnalyzer constructor.
* @param Tolerant\Parser $parser
* @param $content
* @param $docBlockFactory
* @param DefinitionResolver $definitionResolver
* @param $uri
*/
public function __construct($parser, $content, $docBlockFactory, $definitionResolver, $uri) { public function __construct($parser, $content, $docBlockFactory, $definitionResolver, $uri) {
$this->uri = $uri; $this->uri = $uri;
$this->parser = $parser; $this->parser = $parser;
$this->docBlockFactory = $docBlockFactory; $this->docBlockFactory = $docBlockFactory;
$this->definitionResolver = $definitionResolver; $this->definitionResolver = $definitionResolver;
$this->content = $content; $this->content = $content;
$errorHandler = new ErrorHandler\Collecting; $this->stmts = $this->parser->parseSourceFile($content, $uri);
$stmts = $this->parser->parse($content, $errorHandler);
$this->diagnostics = []; // TODO - docblock errors
foreach ($errorHandler->getErrors() as $error) {
$this->diagnostics[] = Diagnostic::fromError($error, $this->content, DiagnosticSeverity::ERROR, 'php'); $this->collectDefinitionsAndReferences($this->stmts);
} }
// $stmts can be null in case of a fatal parsing error <- Interesting. When do fatal parsing errors occur? public function collectDefinitionsAndReferences(Tolerant\Node $stmts) {
if ($stmts) { foreach ($stmts::CHILD_NAMES as $name) {
$traverser = new NodeTraverser; $node = $stmts->$name;
// Resolve aliased names to FQNs if ($node === null) {
$traverser->addVisitor(new NameResolver($errorHandler)); continue;
// Add parentNode, previousSibling, nextSibling attributes
$traverser->addVisitor(new ReferencesAdder($this));
// Add column attributes to nodes
$traverser->addVisitor(new ColumnCalculator($content));
// Parse docblocks and add docBlock attributes to nodes
$docBlockParser = new DocBlockParser($this->docBlockFactory);
$traverser->addVisitor($docBlockParser);
$traverser->traverse($stmts);
// Report errors from parsing docblocks
foreach ($docBlockParser->errors as $error) {
$this->diagnostics[] = Diagnostic::fromError($error, $this->content, DiagnosticSeverity::WARNING, 'php');
} }
$traverser = new NodeTraverser; if (\is_array($node)) {
foreach ($node as $child) {
// Collect all definitions if ($child instanceof Tolerant\Node) {
$definitionCollector = new DefinitionCollector($this->definitionResolver); $this->update($child);
$traverser->addVisitor($definitionCollector);
// Collect all references
$referencesCollector = new ReferencesCollector($this->definitionResolver);
$traverser->addVisitor($referencesCollector);
$traverser->traverse($stmts);
// Register this document on the project for all the symbols defined in it
$this->definitions = $definitionCollector->definitions;
$this->definitionNodes = $definitionCollector->nodes;
foreach ($definitionCollector->definitions as $fqn => $definition) {
// $this->index->setDefinition($fqn, $definition);
} }
// Register this document on the project for references }
$this->referenceNodes = $referencesCollector->nodes; continue;
foreach ($referencesCollector->nodes as $fqn => $nodes) {
// $this->index->addReferenceUri($fqn, $this->uri);
} }
$this->stmts = $stmts; if ($node instanceof Tolerant\Node) {
$this->update($node);
} }
if (($_error = Tolerant\DiagnosticsProvider::checkDiagnostics($node)) !== null) {
$range = Tolerant\PositionUtilities::getRangeFromPosition($_error->start, $_error->length, $this->content);
$this->diagnostics[] = new Diagnostic(
$_error->message,
new Range(
new Position($range->start->line, $range->start->character),
new Position($range->end->line, $range->start->character)
),
null,
DiagnosticSeverity::ERROR,
'php'
);
}
}
}
public function update($node) {
$fqn = ($this->definitionResolver)::getDefinedFqn($node);
// Only index definitions with an FQN (no variables)
if ($fqn !== null) {
$this->definitionNodes[$fqn] = $node;
$this->definitions[$fqn] = $this->definitionResolver->createDefinitionFromNode($node, $fqn);
} else {
$parent = $node->parent;
if (!(
(
// $node->parent instanceof Tolerant\Node\Expression\ScopedPropertyAccessExpression ||
($node instanceof Tolerant\Node\Expression\ScopedPropertyAccessExpression ||
$node instanceof Tolerant\Node\Expression\MemberAccessExpression)
&& !(
$node->parent instanceof Tolerant\Node\Expression\CallExpression ||
$node->memberName instanceof Tolerant\Token
))
|| ($parent instanceof Tolerant\Node\Statement\NamespaceDefinition && $parent->name !== null && $parent->name->getStart() === $node->getStart()))
) {
$fqn = $this->definitionResolver->resolveReferenceNodeToFqn($node);
if ($fqn !== null) {
$this->addReference($fqn, $node);
if (
$node instanceof Tolerant\Node\QualifiedName
&& ($node->isQualifiedName() || $node->parent instanceof Tolerant\Node\NamespaceUseClause)
&& !($parent instanceof Tolerant\Node\Statement\NamespaceDefinition && $parent->name->getStart() === $node->getStart()
)
) {
// Add references for each referenced namespace
$ns = $fqn;
while (($pos = strrpos($ns, '\\')) !== false) {
$ns = substr($ns, 0, $pos);
$this->addReference($ns, $node);
}
}
// Namespaced constant access and function calls also need to register a reference
// to the global version because PHP falls back to global at runtime
// http://php.net/manual/en/language.namespaces.fallback.php
if (ParserHelpers::isConstantFetch($node) ||
($parent instanceof Tolerant\Node\Expression\CallExpression
&& !(
$node instanceof Tolerant\Node\Expression\ScopedPropertyAccessExpression ||
$node instanceof Tolerant\Node\Expression\MemberAccessExpression
))) {
$parts = explode('\\', $fqn);
if (count($parts) > 1) {
$globalFqn = end($parts);
$this->addReference($globalFqn, $node);
}
}
}
}
}
$this->collectDefinitionsAndReferences($node);
} }
public function getDiagnostics() { public function getDiagnostics() {
return $this->diagnostics; return $this->diagnostics ?? [];
}
private function addReference(string $fqn, Tolerant\Node $node)
{
if (!isset($this->referenceNodes[$fqn])) {
$this->referenceNodes[$fqn] = [];
}
$this->referenceNodes[$fqn][] = $node;
} }
public function getDefinitions() { public function getDefinitions() {

View File

@ -1,34 +0,0 @@
<?php
declare(strict_types = 1);
namespace LanguageServer;
use LanguageServer\Protocol\{Diagnostic, DiagnosticSeverity, Range, Position, TextEdit};
use LanguageServer\NodeVisitor\{
NodeAtPositionFinder,
ReferencesAdder,
DocBlockParser,
DefinitionCollector,
ColumnCalculator,
ReferencesCollector
};
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;
interface TreeAnalyzerInterface {
public function __construct($parser, $content, $docBlockFactory, $definitionResolver, $uri);
public function getDiagnostics();
public function getDefinitions();
public function getDefinitionNodes();
public function getReferenceNodes();
public function getStmts();
}

View File

@ -7,7 +7,7 @@ use PHPUnit\Framework\TestCase;
use PhpParser\{Node}; use PhpParser\{Node};
use phpDocumentor\Reflection\DocBlockFactory; use phpDocumentor\Reflection\DocBlockFactory;
use LanguageServer\{ use LanguageServer\{
TolerantDefinitionResolver, TolerantTreeAnalyzer DefinitionResolver, TreeAnalyzer
}; };
use LanguageServer\Index\{Index}; use LanguageServer\Index\{Index};
use function LanguageServer\pathToUri; use function LanguageServer\pathToUri;
@ -71,10 +71,10 @@ class DefinitionCollectorTest extends TestCase
$docBlockFactory = DocBlockFactory::createInstance(); $docBlockFactory = DocBlockFactory::createInstance();
$index = new Index; $index = new Index;
$definitionResolver = new TolerantDefinitionResolver($index); $definitionResolver = new DefinitionResolver($index);
$content = file_get_contents($path); $content = file_get_contents($path);
$treeAnalyzer = new TolerantTreeAnalyzer($parser, $content, $docBlockFactory, $definitionResolver, $uri); $treeAnalyzer = new TreeAnalyzer($parser, $content, $docBlockFactory, $definitionResolver, $uri);
return $treeAnalyzer->getDefinitionNodes(); return $treeAnalyzer->getDefinitionNodes();
} }
} }

View File

@ -4,7 +4,7 @@ declare(strict_types = 1);
namespace LanguageServer\Tests\Server; namespace LanguageServer\Tests\Server;
use LanguageServer\{ use LanguageServer\{
PhpDocument, PhpDocumentLoader, Project, TolerantDefinitionResolver PhpDocument, PhpDocumentLoader, Project, DefinitionResolver
}; };
use LanguageServer\ContentRetriever\FileSystemContentRetriever; use LanguageServer\ContentRetriever\FileSystemContentRetriever;
use LanguageServer\Index\{ use LanguageServer\Index\{
@ -26,7 +26,7 @@ class PhpDocumentLoaderTest extends TestCase
$this->loader = new PhpDocumentLoader( $this->loader = new PhpDocumentLoader(
new FileSystemContentRetriever, new FileSystemContentRetriever,
$projectIndex, $projectIndex,
new TolerantDefinitionResolver($projectIndex) new DefinitionResolver($projectIndex)
); );
} }

View File

@ -4,7 +4,7 @@ declare(strict_types = 1);
namespace LanguageServer\Tests\Server; namespace LanguageServer\Tests\Server;
use LanguageServer\{ use LanguageServer\{
PhpDocument, TolerantDefinitionResolver PhpDocument, DefinitionResolver
}; };
use LanguageServer\Index\{ use LanguageServer\Index\{
Index Index
@ -25,7 +25,7 @@ class PhpDocumentTest extends TestCase
$parser = new Tolerant\Parser(); $parser = new Tolerant\Parser();
$docBlockFactory = DocBlockFactory::createInstance(); $docBlockFactory = DocBlockFactory::createInstance();
$index = new Index; $index = new Index;
$definitionResolver = new TolerantDefinitionResolver($index); $definitionResolver = new DefinitionResolver($index);
return new PhpDocument($uri, $content, $index, $parser, $docBlockFactory, $definitionResolver); return new PhpDocument($uri, $content, $index, $parser, $docBlockFactory, $definitionResolver);
} }

View File

@ -6,7 +6,7 @@ namespace LanguageServer\Tests\Server;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use LanguageServer\Tests\MockProtocolStream; use LanguageServer\Tests\MockProtocolStream;
use LanguageServer\{ use LanguageServer\{
Server, LanguageClient, PhpDocumentLoader, TolerantDefinitionResolver Server, LanguageClient, PhpDocumentLoader, DefinitionResolver
}; };
use LanguageServer\Index\{ProjectIndex, DependenciesIndex, Index}; use LanguageServer\Index\{ProjectIndex, DependenciesIndex, Index};
use LanguageServer\ContentRetriever\FileSystemContentRetriever; use LanguageServer\ContentRetriever\FileSystemContentRetriever;
@ -51,7 +51,7 @@ abstract class ServerTestCase extends TestCase
$projectIndex = new ProjectIndex($sourceIndex, $dependenciesIndex); $projectIndex = new ProjectIndex($sourceIndex, $dependenciesIndex);
$projectIndex->setComplete(); $projectIndex->setComplete();
$definitionResolver = new TolerantDefinitionResolver($projectIndex); $definitionResolver = new DefinitionResolver($projectIndex);
$client = new LanguageClient(new MockProtocolStream, new MockProtocolStream); $client = new LanguageClient(new MockProtocolStream, new MockProtocolStream);
$this->documentLoader = new PhpDocumentLoader(new FileSystemContentRetriever, $projectIndex, $definitionResolver); $this->documentLoader = new PhpDocumentLoader(new FileSystemContentRetriever, $projectIndex, $definitionResolver);
$this->textDocument = new Server\TextDocument($this->documentLoader, $definitionResolver, $client, $projectIndex); $this->textDocument = new Server\TextDocument($this->documentLoader, $definitionResolver, $client, $projectIndex);

View File

@ -6,7 +6,7 @@ namespace LanguageServer\Tests\Server\TextDocument;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use LanguageServer\Tests\MockProtocolStream; use LanguageServer\Tests\MockProtocolStream;
use LanguageServer\{ use LanguageServer\{
Server, LanguageClient, PhpDocumentLoader, TolerantDefinitionResolver Server, LanguageClient, PhpDocumentLoader, DefinitionResolver
}; };
use LanguageServer\Index\{Index, ProjectIndex, DependenciesIndex}; use LanguageServer\Index\{Index, ProjectIndex, DependenciesIndex};
use LanguageServer\ContentRetriever\FileSystemContentRetriever; use LanguageServer\ContentRetriever\FileSystemContentRetriever;
@ -37,7 +37,7 @@ class CompletionTest extends TestCase
{ {
$client = new LanguageClient(new MockProtocolStream, new MockProtocolStream); $client = new LanguageClient(new MockProtocolStream, new MockProtocolStream);
$projectIndex = new ProjectIndex(new Index, new DependenciesIndex); $projectIndex = new ProjectIndex(new Index, new DependenciesIndex);
$definitionResolver = new TolerantDefinitionResolver($projectIndex); $definitionResolver = new DefinitionResolver($projectIndex);
$contentRetriever = new FileSystemContentRetriever; $contentRetriever = new FileSystemContentRetriever;
$this->loader = new PhpDocumentLoader($contentRetriever, $projectIndex, $definitionResolver); $this->loader = new PhpDocumentLoader($contentRetriever, $projectIndex, $definitionResolver);
$this->loader->load(pathToUri(__DIR__ . '/../../../fixtures/global_symbols.php'))->wait(); $this->loader->load(pathToUri(__DIR__ . '/../../../fixtures/global_symbols.php'))->wait();

View File

@ -6,7 +6,7 @@ namespace LanguageServer\Tests\Server\TextDocument\Definition;
use LanguageServer\Tests\MockProtocolStream; use LanguageServer\Tests\MockProtocolStream;
use LanguageServer\Tests\Server\ServerTestCase; use LanguageServer\Tests\Server\ServerTestCase;
use LanguageServer\{ use LanguageServer\{
Server, LanguageClient, PhpDocumentLoader, TolerantDefinitionResolver Server, LanguageClient, PhpDocumentLoader, DefinitionResolver
}; };
use LanguageServer\Index\{Index, ProjectIndex, DependenciesIndex}; use LanguageServer\Index\{Index, ProjectIndex, DependenciesIndex};
use LanguageServer\ContentRetriever\FileSystemContentRetriever; use LanguageServer\ContentRetriever\FileSystemContentRetriever;
@ -19,7 +19,7 @@ class GlobalFallbackTest extends ServerTestCase
$projectIndex = new ProjectIndex(new Index, new DependenciesIndex); $projectIndex = new ProjectIndex(new Index, new DependenciesIndex);
$projectIndex->setComplete(); $projectIndex->setComplete();
$client = new LanguageClient(new MockProtocolStream, new MockProtocolStream); $client = new LanguageClient(new MockProtocolStream, new MockProtocolStream);
$definitionResolver = new TolerantDefinitionResolver($projectIndex); $definitionResolver = new DefinitionResolver($projectIndex);
$contentRetriever = new FileSystemContentRetriever; $contentRetriever = new FileSystemContentRetriever;
$loader = new PhpDocumentLoader($contentRetriever, $projectIndex, $definitionResolver); $loader = new PhpDocumentLoader($contentRetriever, $projectIndex, $definitionResolver);
$this->textDocument = new Server\TextDocument($loader, $definitionResolver, $client, $projectIndex); $this->textDocument = new Server\TextDocument($loader, $definitionResolver, $client, $projectIndex);

View File

@ -6,7 +6,7 @@ namespace LanguageServer\Tests\Server\TextDocument;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use LanguageServer\Tests\MockProtocolStream; use LanguageServer\Tests\MockProtocolStream;
use LanguageServer\{ use LanguageServer\{
Server, LanguageClient, PhpDocumentLoader, TolerantDefinitionResolver Server, LanguageClient, PhpDocumentLoader, DefinitionResolver
}; };
use LanguageServer\ContentRetriever\FileSystemContentRetriever; use LanguageServer\ContentRetriever\FileSystemContentRetriever;
use LanguageServer\Index\{Index, ProjectIndex, DependenciesIndex}; use LanguageServer\Index\{Index, ProjectIndex, DependenciesIndex};
@ -23,7 +23,7 @@ class DidChangeTest extends TestCase
{ {
$projectIndex = new ProjectIndex(new Index, new DependenciesIndex); $projectIndex = new ProjectIndex(new Index, new DependenciesIndex);
$client = new LanguageClient(new MockProtocolStream, new MockProtocolStream); $client = new LanguageClient(new MockProtocolStream, new MockProtocolStream);
$definitionResolver = new TolerantDefinitionResolver($projectIndex); $definitionResolver = new DefinitionResolver($projectIndex);
$loader = new PhpDocumentLoader(new FileSystemContentRetriever, $projectIndex, $definitionResolver); $loader = new PhpDocumentLoader(new FileSystemContentRetriever, $projectIndex, $definitionResolver);
$textDocument = new Server\TextDocument($loader, $definitionResolver, $client, $projectIndex); $textDocument = new Server\TextDocument($loader, $definitionResolver, $client, $projectIndex);
$phpDocument = $loader->open('whatever', "<?php\necho 'Hello, World'\n"); $phpDocument = $loader->open('whatever', "<?php\necho 'Hello, World'\n");

View File

@ -6,7 +6,7 @@ namespace LanguageServer\Tests\Server\TextDocument;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use LanguageServer\Tests\MockProtocolStream; use LanguageServer\Tests\MockProtocolStream;
use LanguageServer\{ use LanguageServer\{
Server, LanguageClient, PhpDocumentLoader, TolerantDefinitionResolver Server, LanguageClient, PhpDocumentLoader, DefinitionResolver
}; };
use LanguageServer\ContentRetriever\FileSystemContentRetriever; use LanguageServer\ContentRetriever\FileSystemContentRetriever;
use LanguageServer\Index\{Index, ProjectIndex, DependenciesIndex}; use LanguageServer\Index\{Index, ProjectIndex, DependenciesIndex};
@ -18,7 +18,7 @@ class DidCloseTest extends TestCase
{ {
$projectIndex = new ProjectIndex(new Index, new DependenciesIndex); $projectIndex = new ProjectIndex(new Index, new DependenciesIndex);
$client = new LanguageClient(new MockProtocolStream, new MockProtocolStream); $client = new LanguageClient(new MockProtocolStream, new MockProtocolStream);
$definitionResolver = new TolerantDefinitionResolver($projectIndex); $definitionResolver = new DefinitionResolver($projectIndex);
$loader = new PhpDocumentLoader(new FileSystemContentRetriever, $projectIndex, $definitionResolver); $loader = new PhpDocumentLoader(new FileSystemContentRetriever, $projectIndex, $definitionResolver);
$textDocument = new Server\TextDocument($loader, $definitionResolver, $client, $projectIndex); $textDocument = new Server\TextDocument($loader, $definitionResolver, $client, $projectIndex);
$phpDocument = $loader->open('whatever', "<?php\necho 'Hello, World'\n"); $phpDocument = $loader->open('whatever', "<?php\necho 'Hello, World'\n");

View File

@ -6,7 +6,7 @@ namespace LanguageServer\Tests\Server\TextDocument;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use LanguageServer\Tests\MockProtocolStream; use LanguageServer\Tests\MockProtocolStream;
use LanguageServer\{ use LanguageServer\{
Server, LanguageClient, PhpDocumentLoader, TolerantDefinitionResolver Server, LanguageClient, PhpDocumentLoader, DefinitionResolver
}; };
use LanguageServer\Index\{Index, ProjectIndex, DependenciesIndex}; use LanguageServer\Index\{Index, ProjectIndex, DependenciesIndex};
use LanguageServer\ContentRetriever\FileSystemContentRetriever; use LanguageServer\ContentRetriever\FileSystemContentRetriever;
@ -26,7 +26,7 @@ class FormattingTest extends TestCase
{ {
$projectIndex = new ProjectIndex(new Index, new DependenciesIndex); $projectIndex = new ProjectIndex(new Index, new DependenciesIndex);
$client = new LanguageClient(new MockProtocolStream, new MockProtocolStream); $client = new LanguageClient(new MockProtocolStream, new MockProtocolStream);
$definitionResolver = new TolerantDefinitionResolver($projectIndex); $definitionResolver = new DefinitionResolver($projectIndex);
$loader = new PhpDocumentLoader(new FileSystemContentRetriever, $projectIndex, $definitionResolver); $loader = new PhpDocumentLoader(new FileSystemContentRetriever, $projectIndex, $definitionResolver);
$textDocument = new Server\TextDocument($loader, $definitionResolver, $client, $projectIndex); $textDocument = new Server\TextDocument($loader, $definitionResolver, $client, $projectIndex);

View File

@ -6,7 +6,7 @@ namespace LanguageServer\Tests\Server\TextDocument;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use LanguageServer\Tests\MockProtocolStream; use LanguageServer\Tests\MockProtocolStream;
use LanguageServer\{ use LanguageServer\{
Server, Client, LanguageClient, ClientHandler, PhpDocumentLoader, TolerantDefinitionResolver Server, Client, LanguageClient, ClientHandler, PhpDocumentLoader, DefinitionResolver
}; };
use LanguageServer\Index\{Index, ProjectIndex, DependenciesIndex}; use LanguageServer\Index\{Index, ProjectIndex, DependenciesIndex};
use LanguageServer\ContentRetriever\FileSystemContentRetriever; use LanguageServer\ContentRetriever\FileSystemContentRetriever;
@ -40,7 +40,7 @@ class ParseErrorsTest extends TestCase
} }
}; };
$projectIndex = new ProjectIndex(new Index, new DependenciesIndex); $projectIndex = new ProjectIndex(new Index, new DependenciesIndex);
$definitionResolver = new TolerantDefinitionResolver($projectIndex); $definitionResolver = new DefinitionResolver($projectIndex);
$loader = new PhpDocumentLoader(new FileSystemContentRetriever, $projectIndex, $definitionResolver); $loader = new PhpDocumentLoader(new FileSystemContentRetriever, $projectIndex, $definitionResolver);
$this->textDocument = new Server\TextDocument($loader, $definitionResolver, $client, $projectIndex); $this->textDocument = new Server\TextDocument($loader, $definitionResolver, $client, $projectIndex);
} }

View File

@ -4,7 +4,7 @@ declare(strict_types = 1);
namespace LanguageServer\Tests\Server\TextDocument\References; namespace LanguageServer\Tests\Server\TextDocument\References;
use LanguageServer\{ use LanguageServer\{
LanguageClient, PhpDocumentLoader, Server, TolerantDefinitionResolver LanguageClient, PhpDocumentLoader, Server, DefinitionResolver
}; };
use LanguageServer\ContentRetriever\FileSystemContentRetriever; use LanguageServer\ContentRetriever\FileSystemContentRetriever;
use LanguageServer\Index\{ use LanguageServer\Index\{
@ -22,7 +22,7 @@ class GlobalFallbackTest extends ServerTestCase
{ {
$projectIndex = new ProjectIndex(new Index, new DependenciesIndex); $projectIndex = new ProjectIndex(new Index, new DependenciesIndex);
$projectIndex->setComplete(); $projectIndex->setComplete();
$definitionResolver = new TolerantDefinitionResolver($projectIndex); $definitionResolver = new DefinitionResolver($projectIndex);
$client = new LanguageClient(new MockProtocolStream, new MockProtocolStream); $client = new LanguageClient(new MockProtocolStream, new MockProtocolStream);
$this->documentLoader = new PhpDocumentLoader(new FileSystemContentRetriever, $projectIndex, $definitionResolver); $this->documentLoader = new PhpDocumentLoader(new FileSystemContentRetriever, $projectIndex, $definitionResolver);
$this->textDocument = new Server\TextDocument($this->documentLoader, $definitionResolver, $client, $projectIndex); $this->textDocument = new Server\TextDocument($this->documentLoader, $definitionResolver, $client, $projectIndex);

View File

@ -9,7 +9,7 @@ use LanguageServer\Definition;
use LanguageServer\Index\Index; use LanguageServer\Index\Index;
use LanguageServer\ParserKind; use LanguageServer\ParserKind;
use LanguageServer\PhpDocument; use LanguageServer\PhpDocument;
use LanguageServer\TolerantDefinitionResolver; use LanguageServer\DefinitionResolver;
use phpDocumentor\Reflection\DocBlock; use phpDocumentor\Reflection\DocBlock;
use phpDocumentor\Reflection\DocBlockFactory; use phpDocumentor\Reflection\DocBlockFactory;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
@ -96,7 +96,7 @@ class ValidationTest extends TestCase
$index = new Index(); $index = new Index();
$parser = new Tolerant\Parser(); $parser = new Tolerant\Parser();
$docBlockFactory = DocBlockFactory::createInstance(); $docBlockFactory = DocBlockFactory::createInstance();
$definitionResolver = new TolerantDefinitionResolver($index); $definitionResolver = new DefinitionResolver($index);
$document = new PhpDocument($filename, $fileContents, $index, $parser, $docBlockFactory, $definitionResolver); $document = new PhpDocument($filename, $fileContents, $index, $parser, $docBlockFactory, $definitionResolver);