1
0
Fork 0

Fix issue #42 and add regression test (#43)

pull/44/head v2.3.1
Stephan Unverwerth 2016-09-30 15:13:54 +02:00 committed by Felix Becker
parent dfc80a5c66
commit 0c758ec815
2 changed files with 72 additions and 0 deletions

View File

@ -73,6 +73,8 @@ class SymbolFinder extends NodeVisitorAbstract
} }
} else { } else {
$this->nameStack[] = $containerName; $this->nameStack[] = $containerName;
// We are not interested in unnamed nodes, return
return;
} }
$class = get_class($node); $class = get_class($node);

70
tests/PhpDocumentTest.php Normal file
View File

@ -0,0 +1,70 @@
<?php
declare(strict_types = 1);
namespace LanguageServer\Tests\Server;
use PHPUnit\Framework\TestCase;
use LanguageServer\Tests\MockProtocolStream;
use LanguageServer\{LanguageClient, Project};
use LanguageServer\Protocol\SymbolKind;
class PhpDocumentTest extends TestCase
{
/**
* @var Project $project
*/
private $project;
public function setUp()
{
$this->project = new Project(new LanguageClient(new MockProtocolStream()));
}
public function testParsesVariableVariables()
{
$document = $this->project->getDocument('whatever');
$document->updateContent("<?php\n$\$a = 'foo';\n\$bar = 'baz';\n");
$symbols = $document->getSymbols();
$this->assertEquals([
[
'name' => 'a',
'kind' => SymbolKind::VARIABLE,
'location' => [
'uri' => 'whatever',
'range' => [
'start' => [
'line' => 1,
'character' => 0
],
'end' => [
'line' => 1,
'character' => 3
]
]
],
'containerName' => null
],
[
'name' => 'bar',
'kind' => SymbolKind::VARIABLE,
'location' => [
'uri' => 'whatever',
'range' => [
'start' => [
'line' => 2,
'character' => 0
],
'end' => [
'line' => 2,
'character' => 4
]
]
],
'containerName' => null
]
], json_decode(json_encode($symbols), true));
}
}