1
0
Fork 0

Fix misc. issues in language server

pull/357/head
Sara Itani 2017-03-28 14:02:26 -07:00
parent 105f9bf813
commit a5fec9452b
2 changed files with 29 additions and 30 deletions

View File

@ -326,8 +326,9 @@ class TolerantDefinitionResolver implements DefinitionResolverInterface
} }
}*/ }*/
else if (($node instanceof Tolerant\Node\Expression\CallExpression && else if (
($access = $node->callableExpression) instanceof Tolerant\Node\Expression\MemberAccessExpression) || ( $node instanceof Tolerant\Node\Expression\CallExpression &&
(($access = $node->callableExpression) instanceof Tolerant\Node\Expression\MemberAccessExpression ||
($access = $node) instanceof Tolerant\Node\Expression\MemberAccessExpression ($access = $node) instanceof Tolerant\Node\Expression\MemberAccessExpression
)) { )) {
if ($access->memberName instanceof Tolerant\Node\Expression) { if ($access->memberName instanceof Tolerant\Node\Expression) {
@ -336,7 +337,6 @@ class TolerantDefinitionResolver implements DefinitionResolverInterface
} }
// Get the type of the left-hand expression // Get the type of the left-hand expression
$varType = $this->resolveExpressionNodeToType($access->dereferencableExpression); $varType = $this->resolveExpressionNodeToType($access->dereferencableExpression);
// var_dump($varType);
if ($varType instanceof Types\Compound) { if ($varType instanceof Types\Compound) {
// For compound types, use the first FQN we find // For compound types, use the first FQN we find
// (popular use case is ClassName|null) // (popular use case is ClassName|null)
@ -363,7 +363,6 @@ class TolerantDefinitionResolver implements DefinitionResolverInterface
// Left-hand expression could not be resolved to a class // Left-hand expression could not be resolved to a class
return null; return null;
} else { } else {
// var_dump("AAAHHHHH");
$classFqn = substr((string)$varType->getFqsen(), 1); $classFqn = substr((string)$varType->getFqsen(), 1);
// TODO // TODO

View File

@ -45,7 +45,8 @@ class TolerantTreeAnalyzer implements TreeAnalyzerInterface {
// TODO - docblock errors // TODO - docblock errors
foreach ($this->stmts->getDescendantNodes() as $node) { foreach ($this->stmts->getDescendantNodesAndTokens() as $node) {
if ($node instanceof Tolerant\Node) {
$fqn = $definitionResolver::getDefinedFqn($node); $fqn = $definitionResolver::getDefinedFqn($node);
// Only index definitions with an FQN (no variables) // Only index definitions with an FQN (no variables)
if ($fqn === null) { if ($fqn === null) {
@ -54,6 +55,18 @@ class TolerantTreeAnalyzer implements TreeAnalyzerInterface {
$this->definitionNodes[$fqn] = $node; $this->definitionNodes[$fqn] = $node;
$this->definitions[$fqn] = $this->definitionResolver->createDefinitionFromNode($node, $fqn); $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) { foreach ($this->stmts->getDescendantNodes() as $node) {
$parent = $node->parent; $parent = $node->parent;
@ -90,7 +103,7 @@ class TolerantTreeAnalyzer implements TreeAnalyzerInterface {
// Namespaced constant access and function calls also need to register a reference // Namespaced constant access and function calls also need to register a reference
// to the global version because PHP falls back to global at runtime // to the global version because PHP falls back to global at runtime
// http://php.net/manual/en/language.namespaces.fallback.php // http://php.net/manual/en/language.namespaces.fallback.php
if ($definitionResolver::isConstantFetch($node) || if (TolerantDefinitionResolver::isConstantFetch($node) ||
($parent instanceof Tolerant\Node\Expression\CallExpression ($parent instanceof Tolerant\Node\Expression\CallExpression
&& !( && !(
$node instanceof Tolerant\Node\Expression\ScopedPropertyAccessExpression $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() { public function getDiagnostics() {
return $this->diagnostics; return $this->diagnostics ?? [];
} }
private function addReference(string $fqn, Tolerant\Node $node) private function addReference(string $fqn, Tolerant\Node $node)