Add $this completion (#419)
parent
f97105740d
commit
dae3f2576c
|
@ -0,0 +1,15 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class ThisClass
|
||||||
|
{
|
||||||
|
private $foo;
|
||||||
|
private $bar;
|
||||||
|
|
||||||
|
protected function method()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
public function test()
|
||||||
|
{
|
||||||
|
$this->
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class ThisClassPrefix extends TestClass
|
||||||
|
{
|
||||||
|
private $foo;
|
||||||
|
private $bar;
|
||||||
|
|
||||||
|
protected function method()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
public function test()
|
||||||
|
{
|
||||||
|
$this->m
|
||||||
|
}
|
||||||
|
}
|
|
@ -574,8 +574,9 @@ class DefinitionResolver
|
||||||
// $this -> Type\this
|
// $this -> Type\this
|
||||||
// $myVariable -> type of corresponding assignment expression
|
// $myVariable -> type of corresponding assignment expression
|
||||||
if ($expr instanceof Node\Expression\Variable || $expr instanceof Node\UseVariableName) {
|
if ($expr instanceof Node\Expression\Variable || $expr instanceof Node\UseVariableName) {
|
||||||
|
// TODO: this will need to change when fluent interfaces are supported
|
||||||
if ($expr->getName() === 'this') {
|
if ($expr->getName() === 'this') {
|
||||||
return new Types\This;
|
return new Types\Object_(new Fqsen('\\' . $this->getContainingClassFqn($expr)));
|
||||||
}
|
}
|
||||||
// Find variable definition (parameter or assignment expression)
|
// Find variable definition (parameter or assignment expression)
|
||||||
$defNode = $this->resolveVariableToNode($expr);
|
$defNode = $this->resolveVariableToNode($expr);
|
||||||
|
|
|
@ -569,4 +569,88 @@ class CompletionTest extends TestCase
|
||||||
|
|
||||||
$this->assertEquals($subsetList->isIncomplete, $list->isIncomplete);
|
$this->assertEquals($subsetList->isIncomplete, $list->isIncomplete);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testThisWithoutPrefix()
|
||||||
|
{
|
||||||
|
$completionUri = pathToUri(__DIR__ . '/../../../fixtures/completion/this.php');
|
||||||
|
$this->loader->open($completionUri, file_get_contents($completionUri));
|
||||||
|
$items = $this->textDocument->completion(
|
||||||
|
new TextDocumentIdentifier($completionUri),
|
||||||
|
new Position(12, 15)
|
||||||
|
)->wait();
|
||||||
|
$this->assertEquals(new CompletionList([
|
||||||
|
new CompletionItem(
|
||||||
|
'foo',
|
||||||
|
CompletionItemKind::PROPERTY,
|
||||||
|
'mixed', // Type of the property
|
||||||
|
null
|
||||||
|
),
|
||||||
|
new CompletionItem(
|
||||||
|
'bar',
|
||||||
|
CompletionItemKind::PROPERTY,
|
||||||
|
'mixed', // Type of the property
|
||||||
|
null
|
||||||
|
),
|
||||||
|
new CompletionItem(
|
||||||
|
'method',
|
||||||
|
CompletionItemKind::METHOD,
|
||||||
|
'mixed', // Return type of the method
|
||||||
|
null
|
||||||
|
),
|
||||||
|
new CompletionItem(
|
||||||
|
'test',
|
||||||
|
CompletionItemKind::METHOD,
|
||||||
|
'mixed', // Return type of the method
|
||||||
|
null
|
||||||
|
)
|
||||||
|
], true), $items);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testThisWithPrefix()
|
||||||
|
{
|
||||||
|
$completionUri = pathToUri(__DIR__ . '/../../../fixtures/completion/this_with_prefix.php');
|
||||||
|
$this->loader->open($completionUri, file_get_contents($completionUri));
|
||||||
|
$items = $this->textDocument->completion(
|
||||||
|
new TextDocumentIdentifier($completionUri),
|
||||||
|
new Position(12, 16)
|
||||||
|
)->wait();
|
||||||
|
$this->assertEquals(new CompletionList([
|
||||||
|
new CompletionItem(
|
||||||
|
'testProperty',
|
||||||
|
CompletionItemKind::PROPERTY,
|
||||||
|
'\TestClass', // Type of the property
|
||||||
|
'Reprehenderit magna velit mollit ipsum do.'
|
||||||
|
),
|
||||||
|
new CompletionItem(
|
||||||
|
'testMethod',
|
||||||
|
CompletionItemKind::METHOD,
|
||||||
|
'\TestClass', // Return type of the method
|
||||||
|
'Non culpa nostrud mollit esse sunt laboris in irure ullamco cupidatat amet.'
|
||||||
|
),
|
||||||
|
new CompletionItem(
|
||||||
|
'foo',
|
||||||
|
CompletionItemKind::PROPERTY,
|
||||||
|
'mixed', // Type of the property
|
||||||
|
null
|
||||||
|
),
|
||||||
|
new CompletionItem(
|
||||||
|
'bar',
|
||||||
|
CompletionItemKind::PROPERTY,
|
||||||
|
'mixed', // Type of the property
|
||||||
|
null
|
||||||
|
),
|
||||||
|
new CompletionItem(
|
||||||
|
'method',
|
||||||
|
CompletionItemKind::METHOD,
|
||||||
|
'mixed', // Return type of the method
|
||||||
|
null
|
||||||
|
),
|
||||||
|
new CompletionItem(
|
||||||
|
'test',
|
||||||
|
CompletionItemKind::METHOD,
|
||||||
|
'mixed', // Return type of the method
|
||||||
|
null
|
||||||
|
)
|
||||||
|
], true), $items);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue