From 578ad76530b5ed02e8db9984463837e7ec9cca84 Mon Sep 17 00:00:00 2001 From: jens1o Date: Sun, 9 Apr 2017 21:21:06 +0200 Subject: [PATCH] :rocket: Fix weird results :heart: --- .../completion/constant_with_namespace.php | 2 +- src/Index/Index.php | 13 +++++++++++ src/Protocol/SymbolInformation.php | 23 ++++++++++--------- tests/Server/ServerTestCase.php | 2 +- tests/Server/Workspace/SymbolTest.php | 1 + 5 files changed, 28 insertions(+), 13 deletions(-) diff --git a/fixtures/completion/constant_with_namespace.php b/fixtures/completion/constant_with_namespace.php index 085036d..cade11f 100644 --- a/fixtures/completion/constant_with_namespace.php +++ b/fixtures/completion/constant_with_namespace.php @@ -9,7 +9,7 @@ namespace HELLO { } - \He + \HE } namespace { diff --git a/src/Index/Index.php b/src/Index/Index.php index b753476..73a7a93 100644 --- a/src/Index/Index.php +++ b/src/Index/Index.php @@ -122,6 +122,19 @@ class Index implements ReadableIndex, \Serializable */ public function setDefinition(string $fqn, Definition $definition) { + if($fqn === null) { + try { + throw new \Exception; + } catch(\Exception $e) { + echo PHP_EOL; + var_dump($fqn); + echo PHP_EOL; + var_dump($definition); + echo PHP_EOL; + echo $e->getTraceAsString(); + echo PHP_EOL; + } + } $this->definitions[$fqn] = $definition; $this->emit('definition-added'); } diff --git a/src/Protocol/SymbolInformation.php b/src/Protocol/SymbolInformation.php index c8219fd..5fcb925 100644 --- a/src/Protocol/SymbolInformation.php +++ b/src/Protocol/SymbolInformation.php @@ -50,7 +50,18 @@ class SymbolInformation { $parent = $node->getAttribute('parentNode'); $symbol = new self; - if ($node instanceof Node\Stmt\Class_|| $node instanceof Node\Stmt\Trait_) { + + if ( + $node instanceof Node\Expr\FuncCall + && $node->name instanceof Node\Name + && (string)$node->name === 'define' + && isset($node->args[0]) + && $node->args[0]->value instanceof Node\Scalar\String_ + ) { + // constants with define() + $symbol->kind = SymbolKind::CONSTANT; + $symbol->name = (string)$node->args[0]->value->value; + } elseif ($node instanceof Node\Stmt\Class_|| $node instanceof Node\Stmt\Trait_) { $symbol->kind = SymbolKind::CLASS_; } else if ($node instanceof Node\Stmt\Interface_) { $symbol->kind = SymbolKind::INTERFACE; @@ -84,16 +95,6 @@ class SymbolInformation $symbol->name = $node->var; } else if (isset($node->name)) { $symbol->name = (string)$node->name; - } else if ( - $node instanceof Node\Expr\FuncCall - && $node->name instanceof Node\Name - && (string)$node->name === 'define' - && isset($node->args[0]) - && $node->args[0]->value instanceof Node\Scalar\String_ - ) { - // constants with define() - $symbol->kind = SymbolKind::CONSTANT; - $symbol->name = (string)$node->args[0]->value->value; } else { return null; } diff --git a/tests/Server/ServerTestCase.php b/tests/Server/ServerTestCase.php index 3d312b5..b3adb12 100644 --- a/tests/Server/ServerTestCase.php +++ b/tests/Server/ServerTestCase.php @@ -72,7 +72,7 @@ abstract class ServerTestCase extends TestCase $this->definitionLocations = [ // Global - 'TEST_PROPERTY' => new Location($globalSymbolsUri, new Range(new Position(106, 4), new Position(106, 31))), + 'TEST_PROPERTY' => new Location($globalSymbolsUri, new Range(new Position(106, 0), new Position(106, 30))), 'TEST_CONST' => new Location($globalSymbolsUri, new Range(new Position( 9, 6), new Position( 9, 22))), 'TestClass' => new Location($globalSymbolsUri, new Range(new Position(20, 0), new Position(61, 1))), 'ChildClass' => new Location($globalSymbolsUri, new Range(new Position(99, 0), new Position(99, 37))), diff --git a/tests/Server/Workspace/SymbolTest.php b/tests/Server/Workspace/SymbolTest.php index fe7cb02..0327856 100644 --- a/tests/Server/Workspace/SymbolTest.php +++ b/tests/Server/Workspace/SymbolTest.php @@ -55,6 +55,7 @@ class SymbolTest extends ServerTestCase new SymbolInformation('TestInterface', SymbolKind::INTERFACE, $this->getDefinitionLocation('TestInterface'), ''), new SymbolInformation('test_function', SymbolKind::FUNCTION, $this->getDefinitionLocation('test_function()'), ''), new SymbolInformation('ChildClass', SymbolKind::CLASS_, $this->getDefinitionLocation('ChildClass'), ''), + new SymbolInformation('define', SymbolKind::CONSTANT, $this->getDefinitionLocation('TEST_PROPERTY'), ''), new SymbolInformation('whatever', SymbolKind::FUNCTION, $this->getDefinitionLocation('whatever()'), ''), new SymbolInformation('SecondTestNamespace', SymbolKind::NAMESPACE, $this->getDefinitionLocation('SecondTestNamespace'), '')