Skip to content

Commit

Permalink
Exclude variable symbols (felixfbecker#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
lgabeskiria authored and felixfbecker committed Sep 9, 2016
1 parent 2d4ca8f commit 4d5052b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 20 deletions.
20 changes: 18 additions & 2 deletions src/SymbolFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class SymbolFinder extends NodeVisitorAbstract
/**
* @var LanguageServer\Protocol\SymbolInformation[]
*/
public $symbols;
public $symbols = [];

/**
* @var string
Expand All @@ -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,
Expand Down
18 changes: 0 additions & 18 deletions tests/Server/TextDocumentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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_,
Expand Down

0 comments on commit 4d5052b

Please sign in to comment.