2016-09-30 09:30:08 +00:00
|
|
|
|
<?php
|
|
|
|
|
declare(strict_types = 1);
|
|
|
|
|
|
2016-10-11 12:42:56 +00:00
|
|
|
|
namespace LanguageServer\Tests\Server\Workspace;
|
2016-09-30 09:30:08 +00:00
|
|
|
|
|
|
|
|
|
use LanguageServer\Tests\MockProtocolStream;
|
2016-10-18 21:09:51 +00:00
|
|
|
|
use LanguageServer\Tests\Server\ServerTestCase;
|
2016-09-30 09:30:08 +00:00
|
|
|
|
use LanguageServer\{Server, Client, LanguageClient, Project, PhpDocument};
|
2016-10-18 21:09:51 +00:00
|
|
|
|
use LanguageServer\Protocol\{TextDocumentItem, TextDocumentIdentifier, SymbolInformation, SymbolKind, DiagnosticSeverity, FormattingOptions};
|
2016-09-30 09:30:08 +00:00
|
|
|
|
use AdvancedJsonRpc\{Request as RequestBody, Response as ResponseBody};
|
2016-10-11 12:42:56 +00:00
|
|
|
|
use function LanguageServer\pathToUri;
|
2016-09-30 09:30:08 +00:00
|
|
|
|
|
2016-10-18 21:09:51 +00:00
|
|
|
|
class SymbolTest extends ServerTestCase
|
2016-09-30 09:30:08 +00:00
|
|
|
|
{
|
2016-10-09 13:48:08 +00:00
|
|
|
|
public function testEmptyQueryReturnsAllSymbols()
|
2016-09-30 09:30:08 +00:00
|
|
|
|
{
|
|
|
|
|
// Request symbols
|
2016-10-09 13:48:08 +00:00
|
|
|
|
$result = $this->workspace->symbol('');
|
2016-10-24 17:35:37 +00:00
|
|
|
|
// @codingStandardsIgnoreStart
|
2016-09-30 09:30:08 +00:00
|
|
|
|
$this->assertEquals([
|
2016-10-18 21:09:51 +00:00
|
|
|
|
// Namespaced
|
|
|
|
|
new SymbolInformation('TEST_CONST', SymbolKind::CONSTANT, $this->getDefinitionLocation('TestNamespace\\TEST_CONST'), 'TestNamespace'),
|
|
|
|
|
new SymbolInformation('TestClass', SymbolKind::CLASS_, $this->getDefinitionLocation('TestNamespace\\TestClass'), 'TestNamespace'),
|
|
|
|
|
new SymbolInformation('TEST_CLASS_CONST', SymbolKind::CONSTANT, $this->getDefinitionLocation('TestNamespace\\TestClass::TEST_CLASS_CONST'), 'TestNamespace\\TestClass'),
|
2016-10-19 23:53:07 +00:00
|
|
|
|
new SymbolInformation('staticTestProperty', SymbolKind::PROPERTY, $this->getDefinitionLocation('TestNamespace\\TestClass::staticTestProperty'), 'TestNamespace\\TestClass'),
|
|
|
|
|
new SymbolInformation('testProperty', SymbolKind::PROPERTY, $this->getDefinitionLocation('TestNamespace\\TestClass::testProperty'), 'TestNamespace\\TestClass'),
|
2016-10-18 21:09:51 +00:00
|
|
|
|
new SymbolInformation('staticTestMethod', SymbolKind::METHOD, $this->getDefinitionLocation('TestNamespace\\TestClass::staticTestMethod()'), 'TestNamespace\\TestClass'),
|
|
|
|
|
new SymbolInformation('testMethod', SymbolKind::METHOD, $this->getDefinitionLocation('TestNamespace\\TestClass::testMethod()'), 'TestNamespace\\TestClass'),
|
|
|
|
|
new SymbolInformation('TestTrait', SymbolKind::CLASS_, $this->getDefinitionLocation('TestNamespace\\TestTrait'), 'TestNamespace'),
|
|
|
|
|
new SymbolInformation('TestInterface', SymbolKind::INTERFACE, $this->getDefinitionLocation('TestNamespace\\TestInterface'), 'TestNamespace'),
|
|
|
|
|
new SymbolInformation('test_function', SymbolKind::FUNCTION, $this->getDefinitionLocation('TestNamespace\\test_function()'), 'TestNamespace'),
|
|
|
|
|
new SymbolInformation('whatever', SymbolKind::FUNCTION, $this->getDefinitionLocation('TestNamespace\\whatever()'), 'TestNamespace'),
|
|
|
|
|
// Global
|
|
|
|
|
new SymbolInformation('TEST_CONST', SymbolKind::CONSTANT, $this->getDefinitionLocation('TEST_CONST'), ''),
|
|
|
|
|
new SymbolInformation('TestClass', SymbolKind::CLASS_, $this->getDefinitionLocation('TestClass'), ''),
|
|
|
|
|
new SymbolInformation('TEST_CLASS_CONST', SymbolKind::CONSTANT, $this->getDefinitionLocation('TestClass::TEST_CLASS_CONST'), 'TestClass'),
|
2016-10-19 23:53:07 +00:00
|
|
|
|
new SymbolInformation('staticTestProperty', SymbolKind::PROPERTY, $this->getDefinitionLocation('TestClass::staticTestProperty'), 'TestClass'),
|
|
|
|
|
new SymbolInformation('testProperty', SymbolKind::PROPERTY, $this->getDefinitionLocation('TestClass::testProperty'), 'TestClass'),
|
2016-10-18 21:09:51 +00:00
|
|
|
|
new SymbolInformation('staticTestMethod', SymbolKind::METHOD, $this->getDefinitionLocation('TestClass::staticTestMethod()'), 'TestClass'),
|
|
|
|
|
new SymbolInformation('testMethod', SymbolKind::METHOD, $this->getDefinitionLocation('TestClass::testMethod()'), 'TestClass'),
|
|
|
|
|
new SymbolInformation('TestTrait', SymbolKind::CLASS_, $this->getDefinitionLocation('TestTrait'), ''),
|
|
|
|
|
new SymbolInformation('TestInterface', SymbolKind::INTERFACE, $this->getDefinitionLocation('TestInterface'), ''),
|
|
|
|
|
new SymbolInformation('test_function', SymbolKind::FUNCTION, $this->getDefinitionLocation('test_function()'), ''),
|
|
|
|
|
new SymbolInformation('whatever', SymbolKind::FUNCTION, $this->getDefinitionLocation('whatever()'), '')
|
|
|
|
|
], $result);
|
2016-10-24 17:35:37 +00:00
|
|
|
|
// @codingStandardsIgnoreEnd
|
2016-10-09 13:48:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testQueryFiltersResults()
|
|
|
|
|
{
|
|
|
|
|
// Request symbols
|
|
|
|
|
$result = $this->workspace->symbol('testmethod');
|
2016-10-24 17:35:37 +00:00
|
|
|
|
// @codingStandardsIgnoreStart
|
2016-10-09 13:48:08 +00:00
|
|
|
|
$this->assertEquals([
|
2016-10-18 21:09:51 +00:00
|
|
|
|
new SymbolInformation('staticTestMethod', SymbolKind::METHOD, $this->getDefinitionLocation('TestNamespace\\TestClass::staticTestMethod()'), 'TestNamespace\\TestClass'),
|
|
|
|
|
new SymbolInformation('testMethod', SymbolKind::METHOD, $this->getDefinitionLocation('TestNamespace\\TestClass::testMethod()'), 'TestNamespace\\TestClass'),
|
|
|
|
|
new SymbolInformation('staticTestMethod', SymbolKind::METHOD, $this->getDefinitionLocation('TestClass::staticTestMethod()'), 'TestClass'),
|
|
|
|
|
new SymbolInformation('testMethod', SymbolKind::METHOD, $this->getDefinitionLocation('TestClass::testMethod()'), 'TestClass')
|
|
|
|
|
], $result);
|
2016-10-24 17:35:37 +00:00
|
|
|
|
// @codingStandardsIgnoreEnd
|
2016-09-30 09:30:08 +00:00
|
|
|
|
}
|
|
|
|
|
}
|