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
.vscode
.idea
vendor/
composer.lock

View File

@ -21,7 +21,7 @@ class SymbolFinder extends NodeVisitorAbstract
];
/**
* @var LanguageServer\Protocol\SymbolInformation[]
* @var \LanguageServer\Protocol\SymbolInformation[]
*/
public $symbols;
@ -44,8 +44,24 @@ class SymbolFinder extends NodeVisitorAbstract
{
$class = get_class($node);
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->kind = self::NODE_SYMBOL_KIND_MAP[$class];
$symbol->name = (string)$node->name;

View File

@ -24,7 +24,7 @@ class TextDocumentTest extends TestCase
// Request symbols
$result = $textDocument->documentSymbol(new TextDocumentIdentifier('whatever'));
$this->assertEquals([
[
[
'name' => 'TestNamespace',
'kind' => SymbolKind::NAMESPACE,
'location' => [
@ -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_,