1
0
Fork 0

Exclude variable symbols (#16)

pull/28/head v2.2.1
Levan Gabeskiria 2016-09-09 21:57:28 +04:00 committed by Felix Becker
parent 2d4ca8f99a
commit 4d5052bebd
2 changed files with 18 additions and 20 deletions

View File

@ -23,7 +23,7 @@ class SymbolFinder extends NodeVisitorAbstract
/**
* @var LanguageServer\Protocol\SymbolInformation[]
*/
public $symbols;
public $symbols = [];
/**
* @var string
@ -46,8 +46,24 @@ class SymbolFinder extends NodeVisitorAbstract
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,

View File

@ -96,24 +96,6 @@ class TextDocumentTest extends TestCase
],
'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_,