Handle hover for $this (#249)
parent
d080c161a9
commit
43a91b0d09
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue