Merge ede87b57a4
into 34d3d2030d
commit
b5c6e2090a
|
@ -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
|
||||||
|
}
|
||||||
|
}
|
|
@ -421,6 +421,10 @@ class DefinitionResolver
|
||||||
{
|
{
|
||||||
if ($expr instanceof Node\Expr\Variable || $expr instanceof Node\Expr\ClosureUse) {
|
if ($expr instanceof Node\Expr\Variable || $expr instanceof Node\Expr\ClosureUse) {
|
||||||
if ($expr instanceof Node\Expr\Variable && $expr->name === 'this') {
|
if ($expr instanceof Node\Expr\Variable && $expr->name === 'this') {
|
||||||
|
$classNode = getClosestNode($expr, Node\Stmt\Class_::class);
|
||||||
|
if ($classNode) {
|
||||||
|
return self::resolveClassNameToType($classNode->namespacedName);
|
||||||
|
}
|
||||||
return new Types\This;
|
return new Types\This;
|
||||||
}
|
}
|
||||||
// Find variable definition
|
// Find variable definition
|
||||||
|
@ -481,6 +485,9 @@ class DefinitionResolver
|
||||||
}
|
}
|
||||||
$def = $this->index->getDefinition($fqn);
|
$def = $this->index->getDefinition($fqn);
|
||||||
if ($def !== null) {
|
if ($def !== null) {
|
||||||
|
if ($def->type instanceof Types\This || $def->type instanceof Types\Self_) {
|
||||||
|
return $this->resolveExpressionNodeToType($expr->var);
|
||||||
|
}
|
||||||
return $def->type;
|
return $def->type;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,7 +57,7 @@ class LanguageServerTest extends TestCase
|
||||||
if ($msg->body->method === 'window/logMessage' && $promise->state === Promise::PENDING) {
|
if ($msg->body->method === 'window/logMessage' && $promise->state === Promise::PENDING) {
|
||||||
if ($msg->body->params->type === MessageType::ERROR) {
|
if ($msg->body->params->type === MessageType::ERROR) {
|
||||||
$promise->reject(new Exception($msg->body->params->message));
|
$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();
|
$promise->fulfill();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -103,7 +103,7 @@ class LanguageServerTest extends TestCase
|
||||||
if ($promise->state === Promise::PENDING) {
|
if ($promise->state === Promise::PENDING) {
|
||||||
$promise->reject(new Exception($msg->body->params->message));
|
$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) {
|
if ($run === 1) {
|
||||||
$run++;
|
$run++;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -433,4 +433,88 @@ class CompletionTest extends TestCase
|
||||||
)
|
)
|
||||||
], true), $items);
|
], 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