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-11-30 21:23:51 +00:00
|
|
|
|
use LanguageServer\Protocol\{
|
|
|
|
|
TextDocumentItem,
|
|
|
|
|
TextDocumentIdentifier,
|
|
|
|
|
SymbolInformation,
|
|
|
|
|
SymbolKind,
|
|
|
|
|
DiagnosticSeverity,
|
|
|
|
|
FormattingOptions,
|
|
|
|
|
Location,
|
|
|
|
|
Range,
|
|
|
|
|
Position
|
|
|
|
|
};
|
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-11-30 21:23:51 +00:00
|
|
|
|
$referencesUri = pathToUri(realpath(__DIR__ . '/../../../fixtures/references.php'));
|
2016-10-24 17:35:37 +00:00
|
|
|
|
// @codingStandardsIgnoreStart
|
2016-09-30 09:30:08 +00:00
|
|
|
|
$this->assertEquals([
|
2016-11-30 21:23:51 +00:00
|
|
|
|
new SymbolInformation('TestNamespace', SymbolKind::NAMESPACE, new Location($referencesUri, new Range(new Position(2, 0), new Position(2, 24))), ''),
|
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'),
|
2016-12-16 00:40:17 +00:00
|
|
|
|
new SymbolInformation('ChildClass', SymbolKind::CLASS_, $this->getDefinitionLocation('TestNamespace\\ChildClass'), 'TestNamespace'),
|
2016-10-18 21:09:51 +00:00
|
|
|
|
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()'), ''),
|
2016-12-16 00:40:17 +00:00
|
|
|
|
new SymbolInformation('ChildClass', SymbolKind::CLASS_, $this->getDefinitionLocation('ChildClass'), ''),
|
2016-11-30 21:23:51 +00:00
|
|
|
|
new SymbolInformation('whatever', SymbolKind::FUNCTION, $this->getDefinitionLocation('whatever()'), ''),
|
|
|
|
|
|
|
|
|
|
new SymbolInformation('SecondTestNamespace', SymbolKind::NAMESPACE, $this->getDefinitionLocation('SecondTestNamespace'), '')
|
2016-10-18 21:09:51 +00:00
|
|
|
|
], $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
|
|
|
|
}
|
|
|
|
|
}
|