1
0
Fork 0

Handle hover for $this (#249)

pull/259/head
Ivan Bozhanov 2017-01-19 16:47:11 +02:00 committed by Felix Becker
parent d080c161a9
commit 43a91b0d09
2 changed files with 16 additions and 0 deletions

View File

@ -144,6 +144,10 @@ class DefinitionResolver
{
// Variables are not indexed globally, as they stay in the file scope anyway
if ($node instanceof Node\Expr\Variable) {
// Resolve $this
if ($node->name === 'this' && $fqn = $this->getContainingClassFqn($node)) {
return $this->index->getDefinition($fqn, false);
}
// Resolve the variable to a definition node (assignment, param or closure use)
$defNode = self::resolveVariableToNode($node);
if ($defNode === null) {

View File

@ -172,4 +172,16 @@ class HoverTest extends ServerTestCase
new Range(new Position(22, 9), new Position(22, 15))
), $result);
}
public function testHoverForThis()
{
// $this;
// Get hover for $this
$uri = pathToUri(realpath(__DIR__ . '/../../../fixtures/global_symbols.php'));
$result = $this->textDocument->hover(new TextDocumentIdentifier($uri), new Position(59, 11))->wait();
$this->assertEquals(new Hover([
new MarkedString('php', "<?php\nclass TestClass implements \\TestInterface"),
'Pariatur ut laborum tempor voluptate consequat ea deserunt.'
], new Range(new Position(59, 8), new Position(59, 13))), $result);
}
}