From f79fbf823594c66ab0a29ec2a1b68e835bd03a1a Mon Sep 17 00:00:00 2001 From: jens1o Date: Mon, 3 Apr 2017 16:06:25 +0200 Subject: [PATCH] progress... --- .../constant_with_namespace.php} | 9 ++++++--- fixtures/global_symbols.php | 9 +++++++++ src/Protocol/SymbolInformation.php | 5 ++--- tests/LanguageServerTest.php | 4 ++-- tests/Server/ServerTestCase.php | 4 ++++ tests/Server/TextDocument/CompletionTest.php | 17 +++++++++++++++++ tests/Server/TextDocument/HoverTest.php | 14 ++++++++++++++ tests/Server/Workspace/SymbolTest.php | 1 + 8 files changed, 55 insertions(+), 8 deletions(-) rename fixtures/{constant-with-namespace.php => completion/constant_with_namespace.php} (67%) diff --git a/fixtures/constant-with-namespace.php b/fixtures/completion/constant_with_namespace.php similarity index 67% rename from fixtures/constant-with-namespace.php rename to fixtures/completion/constant_with_namespace.php index b91b6e7..8e76089 100644 --- a/fixtures/constant-with-namespace.php +++ b/fixtures/completion/constant_with_namespace.php @@ -9,14 +9,17 @@ namespace HELLO { } - \HELLO; + \HE } namespace { + /** + * Lorem ipsum dolor sit amet. + * + * @var bool + */ define('HELLO', true); - HELLO; - HELLO\world(); } diff --git a/fixtures/global_symbols.php b/fixtures/global_symbols.php index 6494848..87bb3da 100644 --- a/fixtures/global_symbols.php +++ b/fixtures/global_symbols.php @@ -98,3 +98,12 @@ new class { }; class ChildClass extends TestClass {} + +/** + * Lorem ipsum dolor sit amet, consectetur. + * + * @var bool + */ +define('TEST_PROPERTY', false); + +print TEST_PROPERTY ? 'true' : 'false'; diff --git a/src/Protocol/SymbolInformation.php b/src/Protocol/SymbolInformation.php index ee8b84a..c8219fd 100644 --- a/src/Protocol/SymbolInformation.php +++ b/src/Protocol/SymbolInformation.php @@ -84,9 +84,8 @@ class SymbolInformation $symbol->name = $node->var; } else if (isset($node->name)) { $symbol->name = (string)$node->name; - } else if - ( - $node instanceof Node\Expr\FuncCall + } else if ( + $node instanceof Node\Expr\FuncCall && $node->name instanceof Node\Name && (string)$node->name === 'define' && isset($node->args[0]) diff --git a/tests/LanguageServerTest.php b/tests/LanguageServerTest.php index c32a76a..fb52ef6 100644 --- a/tests/LanguageServerTest.php +++ b/tests/LanguageServerTest.php @@ -57,7 +57,7 @@ class LanguageServerTest extends TestCase if ($msg->body->method === 'window/logMessage' && $promise->state === Promise::PENDING) { if ($msg->body->params->type === MessageType::ERROR) { $promise->reject(new Exception($msg->body->params->message)); - } else if (strpos($msg->body->params->message, 'All 26 PHP files parsed') !== false) { + } else if (strpos($msg->body->params->message, 'All 27 PHP files parsed') !== false) { $promise->fulfill(); } } @@ -103,7 +103,7 @@ class LanguageServerTest extends TestCase if ($promise->state === Promise::PENDING) { $promise->reject(new Exception($msg->body->params->message)); } - } else if (strpos($msg->body->params->message, 'All 26 PHP files parsed') !== false) { + } else if (strpos($msg->body->params->message, 'All 27 PHP files parsed') !== false) { $promise->fulfill(); } } diff --git a/tests/Server/ServerTestCase.php b/tests/Server/ServerTestCase.php index 94ba933..3d312b5 100644 --- a/tests/Server/ServerTestCase.php +++ b/tests/Server/ServerTestCase.php @@ -72,6 +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_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))), @@ -160,6 +161,9 @@ abstract class ServerTestCase extends TestCase ], // Global + 'TEST_PROPERTY' => [ + 0 => new Location($globalSymbolsUri, new Range(new Position(108, 6), new Position(108, 19))) + ], 'TEST_CONST' => [ 0 => new Location($referencesUri, new Range(new Position(29, 5), new Position(29, 15))), 1 => new Location($globalReferencesUri, new Range(new Position(29, 5), new Position(29, 15))) diff --git a/tests/Server/TextDocument/CompletionTest.php b/tests/Server/TextDocument/CompletionTest.php index 786fb55..ad9b38d 100644 --- a/tests/Server/TextDocument/CompletionTest.php +++ b/tests/Server/TextDocument/CompletionTest.php @@ -229,6 +229,23 @@ class CompletionTest extends TestCase ], true), $items); } + public function testGlobalConstant() { + $completionUri = pathToUri(__DIR__ . '/../../../fixtures/completion/constant_with_namespace.php'); + $this->loader->open($completionUri, file_get_contents($completionUri)); + $items = $this->textDocument->completion( + new TextDocumentIdentifier($completionUri), + new Position(11, 7) + )->wait(); + + var_dump($items); + $this->assertEquals(new CompletionList([ + new CompletionItem( + 'HELLO', + CompletionItemKind::VARIABLE + ) + ], true), $items); + } + public function testStaticPropertyWithPrefix() { $completionUri = pathToUri(__DIR__ . '/../../../fixtures/completion/static_property_with_prefix.php'); diff --git a/tests/Server/TextDocument/HoverTest.php b/tests/Server/TextDocument/HoverTest.php index cdc1718..5844e12 100644 --- a/tests/Server/TextDocument/HoverTest.php +++ b/tests/Server/TextDocument/HoverTest.php @@ -156,6 +156,20 @@ class HoverTest extends ServerTestCase ], $reference->range), $result); } + public function testHoverForGlobalConstant() { + // HELLO; + // Get hover for HELLO + $reference = $this->getReferenceLocations('TEST_PROPERTY')[0]; + $result = $this->textDocument->hover( + new TextDocumentIdentifier($reference->uri), + $reference->range->end + )->wait(); + $this->assertEquals(new Hover([ + new MarkedString('php', "range), $result); + } + public function testHoverForVariable() { // echo $var; diff --git a/tests/Server/Workspace/SymbolTest.php b/tests/Server/Workspace/SymbolTest.php index d3d13b6..d9b8e3e 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('TEST_PROPERTY', SymbolKind::VARIABLE, $this->getDefinitionLocation('TEST_PROPERTY'), ''), new SymbolInformation('whatever', SymbolKind::FUNCTION, $this->getDefinitionLocation('whatever()'), ''), new SymbolInformation('SecondTestNamespace', SymbolKind::NAMESPACE, $this->getDefinitionLocation('SecondTestNamespace'), '')