From 658a27f5a526adb4031c02cc85c765f0d4cfeb4b Mon Sep 17 00:00:00 2001 From: Felix Becker Date: Sat, 8 Oct 2016 13:14:42 +0200 Subject: [PATCH] Add more symbols to symbol test * constants * static properties * static methods --- fixtures/symbols.php | 9 +++ src/NodeVisitors/SymbolFinder.php | 2 +- tests/Server/TextDocumentTest.php | 92 +++++++++++++++++++++++++++---- 3 files changed, 92 insertions(+), 11 deletions(-) diff --git a/fixtures/symbols.php b/fixtures/symbols.php index 03281c5..77dff07 100644 --- a/fixtures/symbols.php +++ b/fixtures/symbols.php @@ -2,10 +2,19 @@ namespace TestNamespace; +const TEST_CONST = 123; + class TestClass { + const TEST_CLASS_CONST = 123; + public static $staticTestProperty; public $testProperty; + public static function staticTestMethod() + { + + } + public function testMethod($testParameter) { $testVariable = 123; diff --git a/src/NodeVisitors/SymbolFinder.php b/src/NodeVisitors/SymbolFinder.php index 31e7c1c..c262043 100644 --- a/src/NodeVisitors/SymbolFinder.php +++ b/src/NodeVisitors/SymbolFinder.php @@ -59,7 +59,7 @@ class SymbolFinder extends NodeVisitorAbstract public function enterNode(Node $node) { $this->nodeStack[] = $node; - $containerName = end($this->nameStack); + $containerName = empty($this->nameStack) ? null : end($this->nameStack); // If we enter a named node, push its name onto name stack. // Else push the current name onto stack. diff --git a/tests/Server/TextDocumentTest.php b/tests/Server/TextDocumentTest.php index 746ded6..17d8031 100644 --- a/tests/Server/TextDocumentTest.php +++ b/tests/Server/TextDocumentTest.php @@ -44,6 +44,24 @@ class TextDocumentTest extends TestCase ], 'containerName' => null ], + [ + 'name' => 'TEST_CONST', + 'kind' => SymbolKind::CONSTANT, + 'location' => [ + 'uri' => 'whatever', + 'range' => [ + 'start' => [ + 'line' => 4, + 'character' => 6 + ], + 'end' => [ + 'line' => 4, + 'character' => 22 + ] + ] + ], + 'containerName' => 'TestNamespace' + ], [ 'name' => 'TestClass', 'kind' => SymbolKind::CLASS_, @@ -51,17 +69,53 @@ class TextDocumentTest extends TestCase 'uri' => 'whatever', 'range' => [ 'start' => [ - 'line' => 4, + 'line' => 6, 'character' => 0 ], 'end' => [ - 'line' => 12, + 'line' => 21, 'character' => 1 ] ] ], 'containerName' => 'TestNamespace' ], + [ + 'name' => 'TEST_CLASS_CONST', + 'kind' => SymbolKind::CONSTANT, + 'location' => [ + 'uri' => 'whatever', + 'range' => [ + 'start' => [ + 'line' => 8, + 'character' => 10 + ], + 'end' => [ + 'line' => 8, + 'character' => 32 + ] + ] + ], + 'containerName' => 'TestNamespace\\TestClass' + ], + [ + 'name' => 'staticTestProperty', + 'kind' => SymbolKind::PROPERTY, + 'location' => [ + 'uri' => 'whatever', + 'range' => [ + 'start' => [ + 'line' => 9, + 'character' => 18 + ], + 'end' => [ + 'line' => 9, + 'character' => 37 + ] + ] + ], + 'containerName' => 'TestNamespace\\TestClass' + ], [ 'name' => 'testProperty', 'kind' => SymbolKind::PROPERTY, @@ -69,17 +123,35 @@ class TextDocumentTest extends TestCase 'uri' => 'whatever', 'range' => [ 'start' => [ - 'line' => 6, + 'line' => 10, 'character' => 11 ], 'end' => [ - 'line' => 6, + 'line' => 10, 'character' => 24 ] ] ], 'containerName' => 'TestNamespace\\TestClass' ], + [ + 'name' => 'staticTestMethod', + 'kind' => SymbolKind::METHOD, + 'location' => [ + 'uri' => 'whatever', + 'range' => [ + 'start' => [ + 'line' => 12, + 'character' => 4 + ], + 'end' => [ + 'line' => 15, + 'character' => 5 + ] + ] + ], + 'containerName' => 'TestNamespace\\TestClass' + ], [ 'name' => 'testMethod', 'kind' => SymbolKind::METHOD, @@ -87,11 +159,11 @@ class TextDocumentTest extends TestCase 'uri' => 'whatever', 'range' => [ 'start' => [ - 'line' => 8, + 'line' => 17, 'character' => 4 ], 'end' => [ - 'line' => 11, + 'line' => 20, 'character' => 5 ] ] @@ -105,11 +177,11 @@ class TextDocumentTest extends TestCase 'uri' => 'whatever', 'range' => [ 'start' => [ - 'line' => 14, + 'line' => 23, 'character' => 0 ], 'end' => [ - 'line' => 17, + 'line' => 26, 'character' => 1 ] ] @@ -123,11 +195,11 @@ class TextDocumentTest extends TestCase 'uri' => 'whatever', 'range' => [ 'start' => [ - 'line' => 19, + 'line' => 28, 'character' => 0 ], 'end' => [ - 'line' => 22, + 'line' => 31, 'character' => 1 ] ]