From a5fec9452ba96c724c8a08ff77f9d8773a300a15 Mon Sep 17 00:00:00 2001 From: Sara Itani Date: Tue, 28 Mar 2017 14:02:26 -0700 Subject: [PATCH] Fix misc. issues in language server --- src/TolerantDefinitionResolver.php | 11 ++++--- src/TolerantTreeAnalyzer.php | 48 +++++++++++++++--------------- 2 files changed, 29 insertions(+), 30 deletions(-) diff --git a/src/TolerantDefinitionResolver.php b/src/TolerantDefinitionResolver.php index 7b60ff9..fbf30aa 100644 --- a/src/TolerantDefinitionResolver.php +++ b/src/TolerantDefinitionResolver.php @@ -326,17 +326,17 @@ class TolerantDefinitionResolver implements DefinitionResolverInterface } }*/ - else if (($node instanceof Tolerant\Node\Expression\CallExpression && - ($access = $node->callableExpression) instanceof Tolerant\Node\Expression\MemberAccessExpression) || ( + else if ( + $node instanceof Tolerant\Node\Expression\CallExpression && + (($access = $node->callableExpression) instanceof Tolerant\Node\Expression\MemberAccessExpression || ($access = $node) instanceof Tolerant\Node\Expression\MemberAccessExpression - )) { + )) { if ($access->memberName instanceof Tolerant\Node\Expression) { // Cannot get definition if right-hand side is expression return null; } // Get the type of the left-hand expression $varType = $this->resolveExpressionNodeToType($access->dereferencableExpression); -// var_dump($varType); if ($varType instanceof Types\Compound) { // For compound types, use the first FQN we find // (popular use case is ClassName|null) @@ -363,7 +363,6 @@ class TolerantDefinitionResolver implements DefinitionResolverInterface // Left-hand expression could not be resolved to a class return null; } else { -// var_dump("AAAHHHHH"); $classFqn = substr((string)$varType->getFqsen(), 1); // TODO @@ -597,7 +596,7 @@ class TolerantDefinitionResolver implements DefinitionResolverInterface if ($expr instanceof Tolerant\Node\Expression\CallExpression && !($expr->callableExpression instanceof Tolerant\Node\Expression\ScopedPropertyAccessExpression || $expr->callableExpression instanceof Tolerant\Node\Expression\MemberAccessExpression)) { - + // Find the function definition if ($expr->callableExpression instanceof Tolerant\Node\Expression) { // Cannot get type for dynamic function call diff --git a/src/TolerantTreeAnalyzer.php b/src/TolerantTreeAnalyzer.php index 4e6b994..39dd7ea 100644 --- a/src/TolerantTreeAnalyzer.php +++ b/src/TolerantTreeAnalyzer.php @@ -45,15 +45,28 @@ class TolerantTreeAnalyzer implements TreeAnalyzerInterface { // TODO - docblock errors - foreach ($this->stmts->getDescendantNodes() as $node) { - $fqn = $definitionResolver::getDefinedFqn($node); - // Only index definitions with an FQN (no variables) - if ($fqn === null) { - continue; - } - $this->definitionNodes[$fqn] = $node; - $this->definitions[$fqn] = $this->definitionResolver->createDefinitionFromNode($node, $fqn); - } + foreach ($this->stmts->getDescendantNodesAndTokens() as $node) { + if ($node instanceof Tolerant\Node) { + $fqn = $definitionResolver::getDefinedFqn($node); + // Only index definitions with an FQN (no variables) + if ($fqn === null) { + continue; + } + $this->definitionNodes[$fqn] = $node; + $this->definitions[$fqn] = $this->definitionResolver->createDefinitionFromNode($node, $fqn); + } + if (($_error = Tolerant\DiagnosticsProvider::checkDiagnostics($node)) !== null) { + $range = Tolerant\PositionUtilities::getRangeFromPosition($_error->start, $_error->length, $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) + ) + ); + } + } foreach ($this->stmts->getDescendantNodes() as $node) { $parent = $node->parent; @@ -90,7 +103,7 @@ class TolerantTreeAnalyzer implements TreeAnalyzerInterface { // 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 ($definitionResolver::isConstantFetch($node) || + if (TolerantDefinitionResolver::isConstantFetch($node) || ($parent instanceof Tolerant\Node\Expression\CallExpression && !( $node instanceof Tolerant\Node\Expression\ScopedPropertyAccessExpression @@ -102,23 +115,10 @@ class TolerantTreeAnalyzer implements TreeAnalyzerInterface { } } } - - $this->diagnostics = []; - foreach (Tolerant\DiagnosticsProvider::getDiagnostics($this->stmts) as $_error) { - $range = Tolerant\PositionUtilities::getRangeFromPosition($_error->start, $_error->length, $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) - ) - ); - } } public function getDiagnostics() { - return $this->diagnostics; + return $this->diagnostics ?? []; } private function addReference(string $fqn, Tolerant\Node $node)