1
0
Fork 0
pull/247/merge
Ivan Bozhanov 2017-02-02 17:51:25 +00:00 committed by GitHub
commit b5c6e2090a
5 changed files with 123 additions and 2 deletions

View File

@ -0,0 +1,15 @@
<?php
class ThisClass
{
private $foo;
private $bar;
protected function method()
{
}
public function test()
{
$this->
}
}

View File

@ -0,0 +1,15 @@
<?php
class ThisClassPrefix extends TestClass
{
private $foo;
private $bar;
protected function method()
{
}
public function test()
{
$this->m
}
}

View File

@ -421,6 +421,10 @@ class DefinitionResolver
{
if ($expr instanceof Node\Expr\Variable || $expr instanceof Node\Expr\ClosureUse) {
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;
}
// Find variable definition
@ -481,6 +485,9 @@ class DefinitionResolver
}
$def = $this->index->getDefinition($fqn);
if ($def !== null) {
if ($def->type instanceof Types\This || $def->type instanceof Types\Self_) {
return $this->resolveExpressionNodeToType($expr->var);
}
return $def->type;
}
}

View File

@ -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 {

View File

@ -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);
}
}