added $this autocompletion
parent
d080c161a9
commit
618f060648
|
@ -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
|
||||
}
|
||||
}
|
|
@ -141,9 +141,17 @@ class CompletionProvider
|
|||
// If the name is an Error node, just filter by the class
|
||||
if ($node instanceof Node\Expr\MethodCall || $node instanceof Node\Expr\PropertyFetch) {
|
||||
// For instances, resolve the variable type
|
||||
$classNode = null;
|
||||
if ($node->var instanceof Node\Expr\Variable && $node->var->name === 'this') {
|
||||
$classNode = getClosestNode($node, Node\Stmt\Class_::class);
|
||||
}
|
||||
if ($classNode !== null && !$classNode->isAnonymous()) {
|
||||
$prefixes = [(string)$classNode->namespacedName];
|
||||
} else {
|
||||
$prefixes = DefinitionResolver::getFqnsFromType(
|
||||
$this->definitionResolver->resolveExpressionNodeToType($node->var)
|
||||
);
|
||||
}
|
||||
} else {
|
||||
// Static member reference
|
||||
$prefixes = [$node->class instanceof Node\Name ? (string)$node->class : ''];
|
||||
|
|
|
@ -57,7 +57,7 @@ class LanguageServerTest extends TestCase
|
|||
if ($msg->body->method === 'window/logMessage' && $promise->state === Promise::PENDING) {
|
||||
if ($msg->body->params->type === MessageType::ERROR) {
|
||||
$promise->reject(new Exception($msg->body->params->message));
|
||||
} else if (strpos($msg->body->params->message, 'All 25 PHP files parsed') !== false) {
|
||||
} else if (strpos($msg->body->params->message, 'All 27 PHP files parsed') !== false) {
|
||||
$promise->fulfill();
|
||||
}
|
||||
}
|
||||
|
@ -103,7 +103,7 @@ class LanguageServerTest extends TestCase
|
|||
if ($promise->state === Promise::PENDING) {
|
||||
$promise->reject(new Exception($msg->body->params->message));
|
||||
}
|
||||
} else if (strpos($msg->body->params->message, 'All 25 PHP files parsed') !== false) {
|
||||
} else if (strpos($msg->body->params->message, 'All 27 PHP files parsed') !== false) {
|
||||
if ($run === 1) {
|
||||
$run++;
|
||||
} else {
|
||||
|
|
|
@ -433,4 +433,88 @@ class CompletionTest extends TestCase
|
|||
)
|
||||
], true), $items);
|
||||
}
|
||||
|
||||
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