From 4d5052bebd36b84faffd52c2c40e9c785c4a094f Mon Sep 17 00:00:00 2001 From: Levan Gabeskiria Date: Fri, 9 Sep 2016 21:57:28 +0400 Subject: [PATCH] Exclude variable symbols (#16) --- src/SymbolFinder.php | 20 ++++++++++++++++++-- tests/Server/TextDocumentTest.php | 18 ------------------ 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/src/SymbolFinder.php b/src/SymbolFinder.php index 3a489489..6db3a47d 100644 --- a/src/SymbolFinder.php +++ b/src/SymbolFinder.php @@ -23,7 +23,7 @@ class SymbolFinder extends NodeVisitorAbstract /** * @var LanguageServer\Protocol\SymbolInformation[] */ - public $symbols; + public $symbols = []; /** * @var string @@ -46,8 +46,24 @@ public function enterNode(Node $node) if (!isset(self::NODE_SYMBOL_KIND_MAP[$class])) { 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->kind = self::NODE_SYMBOL_KIND_MAP[$class]; + $symbol->kind = $kind; $symbol->name = (string)$node->name; $symbol->location = new Location( $this->uri, diff --git a/tests/Server/TextDocumentTest.php b/tests/Server/TextDocumentTest.php index 509f7c41..697a2bdb 100644 --- a/tests/Server/TextDocumentTest.php +++ b/tests/Server/TextDocumentTest.php @@ -96,24 +96,6 @@ public function testDocumentSymbol() ], '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', 'kind' => SymbolKind::CLASS_,