1
0
Fork 0

exclude variable symbols.

pull/15/head
Levan Gabeskiria 2016-09-08 22:19:36 +04:00
parent 7138088b4f
commit 347cfae7c0
3 changed files with 22 additions and 23 deletions

1
.gitignore vendored
View File

@ -1,4 +1,5 @@
.DS_Store .DS_Store
.vscode .vscode
.idea
vendor/ vendor/
composer.lock composer.lock

View File

@ -21,7 +21,7 @@ class SymbolFinder extends NodeVisitorAbstract
]; ];
/** /**
* @var LanguageServer\Protocol\SymbolInformation[] * @var \LanguageServer\Protocol\SymbolInformation[]
*/ */
public $symbols; public $symbols;
@ -44,8 +44,24 @@ class SymbolFinder extends NodeVisitorAbstract
{ {
$class = get_class($node); $class = get_class($node);
if (!isset(self::NODE_SYMBOL_KIND_MAP[$class])) { if (!isset(self::NODE_SYMBOL_KIND_MAP[$class])) {
return; return;
}
$symbol = end($this->symbols);
$kind = self::NODE_SYMBOL_KIND_MAP[$class];
// exclude variable symbols that are defined in methods and functions.
if ($symbol && $kind === SymbolKind::VARIABLE &&
($symbol->kind === SymbolKind::METHOD || $symbol->kind === SymbolKind::FUNCTION)
) {
if (
$node->getAttribute('startLine') - 1 > $symbol->location->range->start->line &&
$node->getAttribute('endLine') - 1 < $symbol->location->range->end->line
) {
return;
}
} }
$symbol = new SymbolInformation(); $symbol = new SymbolInformation();
$symbol->kind = self::NODE_SYMBOL_KIND_MAP[$class]; $symbol->kind = self::NODE_SYMBOL_KIND_MAP[$class];
$symbol->name = (string)$node->name; $symbol->name = (string)$node->name;

View File

@ -24,7 +24,7 @@ class TextDocumentTest extends TestCase
// Request symbols // Request symbols
$result = $textDocument->documentSymbol(new TextDocumentIdentifier('whatever')); $result = $textDocument->documentSymbol(new TextDocumentIdentifier('whatever'));
$this->assertEquals([ $this->assertEquals([
[ [
'name' => 'TestNamespace', 'name' => 'TestNamespace',
'kind' => SymbolKind::NAMESPACE, 'kind' => SymbolKind::NAMESPACE,
'location' => [ 'location' => [
@ -96,24 +96,6 @@ class TextDocumentTest extends TestCase
], ],
'containerName' => null 'containerName' => null
], ],
[
'name' => 'testVariable',
'kind' => SymbolKind::VARIABLE,
'location' => [
'uri' => 'whatever',
'range' => [
'start' => [
'line' => 10,
'character' => 8
],
'end' => [
'line' => 10,
'character' => 20
]
]
],
'containerName' => null
],
[ [
'name' => 'TestTrait', 'name' => 'TestTrait',
'kind' => SymbolKind::CLASS_, 'kind' => SymbolKind::CLASS_,
@ -197,7 +179,7 @@ class TextDocumentTest extends TestCase
]] ]]
], json_decode(json_encode($args), true)); ], json_decode(json_encode($args), true));
} }
public function testFormatting() public function testFormatting()
{ {
$textDocument = new Server\TextDocument(new LanguageClient(new MockProtocolStream())); $textDocument = new Server\TextDocument(new LanguageClient(new MockProtocolStream()));
@ -208,7 +190,7 @@ class TextDocumentTest extends TestCase
$textDocumentItem->version = 1; $textDocumentItem->version = 1;
$textDocumentItem->text = file_get_contents(__DIR__ . '/../../fixtures/format.php'); $textDocumentItem->text = file_get_contents(__DIR__ . '/../../fixtures/format.php');
$textDocument->didOpen($textDocumentItem); $textDocument->didOpen($textDocumentItem);
// how code should look after formatting // how code should look after formatting
$expected = file_get_contents(__DIR__ . '/../../fixtures/format_expected.php'); $expected = file_get_contents(__DIR__ . '/../../fixtures/format_expected.php');
// Request formatting // Request formatting