Merge 56e2006e30
into 9eea26df71
commit
38e3e4e511
|
@ -587,6 +587,7 @@ class DefinitionResolver
|
||||||
if ($n instanceof Node\Statement\ExpressionStatement) {
|
if ($n instanceof Node\Statement\ExpressionStatement) {
|
||||||
$n = $n->expression;
|
$n = $n->expression;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
// TODO - clean this up
|
// TODO - clean this up
|
||||||
($n instanceof Node\Expression\AssignmentExpression && $n->operator->kind === PhpParser\TokenKind::EqualsToken)
|
($n instanceof Node\Expression\AssignmentExpression && $n->operator->kind === PhpParser\TokenKind::EqualsToken)
|
||||||
|
@ -594,6 +595,14 @@ class DefinitionResolver
|
||||||
) {
|
) {
|
||||||
return $n;
|
return $n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// get variables from foreach statements
|
||||||
|
if (
|
||||||
|
($n instanceof Node\ForeachValue || $n instanceof Node\ForeachKey) &&
|
||||||
|
$n->expression->getName() === $name
|
||||||
|
) {
|
||||||
|
return $n;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} while (isset($n) && $n = $n->parent);
|
} while (isset($n) && $n = $n->parent);
|
||||||
// Return null if nothing was found
|
// Return null if nothing was found
|
||||||
|
@ -1026,6 +1035,11 @@ class DefinitionResolver
|
||||||
return $this->resolveExpressionNodeToType($node->argumentExpressionList->children[2]->expression);
|
return $this->resolveExpressionNodeToType($node->argumentExpressionList->children[2]->expression);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FOREACH KEY VARIABLE
|
||||||
|
if ($node instanceof Node\ForeachKey) {
|
||||||
|
return new Types\Integer;
|
||||||
|
}
|
||||||
|
|
||||||
// PARAMETERS
|
// PARAMETERS
|
||||||
// Get the type of the parameter:
|
// Get the type of the parameter:
|
||||||
// 1. Doc block
|
// 1. Doc block
|
||||||
|
|
|
@ -83,6 +83,8 @@ class SymbolInformation
|
||||||
)
|
)
|
||||||
|| $node instanceof Node\UseVariableName
|
|| $node instanceof Node\UseVariableName
|
||||||
|| $node instanceof Node\Parameter
|
|| $node instanceof Node\Parameter
|
||||||
|
|| $node instanceof Node\ForeachValue
|
||||||
|
|| $node instanceof Node\ForeachKey
|
||||||
) {
|
) {
|
||||||
$symbol->kind = SymbolKind::VARIABLE;
|
$symbol->kind = SymbolKind::VARIABLE;
|
||||||
} else {
|
} else {
|
||||||
|
@ -103,6 +105,8 @@ class SymbolInformation
|
||||||
} else {
|
} else {
|
||||||
$symbol->name = ltrim((string)$node->name->getText($node->getFileContents()), "$");
|
$symbol->name = ltrim((string)$node->name->getText($node->getFileContents()), "$");
|
||||||
}
|
}
|
||||||
|
} else if ($node instanceof Node\ForeachValue || $node instanceof Node\ForeachKey) {
|
||||||
|
$symbol->name = $node->expression->getName();
|
||||||
} else if (isset($node->variableName)) {
|
} else if (isset($node->variableName)) {
|
||||||
$symbol->name = $node->variableName->getText($node);
|
$symbol->name = $node->variableName->getText($node);
|
||||||
} else if (!isset($symbol->name)) {
|
} else if (!isset($symbol->name)) {
|
||||||
|
|
|
@ -312,6 +312,8 @@ class TextDocument
|
||||||
public function hover(TextDocumentIdentifier $textDocument, Position $position): Promise
|
public function hover(TextDocumentIdentifier $textDocument, Position $position): Promise
|
||||||
{
|
{
|
||||||
return coroutine(function () use ($textDocument, $position) {
|
return coroutine(function () use ($textDocument, $position) {
|
||||||
|
$contents = [];
|
||||||
|
|
||||||
$document = yield $this->documentLoader->getOrLoad($textDocument->uri);
|
$document = yield $this->documentLoader->getOrLoad($textDocument->uri);
|
||||||
// Find the node under the cursor
|
// Find the node under the cursor
|
||||||
$node = $document->getNodeAtPosition($position);
|
$node = $document->getNodeAtPosition($position);
|
||||||
|
|
|
@ -62,4 +62,19 @@ class DefinitionResolverTest extends TestCase
|
||||||
|
|
||||||
$this->assertEquals('TEST_DEFINE', $fqn);
|
$this->assertEquals('TEST_DEFINE', $fqn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testGetVaribleFromForeachValue()
|
||||||
|
{
|
||||||
|
$parser = new PhpParser\Parser;
|
||||||
|
$doc = new MockPhpDocument;
|
||||||
|
$sourceFileNode = $parser->parseSourceFile("<?php\nforeach([1, 2] as \$testValue) { echo \$testValue; }", $doc->getUri());
|
||||||
|
|
||||||
|
$index = new Index;
|
||||||
|
|
||||||
|
$definitionResolver = new DefinitionResolver($index);
|
||||||
|
$testValueVariable = $sourceFileNode->statementList[1]->statements->statements[0]->expression->expressions->children[0];
|
||||||
|
$fqn = $definitionResolver->resolveVariableToNode($testValueVariable);
|
||||||
|
|
||||||
|
$this->assertInstanceOf(PhpParser\Node\ForeachValue::class, $fqn);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue