fix tests
parent
60ed930a50
commit
a5433b211a
|
@ -3,41 +3,46 @@ declare(strict_types = 1);
|
||||||
|
|
||||||
namespace LanguageServer\Tests;
|
namespace LanguageServer\Tests;
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
|
||||||
use LanguageServer\ClientHandler;
|
|
||||||
use LanguageServer\Message;
|
|
||||||
use AdvancedJsonRpc;
|
use AdvancedJsonRpc;
|
||||||
use Sabre\Event\Loop;
|
use Amp\Loop;
|
||||||
|
use LanguageServer\ClientHandler;
|
||||||
|
use LanguageServer\Event\MessageEvent;
|
||||||
|
use LanguageServer\Message;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
class ClientHandlerTest extends TestCase
|
class ClientHandlerTest extends TestCase
|
||||||
{
|
{
|
||||||
public function testRequest()
|
public function testRequest()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
$reader = new MockProtocolStream;
|
$reader = new MockProtocolStream;
|
||||||
$writer = new MockProtocolStream;
|
$writer = new MockProtocolStream;
|
||||||
$handler = new ClientHandler($reader, $writer);
|
$handler = new ClientHandler($reader, $writer);
|
||||||
$writer->once('message', function (Message $msg) use ($reader) {
|
$writer->addOneTimeListener('message', function (MessageEvent $messageEvent) use ($reader) {
|
||||||
|
$msg = $messageEvent->getMessage();
|
||||||
// Respond to request
|
// Respond to request
|
||||||
Loop\setTimeout(function () use ($reader, $msg) {
|
Loop::defer(function () use ($reader, $msg) {
|
||||||
$reader->write(new Message(new AdvancedJsonRpc\SuccessResponse($msg->body->id, 'pong')));
|
yield from $reader->write(new Message(new AdvancedJsonRpc\SuccessResponse($msg->body->id, 'pong')));
|
||||||
}, 0);
|
|
||||||
});
|
});
|
||||||
$handler->request('testMethod', ['ping'])->then(function ($result) {
|
});
|
||||||
|
$result = yield from $handler->request('testMethod', ['ping']);
|
||||||
$this->assertEquals('pong', $result);
|
$this->assertEquals('pong', $result);
|
||||||
})->wait();
|
|
||||||
// No event listeners
|
// No event listeners
|
||||||
$this->assertEquals([], $reader->listeners('message'));
|
$this->assertEquals([], $reader->getListeners('message'));
|
||||||
$this->assertEquals([], $writer->listeners('message'));
|
$this->assertEquals([], $writer->getListeners('message'));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testNotify()
|
public function testNotify()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
$reader = new MockProtocolStream;
|
$reader = new MockProtocolStream;
|
||||||
$writer = new MockProtocolStream;
|
$writer = new MockProtocolStream;
|
||||||
$handler = new ClientHandler($reader, $writer);
|
$handler = new ClientHandler($reader, $writer);
|
||||||
$handler->notify('testMethod', ['ping'])->wait();
|
yield from $handler->notify('testMethod', ['ping']);
|
||||||
// No event listeners
|
// No event listeners
|
||||||
$this->assertEquals([], $reader->listeners('message'));
|
$this->assertEquals([], $reader->getListeners('message'));
|
||||||
$this->assertEquals([], $writer->listeners('message'));
|
$this->assertEquals([], $writer->getListeners('message'));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,33 +3,34 @@ declare(strict_types = 1);
|
||||||
|
|
||||||
namespace LanguageServer\Tests;
|
namespace LanguageServer\Tests;
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use AdvancedJsonRpc;
|
||||||
|
use Amp\Deferred;
|
||||||
|
use Amp\Loop;
|
||||||
|
use Exception;
|
||||||
|
use LanguageServer\Event\MessageEvent;
|
||||||
use LanguageServer\LanguageServer;
|
use LanguageServer\LanguageServer;
|
||||||
use LanguageServer\Message;
|
use LanguageServer\Message;
|
||||||
use LanguageServerProtocol\{
|
use LanguageServerProtocol\{ClientCapabilities,
|
||||||
ClientCapabilities,
|
|
||||||
TextDocumentSyncKind,
|
|
||||||
MessageType,
|
|
||||||
TextDocumentItem,
|
|
||||||
TextDocumentIdentifier,
|
|
||||||
InitializeResult,
|
|
||||||
ServerCapabilities,
|
|
||||||
CompletionOptions,
|
CompletionOptions,
|
||||||
SignatureHelpOptions
|
InitializeResult,
|
||||||
};
|
MessageType,
|
||||||
use AdvancedJsonRpc;
|
ServerCapabilities,
|
||||||
|
SignatureHelpOptions,
|
||||||
|
TextDocumentIdentifier,
|
||||||
|
TextDocumentItem,
|
||||||
|
TextDocumentSyncKind};
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
use Webmozart\Glob\Glob;
|
use Webmozart\Glob\Glob;
|
||||||
use Webmozart\PathUtil\Path;
|
use Webmozart\PathUtil\Path;
|
||||||
use Sabre\Event\Promise;
|
|
||||||
use Exception;
|
|
||||||
use function LanguageServer\pathToUri;
|
use function LanguageServer\pathToUri;
|
||||||
|
|
||||||
class LanguageServerTest extends TestCase
|
class LanguageServerTest extends TestCase
|
||||||
{
|
{
|
||||||
public function testInitialize()
|
public function testInitialize()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
$server = new LanguageServer(new MockProtocolStream, new MockProtocolStream);
|
$server = new LanguageServer(new MockProtocolStream, new MockProtocolStream);
|
||||||
$result = $server->initialize(new ClientCapabilities, __DIR__, getmypid())->wait();
|
$result = yield $server->initialize(new ClientCapabilities, __DIR__, getmypid());
|
||||||
|
|
||||||
$serverCapabilities = new ServerCapabilities();
|
$serverCapabilities = new ServerCapabilities();
|
||||||
$serverCapabilities->textDocumentSync = TextDocumentSyncKind::FULL;
|
$serverCapabilities->textDocumentSync = TextDocumentSyncKind::FULL;
|
||||||
|
@ -48,38 +49,47 @@ class LanguageServerTest extends TestCase
|
||||||
$serverCapabilities->xdependenciesProvider = true;
|
$serverCapabilities->xdependenciesProvider = true;
|
||||||
|
|
||||||
$this->assertEquals(new InitializeResult($serverCapabilities), $result);
|
$this->assertEquals(new InitializeResult($serverCapabilities), $result);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testIndexingWithDirectFileAccess()
|
public function testIndexingWithDirectFileAccess()
|
||||||
{
|
{
|
||||||
$promise = new Promise;
|
Loop::run(function () {
|
||||||
|
$deferred = new Deferred();
|
||||||
$input = new MockProtocolStream;
|
$input = new MockProtocolStream;
|
||||||
$output = new MockProtocolStream;
|
$output = new MockProtocolStream;
|
||||||
$output->on('message', function (Message $msg) use ($promise) {
|
$output->addListener('message', function (MessageEvent $messageEvent) use ($deferred) {
|
||||||
if ($msg->body->method === 'window/logMessage' && $promise->state === Promise::PENDING) {
|
$msg = $messageEvent->getMessage();
|
||||||
|
Loop::defer(function () use ($deferred, $msg) {
|
||||||
|
if ($msg->body->method === 'window/logMessage') {
|
||||||
if ($msg->body->params->type === MessageType::ERROR) {
|
if ($msg->body->params->type === MessageType::ERROR) {
|
||||||
$promise->reject(new Exception($msg->body->params->message));
|
$deferred->fail(new Exception($msg->body->params->message));
|
||||||
} else if (preg_match('/All \d+ PHP files parsed/', $msg->body->params->message)) {
|
} else if (preg_match('/All \d+ PHP files parsed/', $msg->body->params->message)) {
|
||||||
$promise->fulfill();
|
$deferred->resolve(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
});
|
||||||
$server = new LanguageServer($input, $output);
|
$server = new LanguageServer($input, $output);
|
||||||
$capabilities = new ClientCapabilities;
|
$capabilities = new ClientCapabilities;
|
||||||
$server->initialize($capabilities, realpath(__DIR__ . '/../fixtures'), getmypid());
|
yield $server->initialize($capabilities, realpath(__DIR__ . '/../fixtures'), getmypid());
|
||||||
$promise->wait();
|
$this->assertTrue(yield $deferred->promise());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testIndexingWithFilesAndContentRequests()
|
public function testIndexingWithFilesAndContentRequests()
|
||||||
{
|
{
|
||||||
$promise = new Promise;
|
Loop::run(function () {
|
||||||
|
$deferred = new Deferred();
|
||||||
$filesCalled = false;
|
$filesCalled = false;
|
||||||
$contentCalled = false;
|
$contentCalled = false;
|
||||||
$rootPath = realpath(__DIR__ . '/../fixtures');
|
$rootPath = realpath(__DIR__ . '/../fixtures');
|
||||||
$input = new MockProtocolStream;
|
$input = new MockProtocolStream;
|
||||||
$output = new MockProtocolStream;
|
$output = new MockProtocolStream;
|
||||||
$run = 1;
|
$run = 1;
|
||||||
$output->on('message', function (Message $msg) use ($promise, $input, $rootPath, &$filesCalled, &$contentCalled, &$run) {
|
$output->addListener('message', function (MessageEvent $messageEvent) use ($deferred, $input, $rootPath, &$filesCalled, &$contentCalled, &$run) {
|
||||||
|
$msg = $messageEvent->getMessage();
|
||||||
|
Loop::defer(function () use ($msg, $deferred, $input, $rootPath, &$filesCalled, &$contentCalled, &$run) {
|
||||||
if ($msg->body->method === 'textDocument/xcontent') {
|
if ($msg->body->method === 'textDocument/xcontent') {
|
||||||
// Document content requested
|
// Document content requested
|
||||||
$contentCalled = true;
|
$contentCalled = true;
|
||||||
|
@ -88,7 +98,7 @@ class LanguageServerTest extends TestCase
|
||||||
$textDocumentItem->version = 1;
|
$textDocumentItem->version = 1;
|
||||||
$textDocumentItem->languageId = 'php';
|
$textDocumentItem->languageId = 'php';
|
||||||
$textDocumentItem->text = file_get_contents($msg->body->params->textDocument->uri);
|
$textDocumentItem->text = file_get_contents($msg->body->params->textDocument->uri);
|
||||||
$input->write(new Message(new AdvancedJsonRpc\SuccessResponse($msg->body->id, $textDocumentItem)));
|
yield from $input->write(new Message(new AdvancedJsonRpc\SuccessResponse($msg->body->id, $textDocumentItem)));
|
||||||
} else if ($msg->body->method === 'workspace/xfiles') {
|
} else if ($msg->body->method === 'workspace/xfiles') {
|
||||||
// Files requested
|
// Files requested
|
||||||
$filesCalled = true;
|
$filesCalled = true;
|
||||||
|
@ -97,26 +107,26 @@ class LanguageServerTest extends TestCase
|
||||||
foreach (Glob::glob($pattern) as $path) {
|
foreach (Glob::glob($pattern) as $path) {
|
||||||
$files[] = new TextDocumentIdentifier(pathToUri($path));
|
$files[] = new TextDocumentIdentifier(pathToUri($path));
|
||||||
}
|
}
|
||||||
$input->write(new Message(new AdvancedJsonRpc\SuccessResponse($msg->body->id, $files)));
|
yield from $input->write(new Message(new AdvancedJsonRpc\SuccessResponse($msg->body->id, $files)));
|
||||||
} else if ($msg->body->method === 'window/logMessage') {
|
} else if ($msg->body->method === 'window/logMessage') {
|
||||||
// Message logged
|
// Message logged
|
||||||
if ($msg->body->params->type === MessageType::ERROR) {
|
if ($msg->body->params->type === MessageType::ERROR) {
|
||||||
// Error happened during indexing, fail test
|
// Error happened during indexing, fail test
|
||||||
if ($promise->state === Promise::PENDING) {
|
$deferred->fail(new Exception($msg->body->params->message));
|
||||||
$promise->reject(new Exception($msg->body->params->message));
|
|
||||||
}
|
|
||||||
} else if (preg_match('/All \d+ PHP files parsed/', $msg->body->params->message)) {
|
} else if (preg_match('/All \d+ PHP files parsed/', $msg->body->params->message)) {
|
||||||
$promise->fulfill();
|
$deferred->resolve(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
});
|
||||||
$server = new LanguageServer($input, $output);
|
$server = new LanguageServer($input, $output);
|
||||||
$capabilities = new ClientCapabilities;
|
$capabilities = new ClientCapabilities;
|
||||||
$capabilities->xfilesProvider = true;
|
$capabilities->xfilesProvider = true;
|
||||||
$capabilities->xcontentProvider = true;
|
$capabilities->xcontentProvider = true;
|
||||||
$server->initialize($capabilities, $rootPath, getmypid());
|
yield $server->initialize($capabilities, $rootPath, getmypid());
|
||||||
$promise->wait();
|
yield $deferred->promise();
|
||||||
$this->assertTrue($filesCalled);
|
$this->assertTrue($filesCalled);
|
||||||
$this->assertTrue($contentCalled);
|
$this->assertTrue($contentCalled);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,9 +3,13 @@ declare(strict_types = 1);
|
||||||
|
|
||||||
namespace LanguageServer\Tests;
|
namespace LanguageServer\Tests;
|
||||||
|
|
||||||
use LanguageServer\{ProtocolReader, ProtocolWriter};
|
use Amp\Deferred;
|
||||||
|
use Amp\Delayed;
|
||||||
|
use Amp\Loop;
|
||||||
|
use LanguageServer\{Event\MessageEvent, ProtocolReader, ProtocolWriter};
|
||||||
use LanguageServer\Message;
|
use LanguageServer\Message;
|
||||||
use Sabre\Event\{Loop, Emitter, Promise};
|
use League\Event\Emitter;
|
||||||
|
use League\Event\Event;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A fake duplex protocol stream
|
* A fake duplex protocol stream
|
||||||
|
@ -18,11 +22,11 @@ class MockProtocolStream extends Emitter implements ProtocolReader, ProtocolWrit
|
||||||
* @param Message $msg
|
* @param Message $msg
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function write(Message $msg): Promise
|
public function write(Message $msg): \Generator
|
||||||
{
|
{
|
||||||
Loop\nextTick(function () use ($msg) {
|
Loop::defer(function () use ($msg) {
|
||||||
$this->emit('message', [Message::parse((string)$msg)]);
|
$this->emit(new MessageEvent('message', Message::parse((string)$msg)));
|
||||||
});
|
});
|
||||||
return Promise\resolve(null);
|
yield new Delayed(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ declare(strict_types = 1);
|
||||||
|
|
||||||
namespace LanguageServer\Tests\Server;
|
namespace LanguageServer\Tests\Server;
|
||||||
|
|
||||||
|
use Amp\Loop;
|
||||||
use LanguageServer\{
|
use LanguageServer\{
|
||||||
PhpDocument, PhpDocumentLoader, Project, DefinitionResolver
|
PhpDocument, PhpDocumentLoader, Project, DefinitionResolver
|
||||||
};
|
};
|
||||||
|
@ -32,10 +33,12 @@ class PhpDocumentLoaderTest extends TestCase
|
||||||
|
|
||||||
public function testGetOrLoadLoadsDocument()
|
public function testGetOrLoadLoadsDocument()
|
||||||
{
|
{
|
||||||
$document = $this->loader->getOrLoad(pathToUri(__FILE__))->wait();
|
Loop::run(function () {
|
||||||
|
$document = yield from $this->loader->getOrLoad(pathToUri(__FILE__));
|
||||||
|
|
||||||
$this->assertNotNull($document);
|
$this->assertNotNull($document);
|
||||||
$this->assertInstanceOf(PhpDocument::class, $document);
|
$this->assertInstanceOf(PhpDocument::class, $document);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetReturnsOpenedInstance()
|
public function testGetReturnsOpenedInstance()
|
||||||
|
|
|
@ -3,30 +3,47 @@ declare(strict_types = 1);
|
||||||
|
|
||||||
namespace LanguageServer\Tests;
|
namespace LanguageServer\Tests;
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use AdvancedJsonRpc\{Request as RequestBody};
|
||||||
use LanguageServer\{LanguageServer, ProtocolStreamReader, ProtocolStreamWriter};
|
use Amp\ByteStream\ResourceInputStream;
|
||||||
|
use Amp\ByteStream\ResourceOutputStream;
|
||||||
|
use Amp\Deferred;
|
||||||
|
use Amp\Loop;
|
||||||
|
use LanguageServer\{Event\MessageEvent, ProtocolStreamReader};
|
||||||
use LanguageServer\Message;
|
use LanguageServer\Message;
|
||||||
use AdvancedJsonRpc\{Request as RequestBody, Response as ResponseBody};
|
use PHPUnit\Framework\TestCase;
|
||||||
use Sabre\Event\Loop;
|
|
||||||
|
|
||||||
class ProtocolStreamReaderTest extends TestCase
|
class ProtocolStreamReaderTest extends TestCase
|
||||||
{
|
{
|
||||||
|
public function getStreamPair()
|
||||||
|
{
|
||||||
|
$domain = \stripos(PHP_OS, "win") === 0 ? STREAM_PF_INET : STREAM_PF_UNIX;
|
||||||
|
list($left, $right) = @\stream_socket_pair($domain, \STREAM_SOCK_STREAM, \STREAM_IPPROTO_IP);
|
||||||
|
$a = new ResourceOutputStream($left);
|
||||||
|
$b = new ResourceInputStream($right);
|
||||||
|
return [$a, $b];
|
||||||
|
}
|
||||||
|
|
||||||
public function testParsingWorksAndListenerIsCalled()
|
public function testParsingWorksAndListenerIsCalled()
|
||||||
{
|
{
|
||||||
$tmpfile = tempnam('', '');
|
Loop::run(function () {
|
||||||
$writeHandle = fopen($tmpfile, 'w');
|
/** @var ResourceOutputStream $outputStream */
|
||||||
$reader = new ProtocolStreamReader(fopen($tmpfile, 'r'));
|
/** @var ResourceInputStream $inputStream */
|
||||||
$msg = null;
|
list($outputStream, $inputStream) = $this->getStreamPair();
|
||||||
$reader->on('message', function (Message $message) use (&$msg) {
|
|
||||||
$msg = $message;
|
$reader = new ProtocolStreamReader($inputStream);
|
||||||
|
$deferred = new Deferred();
|
||||||
|
$reader->addListener('message', function (MessageEvent $messageEvent) use (&$deferred) {
|
||||||
|
$deferred->resolve($messageEvent->getMessage());
|
||||||
});
|
});
|
||||||
$ret = fwrite($writeHandle, (string)new Message(new RequestBody(1, 'aMethod', ['arg' => 'Hello World'])));
|
|
||||||
Loop\tick();
|
yield $outputStream->write((string)new Message(new RequestBody(1, 'aMethod', ['arg' => 'Hello World'])));
|
||||||
|
$msg = yield $deferred->promise();
|
||||||
$this->assertNotNull($msg);
|
$this->assertNotNull($msg);
|
||||||
$this->assertInstanceOf(Message::class, $msg);
|
$this->assertInstanceOf(Message::class, $msg);
|
||||||
$this->assertInstanceOf(RequestBody::class, $msg->body);
|
$this->assertInstanceOf(RequestBody::class, $msg->body);
|
||||||
$this->assertEquals(1, $msg->body->id);
|
$this->assertEquals(1, $msg->body->id);
|
||||||
$this->assertEquals('aMethod', $msg->body->method);
|
$this->assertEquals('aMethod', $msg->body->method);
|
||||||
$this->assertEquals((object)['arg' => 'Hello World'], $msg->body->params);
|
$this->assertEquals((object)['arg' => 'Hello World'], $msg->body->params);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,35 +0,0 @@
|
||||||
<?php
|
|
||||||
declare(strict_types = 1);
|
|
||||||
|
|
||||||
namespace LanguageServer\Tests;
|
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
|
||||||
use LanguageServer\ProtocolStreamWriter;
|
|
||||||
use LanguageServer\Message;
|
|
||||||
use AdvancedJsonRpc\{Request as RequestBody};
|
|
||||||
use Sabre\Event\Loop;
|
|
||||||
|
|
||||||
class ProtocolStreamWriterTest extends TestCase
|
|
||||||
{
|
|
||||||
public function testLargeMessageIsSent()
|
|
||||||
{
|
|
||||||
$tmpfile = tempnam('', '');
|
|
||||||
$writeHandle = fopen($tmpfile, 'w');
|
|
||||||
|
|
||||||
stream_set_blocking($writeHandle, false);
|
|
||||||
|
|
||||||
$writer = new ProtocolStreamWriter($writeHandle);
|
|
||||||
$msg = new Message(new RequestBody(1, 'aMethod', ['arg' => str_repeat('X', 100000)]));
|
|
||||||
$msgString = (string)$msg;
|
|
||||||
|
|
||||||
$promise = $writer->write($msg);
|
|
||||||
|
|
||||||
Loop\tick();
|
|
||||||
|
|
||||||
$promise->wait();
|
|
||||||
|
|
||||||
fclose($writeHandle);
|
|
||||||
|
|
||||||
$this->assertEquals(strlen($msgString), filesize($tmpfile));
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -3,6 +3,7 @@ declare(strict_types = 1);
|
||||||
|
|
||||||
namespace LanguageServer\Tests\Server;
|
namespace LanguageServer\Tests\Server;
|
||||||
|
|
||||||
|
use Amp\Loop;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use LanguageServer\Tests\MockProtocolStream;
|
use LanguageServer\Tests\MockProtocolStream;
|
||||||
use LanguageServer\{
|
use LanguageServer\{
|
||||||
|
@ -46,6 +47,7 @@ abstract class ServerTestCase extends TestCase
|
||||||
|
|
||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
$sourceIndex = new Index;
|
$sourceIndex = new Index;
|
||||||
$dependenciesIndex = new DependenciesIndex;
|
$dependenciesIndex = new DependenciesIndex;
|
||||||
$projectIndex = new ProjectIndex($sourceIndex, $dependenciesIndex);
|
$projectIndex = new ProjectIndex($sourceIndex, $dependenciesIndex);
|
||||||
|
@ -63,11 +65,11 @@ abstract class ServerTestCase extends TestCase
|
||||||
$referencesUri = pathToUri(realpath(__DIR__ . '/../../fixtures/references.php'));
|
$referencesUri = pathToUri(realpath(__DIR__ . '/../../fixtures/references.php'));
|
||||||
$useUri = pathToUri(realpath(__DIR__ . '/../../fixtures/use.php'));
|
$useUri = pathToUri(realpath(__DIR__ . '/../../fixtures/use.php'));
|
||||||
|
|
||||||
$this->documentLoader->load($symbolsUri)->wait();
|
yield from $this->documentLoader->load($symbolsUri);
|
||||||
$this->documentLoader->load($referencesUri)->wait();
|
yield from $this->documentLoader->load($referencesUri);
|
||||||
$this->documentLoader->load($globalSymbolsUri)->wait();
|
yield from $this->documentLoader->load($globalSymbolsUri);
|
||||||
$this->documentLoader->load($globalReferencesUri)->wait();
|
yield from $this->documentLoader->load($globalReferencesUri);
|
||||||
$this->documentLoader->load($useUri)->wait();
|
yield from $this->documentLoader->load($useUri);
|
||||||
|
|
||||||
// @codingStandardsIgnoreStart
|
// @codingStandardsIgnoreStart
|
||||||
$this->definitionLocations = [
|
$this->definitionLocations = [
|
||||||
|
@ -225,6 +227,7 @@ abstract class ServerTestCase extends TestCase
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
// @codingStandardsIgnoreEnd
|
// @codingStandardsIgnoreEnd
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getDefinitionLocation(string $fqn): Location
|
protected function getDefinitionLocation(string $fqn): Location
|
||||||
|
|
|
@ -3,6 +3,7 @@ declare(strict_types = 1);
|
||||||
|
|
||||||
namespace LanguageServer\Tests\Server\TextDocument;
|
namespace LanguageServer\Tests\Server\TextDocument;
|
||||||
|
|
||||||
|
use Amp\Loop;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use LanguageServer\Tests\MockProtocolStream;
|
use LanguageServer\Tests\MockProtocolStream;
|
||||||
use LanguageServer\{
|
use LanguageServer\{
|
||||||
|
@ -37,14 +38,16 @@ class CompletionTest extends TestCase
|
||||||
|
|
||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
$client = new LanguageClient(new MockProtocolStream, new MockProtocolStream);
|
$client = new LanguageClient(new MockProtocolStream, new MockProtocolStream);
|
||||||
$projectIndex = new ProjectIndex(new Index, new DependenciesIndex);
|
$projectIndex = new ProjectIndex(new Index, new DependenciesIndex);
|
||||||
$definitionResolver = new DefinitionResolver($projectIndex);
|
$definitionResolver = new DefinitionResolver($projectIndex);
|
||||||
$contentRetriever = new FileSystemContentRetriever;
|
$contentRetriever = new FileSystemContentRetriever;
|
||||||
$this->loader = new PhpDocumentLoader($contentRetriever, $projectIndex, $definitionResolver);
|
$this->loader = new PhpDocumentLoader($contentRetriever, $projectIndex, $definitionResolver);
|
||||||
$this->loader->load(pathToUri(__DIR__ . '/../../../fixtures/global_symbols.php'))->wait();
|
yield from $this->loader->load(pathToUri(__DIR__ . '/../../../fixtures/global_symbols.php'));
|
||||||
$this->loader->load(pathToUri(__DIR__ . '/../../../fixtures/symbols.php'))->wait();
|
yield from $this->loader->load(pathToUri(__DIR__ . '/../../../fixtures/symbols.php'));
|
||||||
$this->textDocument = new Server\TextDocument($this->loader, $definitionResolver, $client, $projectIndex);
|
$this->textDocument = new Server\TextDocument($this->loader, $definitionResolver, $client, $projectIndex);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -52,12 +55,13 @@ class CompletionTest extends TestCase
|
||||||
*/
|
*/
|
||||||
public function testPropertyAndMethodWithPrefix()
|
public function testPropertyAndMethodWithPrefix()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
$completionUri = pathToUri(__DIR__ . '/../../../fixtures/completion/property_with_prefix.php');
|
$completionUri = pathToUri(__DIR__ . '/../../../fixtures/completion/property_with_prefix.php');
|
||||||
$this->loader->open($completionUri, file_get_contents($completionUri));
|
$this->loader->open($completionUri, file_get_contents($completionUri));
|
||||||
$items = $this->textDocument->completion(
|
$items = yield $this->textDocument->completion(
|
||||||
new TextDocumentIdentifier($completionUri),
|
new TextDocumentIdentifier($completionUri),
|
||||||
new Position(3, 7)
|
new Position(3, 7)
|
||||||
)->wait();
|
);
|
||||||
$this->assertCompletionsListSubset(new CompletionList([
|
$this->assertCompletionsListSubset(new CompletionList([
|
||||||
new CompletionItem(
|
new CompletionItem(
|
||||||
'testProperty',
|
'testProperty',
|
||||||
|
@ -72,6 +76,7 @@ class CompletionTest extends TestCase
|
||||||
'Non culpa nostrud mollit esse sunt laboris in irure ullamco cupidatat amet.'
|
'Non culpa nostrud mollit esse sunt laboris in irure ullamco cupidatat amet.'
|
||||||
)
|
)
|
||||||
], true), $items);
|
], true), $items);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -79,12 +84,13 @@ class CompletionTest extends TestCase
|
||||||
*/
|
*/
|
||||||
public function testGlobalFunctionInsideNamespaceAndClass()
|
public function testGlobalFunctionInsideNamespaceAndClass()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
$completionUri = pathToUri(__DIR__ . '/../../../fixtures/completion/inside_namespace_and_method.php');
|
$completionUri = pathToUri(__DIR__ . '/../../../fixtures/completion/inside_namespace_and_method.php');
|
||||||
$this->loader->open($completionUri, file_get_contents($completionUri));
|
$this->loader->open($completionUri, file_get_contents($completionUri));
|
||||||
$items = $this->textDocument->completion(
|
$items = yield $this->textDocument->completion(
|
||||||
new TextDocumentIdentifier($completionUri),
|
new TextDocumentIdentifier($completionUri),
|
||||||
new Position(8, 11)
|
new Position(8, 11)
|
||||||
)->wait();
|
);
|
||||||
$this->assertCompletionsListSubset(new CompletionList([
|
$this->assertCompletionsListSubset(new CompletionList([
|
||||||
new CompletionItem(
|
new CompletionItem(
|
||||||
'test_function',
|
'test_function',
|
||||||
|
@ -96,6 +102,7 @@ class CompletionTest extends TestCase
|
||||||
'\test_function'
|
'\test_function'
|
||||||
)
|
)
|
||||||
], true), $items);
|
], true), $items);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -103,12 +110,13 @@ class CompletionTest extends TestCase
|
||||||
*/
|
*/
|
||||||
public function testPropertyAndMethodWithoutPrefix()
|
public function testPropertyAndMethodWithoutPrefix()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
$completionUri = pathToUri(__DIR__ . '/../../../fixtures/completion/property.php');
|
$completionUri = pathToUri(__DIR__ . '/../../../fixtures/completion/property.php');
|
||||||
$this->loader->open($completionUri, file_get_contents($completionUri));
|
$this->loader->open($completionUri, file_get_contents($completionUri));
|
||||||
$items = $this->textDocument->completion(
|
$items = yield $this->textDocument->completion(
|
||||||
new TextDocumentIdentifier($completionUri),
|
new TextDocumentIdentifier($completionUri),
|
||||||
new Position(3, 6)
|
new Position(3, 6)
|
||||||
)->wait();
|
);
|
||||||
$this->assertCompletionsListSubset(new CompletionList([
|
$this->assertCompletionsListSubset(new CompletionList([
|
||||||
new CompletionItem(
|
new CompletionItem(
|
||||||
'testProperty',
|
'testProperty',
|
||||||
|
@ -123,6 +131,7 @@ class CompletionTest extends TestCase
|
||||||
'Non culpa nostrud mollit esse sunt laboris in irure ullamco cupidatat amet.'
|
'Non culpa nostrud mollit esse sunt laboris in irure ullamco cupidatat amet.'
|
||||||
)
|
)
|
||||||
], true), $items);
|
], true), $items);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -130,12 +139,13 @@ class CompletionTest extends TestCase
|
||||||
*/
|
*/
|
||||||
public function testVariable()
|
public function testVariable()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
$completionUri = pathToUri(__DIR__ . '/../../../fixtures/completion/variable.php');
|
$completionUri = pathToUri(__DIR__ . '/../../../fixtures/completion/variable.php');
|
||||||
$this->loader->open($completionUri, file_get_contents($completionUri));
|
$this->loader->open($completionUri, file_get_contents($completionUri));
|
||||||
$items = $this->textDocument->completion(
|
$items = yield $this->textDocument->completion(
|
||||||
new TextDocumentIdentifier($completionUri),
|
new TextDocumentIdentifier($completionUri),
|
||||||
new Position(8, 5)
|
new Position(8, 5)
|
||||||
)->wait();
|
);
|
||||||
$this->assertCompletionsListSubset(new CompletionList([
|
$this->assertCompletionsListSubset(new CompletionList([
|
||||||
new CompletionItem(
|
new CompletionItem(
|
||||||
'$var',
|
'$var',
|
||||||
|
@ -158,6 +168,7 @@ class CompletionTest extends TestCase
|
||||||
new TextEdit(new Range(new Position(8, 5), new Position(8, 5)), 'param')
|
new TextEdit(new Range(new Position(8, 5), new Position(8, 5)), 'param')
|
||||||
)
|
)
|
||||||
], true), $items);
|
], true), $items);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -165,12 +176,13 @@ class CompletionTest extends TestCase
|
||||||
*/
|
*/
|
||||||
public function testVariableWithPrefix()
|
public function testVariableWithPrefix()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
$completionUri = pathToUri(__DIR__ . '/../../../fixtures/completion/variable_with_prefix.php');
|
$completionUri = pathToUri(__DIR__ . '/../../../fixtures/completion/variable_with_prefix.php');
|
||||||
$this->loader->open($completionUri, file_get_contents($completionUri));
|
$this->loader->open($completionUri, file_get_contents($completionUri));
|
||||||
$items = $this->textDocument->completion(
|
$items = yield $this->textDocument->completion(
|
||||||
new TextDocumentIdentifier($completionUri),
|
new TextDocumentIdentifier($completionUri),
|
||||||
new Position(8, 6)
|
new Position(8, 6)
|
||||||
)->wait();
|
);
|
||||||
$this->assertCompletionsListSubset(new CompletionList([
|
$this->assertCompletionsListSubset(new CompletionList([
|
||||||
new CompletionItem(
|
new CompletionItem(
|
||||||
'$param',
|
'$param',
|
||||||
|
@ -183,6 +195,7 @@ class CompletionTest extends TestCase
|
||||||
new TextEdit(new Range(new Position(8, 6), new Position(8, 6)), 'aram')
|
new TextEdit(new Range(new Position(8, 6), new Position(8, 6)), 'aram')
|
||||||
)
|
)
|
||||||
], true), $items);
|
], true), $items);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -190,12 +203,13 @@ class CompletionTest extends TestCase
|
||||||
*/
|
*/
|
||||||
public function testNewInNamespace()
|
public function testNewInNamespace()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
$completionUri = pathToUri(__DIR__ . '/../../../fixtures/completion/used_new.php');
|
$completionUri = pathToUri(__DIR__ . '/../../../fixtures/completion/used_new.php');
|
||||||
$this->loader->open($completionUri, file_get_contents($completionUri));
|
$this->loader->open($completionUri, file_get_contents($completionUri));
|
||||||
$items = $this->textDocument->completion(
|
$items = yield $this->textDocument->completion(
|
||||||
new TextDocumentIdentifier($completionUri),
|
new TextDocumentIdentifier($completionUri),
|
||||||
new Position(6, 10)
|
new Position(6, 10)
|
||||||
)->wait();
|
);
|
||||||
$this->assertCompletionsListSubset(new CompletionList([
|
$this->assertCompletionsListSubset(new CompletionList([
|
||||||
// Global TestClass definition (inserted as \TestClass)
|
// Global TestClass definition (inserted as \TestClass)
|
||||||
new CompletionItem(
|
new CompletionItem(
|
||||||
|
@ -237,6 +251,7 @@ class CompletionTest extends TestCase
|
||||||
'TestClass'
|
'TestClass'
|
||||||
),
|
),
|
||||||
], true), $items);
|
], true), $items);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -244,12 +259,13 @@ class CompletionTest extends TestCase
|
||||||
*/
|
*/
|
||||||
public function testUsedClass()
|
public function testUsedClass()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
$completionUri = pathToUri(__DIR__ . '/../../../fixtures/completion/used_class.php');
|
$completionUri = pathToUri(__DIR__ . '/../../../fixtures/completion/used_class.php');
|
||||||
$this->loader->open($completionUri, file_get_contents($completionUri));
|
$this->loader->open($completionUri, file_get_contents($completionUri));
|
||||||
$items = $this->textDocument->completion(
|
$items = yield $this->textDocument->completion(
|
||||||
new TextDocumentIdentifier($completionUri),
|
new TextDocumentIdentifier($completionUri),
|
||||||
new Position(6, 5)
|
new Position(6, 5)
|
||||||
)->wait();
|
);
|
||||||
$this->assertCompletionsListSubset(new CompletionList([
|
$this->assertCompletionsListSubset(new CompletionList([
|
||||||
new CompletionItem(
|
new CompletionItem(
|
||||||
'TestClass',
|
'TestClass',
|
||||||
|
@ -269,6 +285,7 @@ class CompletionTest extends TestCase
|
||||||
|
|
||||||
$this->assertCompletionsListDoesNotContainLabel('OtherClass', $items);
|
$this->assertCompletionsListDoesNotContainLabel('OtherClass', $items);
|
||||||
$this->assertCompletionsListDoesNotContainLabel('TestInterface', $items);
|
$this->assertCompletionsListDoesNotContainLabel('TestInterface', $items);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -276,12 +293,13 @@ class CompletionTest extends TestCase
|
||||||
*/
|
*/
|
||||||
public function testUsedNamespaceWithPrefix()
|
public function testUsedNamespaceWithPrefix()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
$completionUri = pathToUri(__DIR__ . '/../../../fixtures/completion/used_namespace.php');
|
$completionUri = pathToUri(__DIR__ . '/../../../fixtures/completion/used_namespace.php');
|
||||||
$this->loader->open($completionUri, file_get_contents($completionUri));
|
$this->loader->open($completionUri, file_get_contents($completionUri));
|
||||||
$items = $this->textDocument->completion(
|
$items = yield $this->textDocument->completion(
|
||||||
new TextDocumentIdentifier($completionUri),
|
new TextDocumentIdentifier($completionUri),
|
||||||
new Position(8, 16)
|
new Position(8, 16)
|
||||||
)->wait();
|
);
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
new CompletionList([
|
new CompletionList([
|
||||||
new CompletionItem(
|
new CompletionItem(
|
||||||
|
@ -296,6 +314,7 @@ class CompletionTest extends TestCase
|
||||||
], true),
|
], true),
|
||||||
$items
|
$items
|
||||||
);
|
);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -303,12 +322,13 @@ class CompletionTest extends TestCase
|
||||||
*/
|
*/
|
||||||
public function testUsedNamespaceWithoutPrefix()
|
public function testUsedNamespaceWithoutPrefix()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
$completionUri = pathToUri(__DIR__ . '/../../../fixtures/completion/used_namespace.php');
|
$completionUri = pathToUri(__DIR__ . '/../../../fixtures/completion/used_namespace.php');
|
||||||
$this->loader->open($completionUri, file_get_contents($completionUri));
|
$this->loader->open($completionUri, file_get_contents($completionUri));
|
||||||
$items = $this->textDocument->completion(
|
$items = yield $this->textDocument->completion(
|
||||||
new TextDocumentIdentifier($completionUri),
|
new TextDocumentIdentifier($completionUri),
|
||||||
new Position(9, 15)
|
new Position(9, 15)
|
||||||
)->wait();
|
);
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
new CompletionList([
|
new CompletionList([
|
||||||
new CompletionItem(
|
new CompletionItem(
|
||||||
|
@ -323,6 +343,7 @@ class CompletionTest extends TestCase
|
||||||
], true),
|
], true),
|
||||||
$items
|
$items
|
||||||
);
|
);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -330,12 +351,13 @@ class CompletionTest extends TestCase
|
||||||
*/
|
*/
|
||||||
public function testStaticPropertyWithPrefix()
|
public function testStaticPropertyWithPrefix()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
$completionUri = pathToUri(__DIR__ . '/../../../fixtures/completion/static_property_with_prefix.php');
|
$completionUri = pathToUri(__DIR__ . '/../../../fixtures/completion/static_property_with_prefix.php');
|
||||||
$this->loader->open($completionUri, file_get_contents($completionUri));
|
$this->loader->open($completionUri, file_get_contents($completionUri));
|
||||||
$items = $this->textDocument->completion(
|
$items = yield $this->textDocument->completion(
|
||||||
new TextDocumentIdentifier($completionUri),
|
new TextDocumentIdentifier($completionUri),
|
||||||
new Position(2, 14)
|
new Position(2, 14)
|
||||||
)->wait();
|
);
|
||||||
$this->assertCompletionsListSubset(new CompletionList([
|
$this->assertCompletionsListSubset(new CompletionList([
|
||||||
new CompletionItem(
|
new CompletionItem(
|
||||||
'staticTestProperty',
|
'staticTestProperty',
|
||||||
|
@ -347,6 +369,7 @@ class CompletionTest extends TestCase
|
||||||
'$staticTestProperty'
|
'$staticTestProperty'
|
||||||
)
|
)
|
||||||
], true), $items);
|
], true), $items);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -354,12 +377,13 @@ class CompletionTest extends TestCase
|
||||||
*/
|
*/
|
||||||
public function testStaticWithoutPrefix()
|
public function testStaticWithoutPrefix()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
$completionUri = pathToUri(__DIR__ . '/../../../fixtures/completion/static.php');
|
$completionUri = pathToUri(__DIR__ . '/../../../fixtures/completion/static.php');
|
||||||
$this->loader->open($completionUri, file_get_contents($completionUri));
|
$this->loader->open($completionUri, file_get_contents($completionUri));
|
||||||
$items = $this->textDocument->completion(
|
$items = yield $this->textDocument->completion(
|
||||||
new TextDocumentIdentifier($completionUri),
|
new TextDocumentIdentifier($completionUri),
|
||||||
new Position(2, 11)
|
new Position(2, 11)
|
||||||
)->wait();
|
);
|
||||||
$this->assertCompletionsListSubset(new CompletionList([
|
$this->assertCompletionsListSubset(new CompletionList([
|
||||||
new CompletionItem(
|
new CompletionItem(
|
||||||
'TEST_CLASS_CONST',
|
'TEST_CLASS_CONST',
|
||||||
|
@ -383,6 +407,7 @@ class CompletionTest extends TestCase
|
||||||
'Do magna consequat veniam minim proident eiusmod incididunt aute proident.'
|
'Do magna consequat veniam minim proident eiusmod incididunt aute proident.'
|
||||||
)
|
)
|
||||||
], true), $items);
|
], true), $items);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -390,12 +415,13 @@ class CompletionTest extends TestCase
|
||||||
*/
|
*/
|
||||||
public function testStaticMethodWithPrefix()
|
public function testStaticMethodWithPrefix()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
$completionUri = pathToUri(__DIR__ . '/../../../fixtures/completion/static_method_with_prefix.php');
|
$completionUri = pathToUri(__DIR__ . '/../../../fixtures/completion/static_method_with_prefix.php');
|
||||||
$this->loader->open($completionUri, file_get_contents($completionUri));
|
$this->loader->open($completionUri, file_get_contents($completionUri));
|
||||||
$items = $this->textDocument->completion(
|
$items = yield $this->textDocument->completion(
|
||||||
new TextDocumentIdentifier($completionUri),
|
new TextDocumentIdentifier($completionUri),
|
||||||
new Position(2, 13)
|
new Position(2, 13)
|
||||||
)->wait();
|
);
|
||||||
$this->assertCompletionsListSubset(new CompletionList([
|
$this->assertCompletionsListSubset(new CompletionList([
|
||||||
new CompletionItem(
|
new CompletionItem(
|
||||||
'staticTestMethod',
|
'staticTestMethod',
|
||||||
|
@ -404,6 +430,7 @@ class CompletionTest extends TestCase
|
||||||
'Do magna consequat veniam minim proident eiusmod incididunt aute proident.'
|
'Do magna consequat veniam minim proident eiusmod incididunt aute proident.'
|
||||||
)
|
)
|
||||||
], true), $items);
|
], true), $items);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -411,12 +438,13 @@ class CompletionTest extends TestCase
|
||||||
*/
|
*/
|
||||||
public function testClassConstWithPrefix()
|
public function testClassConstWithPrefix()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
$completionUri = pathToUri(__DIR__ . '/../../../fixtures/completion/class_const_with_prefix.php');
|
$completionUri = pathToUri(__DIR__ . '/../../../fixtures/completion/class_const_with_prefix.php');
|
||||||
$this->loader->open($completionUri, file_get_contents($completionUri));
|
$this->loader->open($completionUri, file_get_contents($completionUri));
|
||||||
$items = $this->textDocument->completion(
|
$items = yield $this->textDocument->completion(
|
||||||
new TextDocumentIdentifier($completionUri),
|
new TextDocumentIdentifier($completionUri),
|
||||||
new Position(2, 13)
|
new Position(2, 13)
|
||||||
)->wait();
|
);
|
||||||
$this->assertCompletionsListSubset(new CompletionList([
|
$this->assertCompletionsListSubset(new CompletionList([
|
||||||
new CompletionItem(
|
new CompletionItem(
|
||||||
'TEST_CLASS_CONST',
|
'TEST_CLASS_CONST',
|
||||||
|
@ -425,6 +453,7 @@ class CompletionTest extends TestCase
|
||||||
'Anim labore veniam consectetur laboris minim quis aute aute esse nulla ad.'
|
'Anim labore veniam consectetur laboris minim quis aute aute esse nulla ad.'
|
||||||
)
|
)
|
||||||
], true), $items);
|
], true), $items);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -432,12 +461,13 @@ class CompletionTest extends TestCase
|
||||||
*/
|
*/
|
||||||
public function testFullyQualifiedClass()
|
public function testFullyQualifiedClass()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
$completionUri = pathToUri(__DIR__ . '/../../../fixtures/completion/fully_qualified_class.php');
|
$completionUri = pathToUri(__DIR__ . '/../../../fixtures/completion/fully_qualified_class.php');
|
||||||
$this->loader->open($completionUri, file_get_contents($completionUri));
|
$this->loader->open($completionUri, file_get_contents($completionUri));
|
||||||
$items = $this->textDocument->completion(
|
$items = yield $this->textDocument->completion(
|
||||||
new TextDocumentIdentifier($completionUri),
|
new TextDocumentIdentifier($completionUri),
|
||||||
new Position(6, 6)
|
new Position(6, 6)
|
||||||
)->wait();
|
);
|
||||||
$this->assertCompletionsListSubset(new CompletionList([
|
$this->assertCompletionsListSubset(new CompletionList([
|
||||||
new CompletionItem(
|
new CompletionItem(
|
||||||
'TestClass',
|
'TestClass',
|
||||||
|
@ -455,6 +485,7 @@ class CompletionTest extends TestCase
|
||||||
foreach ($items->items as $item) {
|
foreach ($items->items as $item) {
|
||||||
$this->assertSame($item->detail, null);
|
$this->assertSame($item->detail, null);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -462,16 +493,18 @@ class CompletionTest extends TestCase
|
||||||
*/
|
*/
|
||||||
public function testKeywords()
|
public function testKeywords()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
$completionUri = pathToUri(__DIR__ . '/../../../fixtures/completion/keywords.php');
|
$completionUri = pathToUri(__DIR__ . '/../../../fixtures/completion/keywords.php');
|
||||||
$this->loader->open($completionUri, file_get_contents($completionUri));
|
$this->loader->open($completionUri, file_get_contents($completionUri));
|
||||||
$items = $this->textDocument->completion(
|
$items = yield $this->textDocument->completion(
|
||||||
new TextDocumentIdentifier($completionUri),
|
new TextDocumentIdentifier($completionUri),
|
||||||
new Position(2, 1)
|
new Position(2, 1)
|
||||||
)->wait();
|
);
|
||||||
$this->assertCompletionsListSubset(new CompletionList([
|
$this->assertCompletionsListSubset(new CompletionList([
|
||||||
new CompletionItem('class', CompletionItemKind::KEYWORD, null, null, null, null, 'class'),
|
new CompletionItem('class', CompletionItemKind::KEYWORD, null, null, null, null, 'class'),
|
||||||
new CompletionItem('clone', CompletionItemKind::KEYWORD, null, null, null, null, 'clone')
|
new CompletionItem('clone', CompletionItemKind::KEYWORD, null, null, null, null, 'clone')
|
||||||
], true), $items);
|
], true), $items);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -479,12 +512,13 @@ class CompletionTest extends TestCase
|
||||||
*/
|
*/
|
||||||
public function testHtmlWithoutPrefix()
|
public function testHtmlWithoutPrefix()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
$completionUri = pathToUri(__DIR__ . '/../../../fixtures/completion/html.php');
|
$completionUri = pathToUri(__DIR__ . '/../../../fixtures/completion/html.php');
|
||||||
$this->loader->open($completionUri, file_get_contents($completionUri));
|
$this->loader->open($completionUri, file_get_contents($completionUri));
|
||||||
$items = $this->textDocument->completion(
|
$items = yield $this->textDocument->completion(
|
||||||
new TextDocumentIdentifier($completionUri),
|
new TextDocumentIdentifier($completionUri),
|
||||||
new Position(0, 0)
|
new Position(0, 0)
|
||||||
)->wait();
|
);
|
||||||
$this->assertCompletionsListSubset(new CompletionList([
|
$this->assertCompletionsListSubset(new CompletionList([
|
||||||
new CompletionItem(
|
new CompletionItem(
|
||||||
'<?php',
|
'<?php',
|
||||||
|
@ -497,6 +531,7 @@ class CompletionTest extends TestCase
|
||||||
new TextEdit(new Range(new Position(0, 0), new Position(0, 0)), '<?php')
|
new TextEdit(new Range(new Position(0, 0), new Position(0, 0)), '<?php')
|
||||||
)
|
)
|
||||||
], true), $items);
|
], true), $items);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -504,14 +539,16 @@ class CompletionTest extends TestCase
|
||||||
*/
|
*/
|
||||||
public function testHtmlWontBeProposedWithoutCompletionContext()
|
public function testHtmlWontBeProposedWithoutCompletionContext()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
$completionUri = pathToUri(__DIR__ . '/../../../fixtures/completion/html_with_prefix.php');
|
$completionUri = pathToUri(__DIR__ . '/../../../fixtures/completion/html_with_prefix.php');
|
||||||
$this->loader->open($completionUri, file_get_contents($completionUri));
|
$this->loader->open($completionUri, file_get_contents($completionUri));
|
||||||
$items = $this->textDocument->completion(
|
$items = yield $this->textDocument->completion(
|
||||||
new TextDocumentIdentifier($completionUri),
|
new TextDocumentIdentifier($completionUri),
|
||||||
new Position(0, 1)
|
new Position(0, 1)
|
||||||
)->wait();
|
);
|
||||||
|
|
||||||
$this->assertEquals(new CompletionList([], true), $items);
|
$this->assertEquals(new CompletionList([], true), $items);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -519,13 +556,14 @@ class CompletionTest extends TestCase
|
||||||
*/
|
*/
|
||||||
public function testHtmlWontBeProposedWithPrefixWithCompletionContext()
|
public function testHtmlWontBeProposedWithPrefixWithCompletionContext()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
$completionUri = pathToUri(__DIR__ . '/../../../fixtures/completion/html_with_prefix.php');
|
$completionUri = pathToUri(__DIR__ . '/../../../fixtures/completion/html_with_prefix.php');
|
||||||
$this->loader->open($completionUri, file_get_contents($completionUri));
|
$this->loader->open($completionUri, file_get_contents($completionUri));
|
||||||
$items = $this->textDocument->completion(
|
$items = yield $this->textDocument->completion(
|
||||||
new TextDocumentIdentifier($completionUri),
|
new TextDocumentIdentifier($completionUri),
|
||||||
new Position(0, 1),
|
new Position(0, 1),
|
||||||
new CompletionContext(CompletionTriggerKind::TRIGGER_CHARACTER, '<')
|
new CompletionContext(CompletionTriggerKind::TRIGGER_CHARACTER, '<')
|
||||||
)->wait();
|
);
|
||||||
|
|
||||||
$this->assertEquals(new CompletionList([
|
$this->assertEquals(new CompletionList([
|
||||||
new CompletionItem(
|
new CompletionItem(
|
||||||
|
@ -539,6 +577,7 @@ class CompletionTest extends TestCase
|
||||||
new TextEdit(new Range(new Position(0, 1), new Position(0, 1)), '?php')
|
new TextEdit(new Range(new Position(0, 1), new Position(0, 1)), '?php')
|
||||||
)
|
)
|
||||||
], true), $items);
|
], true), $items);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -546,14 +585,16 @@ class CompletionTest extends TestCase
|
||||||
*/
|
*/
|
||||||
public function testHtmlPrefixShouldNotTriggerCompletion()
|
public function testHtmlPrefixShouldNotTriggerCompletion()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
$completionUri = pathToUri(__DIR__ . '/../../../fixtures/completion/html_no_completion.php');
|
$completionUri = pathToUri(__DIR__ . '/../../../fixtures/completion/html_no_completion.php');
|
||||||
$this->loader->open($completionUri, file_get_contents($completionUri));
|
$this->loader->open($completionUri, file_get_contents($completionUri));
|
||||||
$items = $this->textDocument->completion(
|
$items = yield $this->textDocument->completion(
|
||||||
new TextDocumentIdentifier($completionUri),
|
new TextDocumentIdentifier($completionUri),
|
||||||
new Position(0, 1),
|
new Position(0, 1),
|
||||||
new CompletionContext(CompletionTriggerKind::TRIGGER_CHARACTER, '>')
|
new CompletionContext(CompletionTriggerKind::TRIGGER_CHARACTER, '>')
|
||||||
)->wait();
|
);
|
||||||
$this->assertEquals(new CompletionList([], true), $items);
|
$this->assertEquals(new CompletionList([], true), $items);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -561,13 +602,14 @@ class CompletionTest extends TestCase
|
||||||
*/
|
*/
|
||||||
public function testHtmlPrefixShouldTriggerCompletionIfManuallyInvoked()
|
public function testHtmlPrefixShouldTriggerCompletionIfManuallyInvoked()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
$completionUri = pathToUri(__DIR__ . '/../../../fixtures/completion/html_no_completion.php');
|
$completionUri = pathToUri(__DIR__ . '/../../../fixtures/completion/html_no_completion.php');
|
||||||
$this->loader->open($completionUri, file_get_contents($completionUri));
|
$this->loader->open($completionUri, file_get_contents($completionUri));
|
||||||
$items = $this->textDocument->completion(
|
$items = yield $this->textDocument->completion(
|
||||||
new TextDocumentIdentifier($completionUri),
|
new TextDocumentIdentifier($completionUri),
|
||||||
new Position(0, 1),
|
new Position(0, 1),
|
||||||
new CompletionContext(CompletionTriggerKind::INVOKED)
|
new CompletionContext(CompletionTriggerKind::INVOKED)
|
||||||
)->wait();
|
);
|
||||||
$this->assertEquals(new CompletionList([
|
$this->assertEquals(new CompletionList([
|
||||||
new CompletionItem(
|
new CompletionItem(
|
||||||
'<?php',
|
'<?php',
|
||||||
|
@ -580,6 +622,7 @@ class CompletionTest extends TestCase
|
||||||
new TextEdit(new Range(new Position(0, 1), new Position(0, 1)), '?php')
|
new TextEdit(new Range(new Position(0, 1), new Position(0, 1)), '?php')
|
||||||
)
|
)
|
||||||
], true), $items);
|
], true), $items);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -587,18 +630,20 @@ class CompletionTest extends TestCase
|
||||||
*/
|
*/
|
||||||
public function testNamespace()
|
public function testNamespace()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
$completionUri = pathToUri(__DIR__ . '/../../../fixtures/completion/namespace.php');
|
$completionUri = pathToUri(__DIR__ . '/../../../fixtures/completion/namespace.php');
|
||||||
$this->loader->open($completionUri, file_get_contents($completionUri));
|
$this->loader->open($completionUri, file_get_contents($completionUri));
|
||||||
$items = $this->textDocument->completion(
|
$items = yield $this->textDocument->completion(
|
||||||
new TextDocumentIdentifier($completionUri),
|
new TextDocumentIdentifier($completionUri),
|
||||||
new Position(4, 6)
|
new Position(4, 6)
|
||||||
)->wait();
|
);
|
||||||
$this->assertCompletionsListSubset(new CompletionList([
|
$this->assertCompletionsListSubset(new CompletionList([
|
||||||
new CompletionItem(
|
new CompletionItem(
|
||||||
'SomeNamespace',
|
'SomeNamespace',
|
||||||
CompletionItemKind::MODULE
|
CompletionItemKind::MODULE
|
||||||
)
|
)
|
||||||
], true), $items);
|
], true), $items);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -606,12 +651,13 @@ class CompletionTest extends TestCase
|
||||||
*/
|
*/
|
||||||
public function testBarePhpVariable()
|
public function testBarePhpVariable()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
$completionUri = pathToUri(__DIR__ . '/../../../fixtures/completion/bare_php.php');
|
$completionUri = pathToUri(__DIR__ . '/../../../fixtures/completion/bare_php.php');
|
||||||
$this->loader->open($completionUri, file_get_contents($completionUri));
|
$this->loader->open($completionUri, file_get_contents($completionUri));
|
||||||
$items = $this->textDocument->completion(
|
$items = yield $this->textDocument->completion(
|
||||||
new TextDocumentIdentifier($completionUri),
|
new TextDocumentIdentifier($completionUri),
|
||||||
new Position(4, 8)
|
new Position(4, 8)
|
||||||
)->wait();
|
);
|
||||||
$this->assertCompletionsListSubset(new CompletionList([
|
$this->assertCompletionsListSubset(new CompletionList([
|
||||||
new CompletionItem(
|
new CompletionItem(
|
||||||
'$abc2',
|
'$abc2',
|
||||||
|
@ -634,6 +680,7 @@ class CompletionTest extends TestCase
|
||||||
new TextEdit(new Range(new Position(4, 8), new Position(4, 8)), 'c')
|
new TextEdit(new Range(new Position(4, 8), new Position(4, 8)), 'c')
|
||||||
)
|
)
|
||||||
], true), $items);
|
], true), $items);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -641,13 +688,15 @@ class CompletionTest extends TestCase
|
||||||
*/
|
*/
|
||||||
public function testForeach(Position $position, array $expectedItems)
|
public function testForeach(Position $position, array $expectedItems)
|
||||||
{
|
{
|
||||||
|
Loop::run(function () use ($expectedItems, $position) {
|
||||||
$completionUri = pathToUri(__DIR__ . '/../../../fixtures/completion/foreach.php');
|
$completionUri = pathToUri(__DIR__ . '/../../../fixtures/completion/foreach.php');
|
||||||
$this->loader->open($completionUri, file_get_contents($completionUri));
|
$this->loader->open($completionUri, file_get_contents($completionUri));
|
||||||
$items = $this->textDocument->completion(
|
$items = yield $this->textDocument->completion(
|
||||||
new TextDocumentIdentifier($completionUri),
|
new TextDocumentIdentifier($completionUri),
|
||||||
$position
|
$position
|
||||||
)->wait();
|
);
|
||||||
$this->assertCompletionsListSubset(new CompletionList($expectedItems, true), $items);
|
$this->assertCompletionsListSubset(new CompletionList($expectedItems, true), $items);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function foreachProvider(): array
|
public function foreachProvider(): array
|
||||||
|
@ -793,12 +842,13 @@ class CompletionTest extends TestCase
|
||||||
|
|
||||||
public function testMethodReturnType()
|
public function testMethodReturnType()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
$completionUri = pathToUri(__DIR__ . '/../../../fixtures/completion/method_return_type.php');
|
$completionUri = pathToUri(__DIR__ . '/../../../fixtures/completion/method_return_type.php');
|
||||||
$this->loader->open($completionUri, file_get_contents($completionUri));
|
$this->loader->open($completionUri, file_get_contents($completionUri));
|
||||||
$items = $this->textDocument->completion(
|
$items = yield $this->textDocument->completion(
|
||||||
new TextDocumentIdentifier($completionUri),
|
new TextDocumentIdentifier($completionUri),
|
||||||
new Position(10, 6)
|
new Position(10, 6)
|
||||||
)->wait();
|
);
|
||||||
$this->assertCompletionsListSubset(new CompletionList([
|
$this->assertCompletionsListSubset(new CompletionList([
|
||||||
new CompletionItem(
|
new CompletionItem(
|
||||||
'foo',
|
'foo',
|
||||||
|
@ -811,16 +861,18 @@ class CompletionTest extends TestCase
|
||||||
null
|
null
|
||||||
)
|
)
|
||||||
], true), $items);
|
], true), $items);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testStaticMethodReturnType()
|
public function testStaticMethodReturnType()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
$completionUri = pathToUri(__DIR__ . '/../../../fixtures/completion/static_method_return_type.php');
|
$completionUri = pathToUri(__DIR__ . '/../../../fixtures/completion/static_method_return_type.php');
|
||||||
$this->loader->open($completionUri, file_get_contents($completionUri));
|
$this->loader->open($completionUri, file_get_contents($completionUri));
|
||||||
$items = $this->textDocument->completion(
|
$items = yield $this->textDocument->completion(
|
||||||
new TextDocumentIdentifier($completionUri),
|
new TextDocumentIdentifier($completionUri),
|
||||||
new Position(11, 6)
|
new Position(11, 6)
|
||||||
)->wait();
|
);
|
||||||
$this->assertCompletionsListSubset(new CompletionList([
|
$this->assertCompletionsListSubset(new CompletionList([
|
||||||
new CompletionItem(
|
new CompletionItem(
|
||||||
'bar',
|
'bar',
|
||||||
|
@ -833,6 +885,7 @@ class CompletionTest extends TestCase
|
||||||
null
|
null
|
||||||
)
|
)
|
||||||
], true), $items);
|
], true), $items);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private function assertCompletionsListSubset(CompletionList $subsetList, CompletionList $list)
|
private function assertCompletionsListSubset(CompletionList $subsetList, CompletionList $list)
|
||||||
|
@ -856,12 +909,13 @@ class CompletionTest extends TestCase
|
||||||
*/
|
*/
|
||||||
public function testThisWithoutPrefix()
|
public function testThisWithoutPrefix()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
$completionUri = pathToUri(__DIR__ . '/../../../fixtures/completion/this.php');
|
$completionUri = pathToUri(__DIR__ . '/../../../fixtures/completion/this.php');
|
||||||
$this->loader->open($completionUri, file_get_contents($completionUri));
|
$this->loader->open($completionUri, file_get_contents($completionUri));
|
||||||
$items = $this->textDocument->completion(
|
$items = yield $this->textDocument->completion(
|
||||||
new TextDocumentIdentifier($completionUri),
|
new TextDocumentIdentifier($completionUri),
|
||||||
new Position(12, 15)
|
new Position(12, 15)
|
||||||
)->wait();
|
);
|
||||||
$this->assertEquals(new CompletionList([
|
$this->assertEquals(new CompletionList([
|
||||||
new CompletionItem(
|
new CompletionItem(
|
||||||
'foo',
|
'foo',
|
||||||
|
@ -888,6 +942,7 @@ class CompletionTest extends TestCase
|
||||||
null
|
null
|
||||||
)
|
)
|
||||||
], true), $items);
|
], true), $items);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -895,12 +950,13 @@ class CompletionTest extends TestCase
|
||||||
*/
|
*/
|
||||||
public function testThisWithPrefix()
|
public function testThisWithPrefix()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
$completionUri = pathToUri(__DIR__ . '/../../../fixtures/completion/this_with_prefix.php');
|
$completionUri = pathToUri(__DIR__ . '/../../../fixtures/completion/this_with_prefix.php');
|
||||||
$this->loader->open($completionUri, file_get_contents($completionUri));
|
$this->loader->open($completionUri, file_get_contents($completionUri));
|
||||||
$items = $this->textDocument->completion(
|
$items = yield $this->textDocument->completion(
|
||||||
new TextDocumentIdentifier($completionUri),
|
new TextDocumentIdentifier($completionUri),
|
||||||
new Position(12, 16)
|
new Position(12, 16)
|
||||||
)->wait();
|
);
|
||||||
$this->assertEquals(new CompletionList([
|
$this->assertEquals(new CompletionList([
|
||||||
new CompletionItem(
|
new CompletionItem(
|
||||||
'foo',
|
'foo',
|
||||||
|
@ -939,6 +995,7 @@ class CompletionTest extends TestCase
|
||||||
'Non culpa nostrud mollit esse sunt laboris in irure ullamco cupidatat amet.'
|
'Non culpa nostrud mollit esse sunt laboris in irure ullamco cupidatat amet.'
|
||||||
),
|
),
|
||||||
], true), $items);
|
], true), $items);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -946,12 +1003,13 @@ class CompletionTest extends TestCase
|
||||||
*/
|
*/
|
||||||
public function testThisReturnValue()
|
public function testThisReturnValue()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
$completionUri = pathToUri(__DIR__ . '/../../../fixtures/completion/this_return_value.php');
|
$completionUri = pathToUri(__DIR__ . '/../../../fixtures/completion/this_return_value.php');
|
||||||
$this->loader->open($completionUri, file_get_contents($completionUri));
|
$this->loader->open($completionUri, file_get_contents($completionUri));
|
||||||
$items = $this->textDocument->completion(
|
$items = yield $this->textDocument->completion(
|
||||||
new TextDocumentIdentifier($completionUri),
|
new TextDocumentIdentifier($completionUri),
|
||||||
new Position(17, 23)
|
new Position(17, 23)
|
||||||
)->wait();
|
);
|
||||||
$this->assertEquals(new CompletionList([
|
$this->assertEquals(new CompletionList([
|
||||||
new CompletionItem(
|
new CompletionItem(
|
||||||
'bar',
|
'bar',
|
||||||
|
@ -969,5 +1027,6 @@ class CompletionTest extends TestCase
|
||||||
'$this' // Return type of the method
|
'$this' // Return type of the method
|
||||||
),
|
),
|
||||||
], true), $items);
|
], true), $items);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ declare(strict_types = 1);
|
||||||
|
|
||||||
namespace LanguageServer\Tests\Server\TextDocument\Definition;
|
namespace LanguageServer\Tests\Server\TextDocument\Definition;
|
||||||
|
|
||||||
|
use Amp\Loop;
|
||||||
use LanguageServer\Tests\MockProtocolStream;
|
use LanguageServer\Tests\MockProtocolStream;
|
||||||
use LanguageServer\Tests\Server\ServerTestCase;
|
use LanguageServer\Tests\Server\ServerTestCase;
|
||||||
use LanguageServer\{
|
use LanguageServer\{
|
||||||
|
@ -29,34 +30,40 @@ class GlobalFallbackTest extends ServerTestCase
|
||||||
|
|
||||||
public function testClassDoesNotFallback()
|
public function testClassDoesNotFallback()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
// $obj = new TestClass();
|
// $obj = new TestClass();
|
||||||
// Get definition for TestClass should not fall back to global
|
// Get definition for TestClass should not fall back to global
|
||||||
$result = $this->textDocument->definition(
|
$result = yield $this->textDocument->definition(
|
||||||
new TextDocumentIdentifier('global_fallback'),
|
new TextDocumentIdentifier('global_fallback'),
|
||||||
new Position(9, 16)
|
new Position(9, 16)
|
||||||
)->wait();
|
);
|
||||||
$this->assertEquals([], $result);
|
$this->assertEquals([], $result);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testFallsBackForConstants()
|
public function testFallsBackForConstants()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
// echo TEST_CONST;
|
// echo TEST_CONST;
|
||||||
// Get definition for TEST_CONST
|
// Get definition for TEST_CONST
|
||||||
$result = $this->textDocument->definition(
|
$result = yield $this->textDocument->definition(
|
||||||
new TextDocumentIdentifier('global_fallback'),
|
new TextDocumentIdentifier('global_fallback'),
|
||||||
new Position(6, 10)
|
new Position(6, 10)
|
||||||
)->wait();
|
);
|
||||||
$this->assertEquals(new Location('global_symbols', new Range(new Position(9, 6), new Position(9, 22))), $result);
|
$this->assertEquals(new Location('global_symbols', new Range(new Position(9, 6), new Position(9, 22))), $result);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testFallsBackForFunctions()
|
public function testFallsBackForFunctions()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
// test_function();
|
// test_function();
|
||||||
// Get definition for test_function
|
// Get definition for test_function
|
||||||
$result = $this->textDocument->definition(
|
$result = yield $this->textDocument->definition(
|
||||||
new TextDocumentIdentifier('global_fallback'),
|
new TextDocumentIdentifier('global_fallback'),
|
||||||
new Position(5, 6)
|
new Position(5, 6)
|
||||||
)->wait();
|
);
|
||||||
$this->assertEquals(new Location('global_symbols', new Range(new Position(78, 0), new Position(81, 1))), $result);
|
$this->assertEquals(new Location('global_symbols', new Range(new Position(78, 0), new Position(81, 1))), $result);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ declare(strict_types = 1);
|
||||||
|
|
||||||
namespace LanguageServer\Tests\Server\TextDocument\Definition;
|
namespace LanguageServer\Tests\Server\TextDocument\Definition;
|
||||||
|
|
||||||
|
use Amp\Loop;
|
||||||
use LanguageServer\Tests\Server\ServerTestCase;
|
use LanguageServer\Tests\Server\ServerTestCase;
|
||||||
use LanguageServerProtocol\{TextDocumentIdentifier, Position, Location, Range};
|
use LanguageServerProtocol\{TextDocumentIdentifier, Position, Location, Range};
|
||||||
use function LanguageServer\pathToUri;
|
use function LanguageServer\pathToUri;
|
||||||
|
@ -11,333 +12,389 @@ class GlobalTest extends ServerTestCase
|
||||||
{
|
{
|
||||||
public function testDefinitionFileBeginning()
|
public function testDefinitionFileBeginning()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
// |<?php
|
// |<?php
|
||||||
$result = $this->textDocument->definition(
|
$result = yield $this->textDocument->definition(
|
||||||
new TextDocumentIdentifier(pathToUri(realpath(__DIR__ . '/../../../../fixtures/references.php'))),
|
new TextDocumentIdentifier(pathToUri(realpath(__DIR__ . '/../../../../fixtures/references.php'))),
|
||||||
new Position(0, 0)
|
new Position(0, 0)
|
||||||
)->wait();
|
);
|
||||||
$this->assertEquals([], $result);
|
$this->assertEquals([], $result);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDefinitionEmptyResult()
|
public function testDefinitionEmptyResult()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
// namespace keyword
|
// namespace keyword
|
||||||
$result = $this->textDocument->definition(
|
$result = yield $this->textDocument->definition(
|
||||||
new TextDocumentIdentifier(pathToUri(realpath(__DIR__ . '/../../../../fixtures/references.php'))),
|
new TextDocumentIdentifier(pathToUri(realpath(__DIR__ . '/../../../../fixtures/references.php'))),
|
||||||
new Position(1, 0)
|
new Position(1, 0)
|
||||||
)->wait();
|
);
|
||||||
$this->assertEquals([], $result);
|
$this->assertEquals([], $result);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDefinitionForSelfKeyword()
|
public function testDefinitionForSelfKeyword()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
// echo self::TEST_CLASS_CONST;
|
// echo self::TEST_CLASS_CONST;
|
||||||
// Get definition for self
|
// Get definition for self
|
||||||
$reference = $this->getReferenceLocations('TestClass')[0];
|
$reference = $this->getReferenceLocations('TestClass')[0];
|
||||||
$result = $this->textDocument->definition(
|
$result = yield $this->textDocument->definition(
|
||||||
new TextDocumentIdentifier($reference->uri),
|
new TextDocumentIdentifier($reference->uri),
|
||||||
$reference->range->start
|
$reference->range->start
|
||||||
)->wait();
|
);
|
||||||
$this->assertEquals($this->getDefinitionLocation('TestClass'), $result);
|
$this->assertEquals($this->getDefinitionLocation('TestClass'), $result);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDefinitionForClassLike()
|
public function testDefinitionForClassLike()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
// $obj = new TestClass();
|
// $obj = new TestClass();
|
||||||
// Get definition for TestClass
|
// Get definition for TestClass
|
||||||
$reference = $this->getReferenceLocations('TestClass')[1];
|
$reference = $this->getReferenceLocations('TestClass')[1];
|
||||||
$result = $this->textDocument->definition(
|
$result = yield $this->textDocument->definition(
|
||||||
new TextDocumentIdentifier($reference->uri),
|
new TextDocumentIdentifier($reference->uri),
|
||||||
$reference->range->start
|
$reference->range->start
|
||||||
)->wait();
|
);
|
||||||
$this->assertEquals($this->getDefinitionLocation('TestClass'), $result);
|
$this->assertEquals($this->getDefinitionLocation('TestClass'), $result);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDefinitionForClassOnStaticMethodCall()
|
public function testDefinitionForClassOnStaticMethodCall()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
// TestClass::staticTestMethod();
|
// TestClass::staticTestMethod();
|
||||||
// Get definition for TestClass
|
// Get definition for TestClass
|
||||||
$reference = $this->getReferenceLocations('TestClass')[2];
|
$reference = $this->getReferenceLocations('TestClass')[2];
|
||||||
$result = $this->textDocument->definition(
|
$result = yield $this->textDocument->definition(
|
||||||
new TextDocumentIdentifier($reference->uri),
|
new TextDocumentIdentifier($reference->uri),
|
||||||
$reference->range->start
|
$reference->range->start
|
||||||
)->wait();
|
);
|
||||||
$this->assertEquals($this->getDefinitionLocation('TestClass'), $result);
|
$this->assertEquals($this->getDefinitionLocation('TestClass'), $result);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDefinitionForClassOnStaticPropertyFetch()
|
public function testDefinitionForClassOnStaticPropertyFetch()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
// echo TestClass::$staticTestProperty;
|
// echo TestClass::$staticTestProperty;
|
||||||
// Get definition for TestClass
|
// Get definition for TestClass
|
||||||
$reference = $this->getReferenceLocations('TestClass')[3];
|
$reference = $this->getReferenceLocations('TestClass')[3];
|
||||||
$result = $this->textDocument->definition(
|
$result = yield $this->textDocument->definition(
|
||||||
new TextDocumentIdentifier($reference->uri),
|
new TextDocumentIdentifier($reference->uri),
|
||||||
$reference->range->start
|
$reference->range->start
|
||||||
)->wait();
|
);
|
||||||
$this->assertEquals($this->getDefinitionLocation('TestClass'), $result);
|
$this->assertEquals($this->getDefinitionLocation('TestClass'), $result);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDefinitionForClassOnConstFetch()
|
public function testDefinitionForClassOnConstFetch()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
// TestClass::TEST_CLASS_CONST;
|
// TestClass::TEST_CLASS_CONST;
|
||||||
// Get definition for TestClass
|
// Get definition for TestClass
|
||||||
$reference = $this->getReferenceLocations('TestClass')[4];
|
$reference = $this->getReferenceLocations('TestClass')[4];
|
||||||
$result = $this->textDocument->definition(
|
$result = yield $this->textDocument->definition(
|
||||||
new TextDocumentIdentifier($reference->uri),
|
new TextDocumentIdentifier($reference->uri),
|
||||||
$reference->range->start
|
$reference->range->start
|
||||||
)->wait();
|
);
|
||||||
$this->assertEquals($this->getDefinitionLocation('TestClass'), $result);
|
$this->assertEquals($this->getDefinitionLocation('TestClass'), $result);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDefinitionForImplements()
|
public function testDefinitionForImplements()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
// class TestClass implements TestInterface
|
// class TestClass implements TestInterface
|
||||||
// Get definition for TestInterface
|
// Get definition for TestInterface
|
||||||
$reference = $this->getReferenceLocations('TestInterface')[0];
|
$reference = $this->getReferenceLocations('TestInterface')[0];
|
||||||
$result = $this->textDocument->definition(
|
$result = yield $this->textDocument->definition(
|
||||||
new TextDocumentIdentifier($reference->uri),
|
new TextDocumentIdentifier($reference->uri),
|
||||||
$reference->range->start
|
$reference->range->start
|
||||||
)->wait();
|
);
|
||||||
$this->assertEquals($this->getDefinitionLocation('TestInterface'), $result);
|
$this->assertEquals($this->getDefinitionLocation('TestInterface'), $result);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDefinitionForClassConstants()
|
public function testDefinitionForClassConstants()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
// echo TestClass::TEST_CLASS_CONST;
|
// echo TestClass::TEST_CLASS_CONST;
|
||||||
// Get definition for TEST_CLASS_CONST
|
// Get definition for TEST_CLASS_CONST
|
||||||
$reference = $this->getReferenceLocations('TestClass::TEST_CLASS_CONST')[1];
|
$reference = $this->getReferenceLocations('TestClass::TEST_CLASS_CONST')[1];
|
||||||
$result = $this->textDocument->definition(
|
$result = yield $this->textDocument->definition(
|
||||||
new TextDocumentIdentifier($reference->uri),
|
new TextDocumentIdentifier($reference->uri),
|
||||||
$reference->range->end
|
$reference->range->end
|
||||||
)->wait();
|
);
|
||||||
$this->assertEquals($this->getDefinitionLocation('TestClass::TEST_CLASS_CONST'), $result);
|
$this->assertEquals($this->getDefinitionLocation('TestClass::TEST_CLASS_CONST'), $result);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDefinitionForClassConstantsOnSelf()
|
public function testDefinitionForClassConstantsOnSelf()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
// echo self::TEST_CLASS_CONST;
|
// echo self::TEST_CLASS_CONST;
|
||||||
// Get definition for TEST_CLASS_CONST
|
// Get definition for TEST_CLASS_CONST
|
||||||
$reference = $this->getReferenceLocations('TestClass::TEST_CLASS_CONST')[0];
|
$reference = $this->getReferenceLocations('TestClass::TEST_CLASS_CONST')[0];
|
||||||
$result = $this->textDocument->definition(
|
$result = yield $this->textDocument->definition(
|
||||||
new TextDocumentIdentifier($reference->uri),
|
new TextDocumentIdentifier($reference->uri),
|
||||||
$reference->range->end
|
$reference->range->end
|
||||||
)->wait();
|
);
|
||||||
$this->assertEquals($this->getDefinitionLocation('TestClass::TEST_CLASS_CONST'), $result);
|
$this->assertEquals($this->getDefinitionLocation('TestClass::TEST_CLASS_CONST'), $result);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDefinitionForConstants()
|
public function testDefinitionForConstants()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
// echo TEST_CONST;
|
// echo TEST_CONST;
|
||||||
// Get definition for TEST_CONST
|
// Get definition for TEST_CONST
|
||||||
$reference = $this->getReferenceLocations('TEST_CONST')[1];
|
$reference = $this->getReferenceLocations('TEST_CONST')[1];
|
||||||
$result = $this->textDocument->definition(
|
$result = yield $this->textDocument->definition(
|
||||||
new TextDocumentIdentifier($reference->uri),
|
new TextDocumentIdentifier($reference->uri),
|
||||||
$reference->range->start
|
$reference->range->start
|
||||||
)->wait();
|
);
|
||||||
$this->assertEquals($this->getDefinitionLocation('TEST_CONST'), $result);
|
$this->assertEquals($this->getDefinitionLocation('TEST_CONST'), $result);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDefinitionForStaticMethods()
|
public function testDefinitionForStaticMethods()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
// TestClass::staticTestMethod();
|
// TestClass::staticTestMethod();
|
||||||
// Get definition for staticTestMethod
|
// Get definition for staticTestMethod
|
||||||
$reference = $this->getReferenceLocations('TestClass::staticTestMethod()')[0];
|
$reference = $this->getReferenceLocations('TestClass::staticTestMethod()')[0];
|
||||||
$result = $this->textDocument->definition(
|
$result = yield $this->textDocument->definition(
|
||||||
new TextDocumentIdentifier($reference->uri),
|
new TextDocumentIdentifier($reference->uri),
|
||||||
$reference->range->end
|
$reference->range->end
|
||||||
)->wait();
|
);
|
||||||
$this->assertEquals($this->getDefinitionLocation('TestClass::staticTestMethod()'), $result);
|
$this->assertEquals($this->getDefinitionLocation('TestClass::staticTestMethod()'), $result);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDefinitionForStaticProperties()
|
public function testDefinitionForStaticProperties()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
// echo TestClass::$staticTestProperty;
|
// echo TestClass::$staticTestProperty;
|
||||||
// Get definition for staticTestProperty
|
// Get definition for staticTestProperty
|
||||||
$reference = $this->getReferenceLocations('TestClass::staticTestProperty')[0];
|
$reference = $this->getReferenceLocations('TestClass::staticTestProperty')[0];
|
||||||
$result = $this->textDocument->definition(
|
$result = yield $this->textDocument->definition(
|
||||||
new TextDocumentIdentifier($reference->uri),
|
new TextDocumentIdentifier($reference->uri),
|
||||||
$reference->range->end
|
$reference->range->end
|
||||||
)->wait();
|
);
|
||||||
$this->assertEquals($this->getDefinitionLocation('TestClass::staticTestProperty'), $result);
|
$this->assertEquals($this->getDefinitionLocation('TestClass::staticTestProperty'), $result);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDefinitionForMethods()
|
public function testDefinitionForMethods()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
// $obj->testMethod();
|
// $obj->testMethod();
|
||||||
// Get definition for testMethod
|
// Get definition for testMethod
|
||||||
$reference = $this->getReferenceLocations('TestClass::testMethod()')[0];
|
$reference = $this->getReferenceLocations('TestClass::testMethod()')[0];
|
||||||
$result = $this->textDocument->definition(
|
$result = yield $this->textDocument->definition(
|
||||||
new TextDocumentIdentifier($reference->uri),
|
new TextDocumentIdentifier($reference->uri),
|
||||||
$reference->range->end
|
$reference->range->end
|
||||||
)->wait();
|
);
|
||||||
$this->assertEquals($this->getDefinitionLocation('TestClass::testMethod()'), $result);
|
$this->assertEquals($this->getDefinitionLocation('TestClass::testMethod()'), $result);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDefinitionForMethodOnChildClass()
|
public function testDefinitionForMethodOnChildClass()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
// $child->testMethod();
|
// $child->testMethod();
|
||||||
// Get definition for testMethod
|
// Get definition for testMethod
|
||||||
$reference = $this->getReferenceLocations('TestClass::testMethod()')[2];
|
$reference = $this->getReferenceLocations('TestClass::testMethod()')[2];
|
||||||
$result = $this->textDocument->definition(
|
$result = yield $this->textDocument->definition(
|
||||||
new TextDocumentIdentifier($reference->uri),
|
new TextDocumentIdentifier($reference->uri),
|
||||||
$reference->range->end
|
$reference->range->end
|
||||||
)->wait();
|
);
|
||||||
$this->assertEquals($this->getDefinitionLocation('TestClass::testMethod()'), $result);
|
$this->assertEquals($this->getDefinitionLocation('TestClass::testMethod()'), $result);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDefinitionForProperties()
|
public function testDefinitionForProperties()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
// echo $obj->testProperty;
|
// echo $obj->testProperty;
|
||||||
// Get definition for testProperty
|
// Get definition for testProperty
|
||||||
$reference = $this->getReferenceLocations('TestClass::testProperty')[1];
|
$reference = $this->getReferenceLocations('TestClass::testProperty')[1];
|
||||||
$result = $this->textDocument->definition(
|
$result = yield $this->textDocument->definition(
|
||||||
new TextDocumentIdentifier($reference->uri),
|
new TextDocumentIdentifier($reference->uri),
|
||||||
$reference->range->end
|
$reference->range->end
|
||||||
)->wait();
|
);
|
||||||
$this->assertEquals($this->getDefinitionLocation('TestClass::testProperty'), $result);
|
$this->assertEquals($this->getDefinitionLocation('TestClass::testProperty'), $result);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDefinitionForPropertiesOnThis()
|
public function testDefinitionForPropertiesOnThis()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
// $this->testProperty = $testParameter;
|
// $this->testProperty = $testParameter;
|
||||||
// Get definition for testProperty
|
// Get definition for testProperty
|
||||||
$reference = $this->getReferenceLocations('TestClass::testProperty')[0];
|
$reference = $this->getReferenceLocations('TestClass::testProperty')[0];
|
||||||
$result = $this->textDocument->definition(
|
$result = yield $this->textDocument->definition(
|
||||||
new TextDocumentIdentifier($reference->uri),
|
new TextDocumentIdentifier($reference->uri),
|
||||||
$reference->range->end
|
$reference->range->end
|
||||||
)->wait();
|
);
|
||||||
$this->assertEquals($this->getDefinitionLocation('TestClass::testProperty'), $result);
|
$this->assertEquals($this->getDefinitionLocation('TestClass::testProperty'), $result);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDefinitionForVariables()
|
public function testDefinitionForVariables()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
// echo $var;
|
// echo $var;
|
||||||
// Get definition for $var
|
// Get definition for $var
|
||||||
$uri = pathToUri(realpath(__DIR__ . '/../../../../fixtures/references.php'));
|
$uri = pathToUri(realpath(__DIR__ . '/../../../../fixtures/references.php'));
|
||||||
$result = $this->textDocument->definition(
|
$result = yield $this->textDocument->definition(
|
||||||
new TextDocumentIdentifier($uri),
|
new TextDocumentIdentifier($uri),
|
||||||
new Position(13, 7)
|
new Position(13, 7)
|
||||||
)->wait();
|
);
|
||||||
$this->assertEquals(new Location($uri, new Range(new Position(12, 0), new Position(12, 10))), $result);
|
$this->assertEquals(new Location($uri, new Range(new Position(12, 0), new Position(12, 10))), $result);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDefinitionForParamTypeHints()
|
public function testDefinitionForParamTypeHints()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
// function whatever(TestClass $param) {
|
// function whatever(TestClass $param) {
|
||||||
// Get definition for TestClass
|
// Get definition for TestClass
|
||||||
$reference = $this->getReferenceLocations('TestClass')[5];
|
$reference = $this->getReferenceLocations('TestClass')[5];
|
||||||
$result = $this->textDocument->definition(
|
$result = yield $this->textDocument->definition(
|
||||||
new TextDocumentIdentifier($reference->uri),
|
new TextDocumentIdentifier($reference->uri),
|
||||||
$reference->range->start
|
$reference->range->start
|
||||||
)->wait();
|
);
|
||||||
$this->assertEquals($this->getDefinitionLocation('TestClass'), $result);
|
$this->assertEquals($this->getDefinitionLocation('TestClass'), $result);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDefinitionForReturnTypeHints()
|
public function testDefinitionForReturnTypeHints()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
// function whatever(TestClass $param): TestClass {
|
// function whatever(TestClass $param): TestClass {
|
||||||
// Get definition for TestClass
|
// Get definition for TestClass
|
||||||
$reference = $this->getReferenceLocations('TestClass')[6];
|
$reference = $this->getReferenceLocations('TestClass')[6];
|
||||||
$result = $this->textDocument->definition(
|
$result = yield $this->textDocument->definition(
|
||||||
new TextDocumentIdentifier($reference->uri),
|
new TextDocumentIdentifier($reference->uri),
|
||||||
$reference->range->start
|
$reference->range->start
|
||||||
)->wait();
|
);
|
||||||
$this->assertEquals($this->getDefinitionLocation('TestClass'), $result);
|
$this->assertEquals($this->getDefinitionLocation('TestClass'), $result);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDefinitionForMethodReturnTypeHints()
|
public function testDefinitionForMethodReturnTypeHints()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
// public function testMethod($testParameter): TestInterface
|
// public function testMethod($testParameter): TestInterface
|
||||||
// Get definition for TestInterface
|
// Get definition for TestInterface
|
||||||
$reference = $this->getReferenceLocations('TestInterface')[1];
|
$reference = $this->getReferenceLocations('TestInterface')[1];
|
||||||
$result = $this->textDocument->definition(
|
$result = yield $this->textDocument->definition(
|
||||||
new TextDocumentIdentifier($reference->uri),
|
new TextDocumentIdentifier($reference->uri),
|
||||||
$reference->range->start
|
$reference->range->start
|
||||||
)->wait();
|
);
|
||||||
$this->assertEquals($this->getDefinitionLocation('TestInterface'), $result);
|
$this->assertEquals($this->getDefinitionLocation('TestInterface'), $result);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDefinitionForParams()
|
public function testDefinitionForParams()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
// echo $param;
|
// echo $param;
|
||||||
// Get definition for $param
|
// Get definition for $param
|
||||||
$uri = pathToUri(realpath(__DIR__ . '/../../../../fixtures/references.php'));
|
$uri = pathToUri(realpath(__DIR__ . '/../../../../fixtures/references.php'));
|
||||||
$result = $this->textDocument->definition(
|
$result = yield $this->textDocument->definition(
|
||||||
new TextDocumentIdentifier($uri),
|
new TextDocumentIdentifier($uri),
|
||||||
new Position(22, 13)
|
new Position(22, 13)
|
||||||
)->wait();
|
);
|
||||||
$this->assertEquals(new Location($uri, new Range(new Position(21, 18), new Position(21, 34))), $result);
|
$this->assertEquals(new Location($uri, new Range(new Position(21, 18), new Position(21, 34))), $result);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDefinitionForUsedVariables()
|
public function testDefinitionForUsedVariables()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
// echo $var;
|
// echo $var;
|
||||||
// Get definition for $var
|
// Get definition for $var
|
||||||
$uri = pathToUri(realpath(__DIR__ . '/../../../../fixtures/references.php'));
|
$uri = pathToUri(realpath(__DIR__ . '/../../../../fixtures/references.php'));
|
||||||
$result = $this->textDocument->definition(
|
$result = yield $this->textDocument->definition(
|
||||||
new TextDocumentIdentifier($uri),
|
new TextDocumentIdentifier($uri),
|
||||||
new Position(26, 11)
|
new Position(26, 11)
|
||||||
)->wait();
|
);
|
||||||
$this->assertEquals(new Location($uri, new Range(new Position(25, 22), new Position(25, 26))), $result);
|
$this->assertEquals(new Location($uri, new Range(new Position(25, 22), new Position(25, 26))), $result);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDefinitionForFunctions()
|
public function testDefinitionForFunctions()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
// test_function();
|
// test_function();
|
||||||
// Get definition for test_function
|
// Get definition for test_function
|
||||||
$reference = $this->getReferenceLocations('test_function()')[0];
|
$reference = $this->getReferenceLocations('test_function()')[0];
|
||||||
$result = $this->textDocument->definition(
|
$result = yield $this->textDocument->definition(
|
||||||
new TextDocumentIdentifier($reference->uri),
|
new TextDocumentIdentifier($reference->uri),
|
||||||
$reference->range->start
|
$reference->range->start
|
||||||
)->wait();
|
);
|
||||||
$this->assertEquals($this->getDefinitionLocation('test_function()'), $result);
|
$this->assertEquals($this->getDefinitionLocation('test_function()'), $result);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDefinitionForUseFunctions()
|
public function testDefinitionForUseFunctions()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
// use function test_function;
|
// use function test_function;
|
||||||
// Get definition for test_function
|
// Get definition for test_function
|
||||||
$reference = $this->getReferenceLocations('test_function()')[1];
|
$reference = $this->getReferenceLocations('test_function()')[1];
|
||||||
$result = $this->textDocument->definition(
|
$result = yield $this->textDocument->definition(
|
||||||
new TextDocumentIdentifier($reference->uri),
|
new TextDocumentIdentifier($reference->uri),
|
||||||
$reference->range->start
|
$reference->range->start
|
||||||
)->wait();
|
);
|
||||||
$this->assertEquals($this->getDefinitionLocation('test_function()'), $result);
|
$this->assertEquals($this->getDefinitionLocation('test_function()'), $result);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDefinitionForInstanceOf()
|
public function testDefinitionForInstanceOf()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
// if ($abc instanceof TestInterface) {
|
// if ($abc instanceof TestInterface) {
|
||||||
// Get definition for TestInterface
|
// Get definition for TestInterface
|
||||||
$reference = $this->getReferenceLocations('TestInterface')[2];
|
$reference = $this->getReferenceLocations('TestInterface')[2];
|
||||||
$result = $this->textDocument->definition(
|
$result = yield $this->textDocument->definition(
|
||||||
new TextDocumentIdentifier($reference->uri),
|
new TextDocumentIdentifier($reference->uri),
|
||||||
$reference->range->start
|
$reference->range->start
|
||||||
)->wait();
|
);
|
||||||
$this->assertEquals($this->getDefinitionLocation('TestInterface'), $result);
|
$this->assertEquals($this->getDefinitionLocation('TestInterface'), $result);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDefinitionForNestedMethodCall()
|
public function testDefinitionForNestedMethodCall()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
// $obj->testProperty->testMethod();
|
// $obj->testProperty->testMethod();
|
||||||
// Get definition for testMethod
|
// Get definition for testMethod
|
||||||
$reference = $this->getReferenceLocations('TestClass::testMethod()')[1];
|
$reference = $this->getReferenceLocations('TestClass::testMethod()')[1];
|
||||||
$result = $this->textDocument->definition(
|
$result = yield $this->textDocument->definition(
|
||||||
new TextDocumentIdentifier($reference->uri),
|
new TextDocumentIdentifier($reference->uri),
|
||||||
$reference->range->end
|
$reference->range->end
|
||||||
)->wait();
|
);
|
||||||
$this->assertEquals($this->getDefinitionLocation('TestClass::testMethod()'), $result);
|
$this->assertEquals($this->getDefinitionLocation('TestClass::testMethod()'), $result);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDefinitionForPropertyFetchOnArrayDimFetch()
|
public function testDefinitionForPropertyFetchOnArrayDimFetch()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
// TestClass::$staticTestProperty[123]->testProperty;
|
// TestClass::$staticTestProperty[123]->testProperty;
|
||||||
// Get definition for testProperty
|
// Get definition for testProperty
|
||||||
$reference = $this->getReferenceLocations('TestClass::testProperty')[3];
|
$reference = $this->getReferenceLocations('TestClass::testProperty')[3];
|
||||||
$result = $this->textDocument->definition(
|
$result = yield $this->textDocument->definition(
|
||||||
new TextDocumentIdentifier($reference->uri),
|
new TextDocumentIdentifier($reference->uri),
|
||||||
$reference->range->end
|
$reference->range->end
|
||||||
)->wait();
|
);
|
||||||
$this->assertEquals($this->getDefinitionLocation('TestClass::testProperty'), $result);
|
$this->assertEquals($this->getDefinitionLocation('TestClass::testProperty'), $result);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ declare(strict_types = 1);
|
||||||
|
|
||||||
namespace LanguageServer\Tests\Server\TextDocument\Definition;
|
namespace LanguageServer\Tests\Server\TextDocument\Definition;
|
||||||
|
|
||||||
|
use Amp\Loop;
|
||||||
use LanguageServerProtocol\{TextDocumentIdentifier, Location};
|
use LanguageServerProtocol\{TextDocumentIdentifier, Location};
|
||||||
use function LanguageServer\pathToUri;
|
use function LanguageServer\pathToUri;
|
||||||
|
|
||||||
|
@ -20,37 +21,43 @@ class NamespacedTest extends GlobalTest
|
||||||
|
|
||||||
public function testDefinitionForConstants()
|
public function testDefinitionForConstants()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
// echo TEST_CONST;
|
// echo TEST_CONST;
|
||||||
// Get definition for TEST_CONST
|
// Get definition for TEST_CONST
|
||||||
$reference = $this->getReferenceLocations('TEST_CONST')[0];
|
$reference = $this->getReferenceLocations('TEST_CONST')[0];
|
||||||
$result = $this->textDocument->definition(
|
$result = yield $this->textDocument->definition(
|
||||||
new TextDocumentIdentifier($reference->uri),
|
new TextDocumentIdentifier($reference->uri),
|
||||||
$reference->range->start
|
$reference->range->start
|
||||||
)->wait();
|
);
|
||||||
$this->assertEquals($this->getDefinitionLocation('TEST_CONST'), $result);
|
$this->assertEquals($this->getDefinitionLocation('TEST_CONST'), $result);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDefinitionForClassLikeUseStatement()
|
public function testDefinitionForClassLikeUseStatement()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
// use TestNamespace\TestClass;
|
// use TestNamespace\TestClass;
|
||||||
// Get definition for TestClass
|
// Get definition for TestClass
|
||||||
$reference = $this->getReferenceLocations('TestClass')[7];
|
$reference = $this->getReferenceLocations('TestClass')[7];
|
||||||
$result = $this->textDocument->definition(
|
$result = yield $this->textDocument->definition(
|
||||||
new TextDocumentIdentifier($reference->uri),
|
new TextDocumentIdentifier($reference->uri),
|
||||||
$reference->range->start
|
$reference->range->start
|
||||||
)->wait();
|
);
|
||||||
$this->assertEquals($this->getDefinitionLocation('TestClass'), $result);
|
$this->assertEquals($this->getDefinitionLocation('TestClass'), $result);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDefinitionForClassLikeGroupUseStatement()
|
public function testDefinitionForClassLikeGroupUseStatement()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
// use TestNamespace\{TestTrait, TestInterface};
|
// use TestNamespace\{TestTrait, TestInterface};
|
||||||
// Get definition for TestInterface
|
// Get definition for TestInterface
|
||||||
$reference = $this->getReferenceLocations('TestClass')[1];
|
$reference = $this->getReferenceLocations('TestClass')[1];
|
||||||
$result = $this->textDocument->definition(
|
$result = yield $this->textDocument->definition(
|
||||||
new TextDocumentIdentifier($reference->uri),
|
new TextDocumentIdentifier($reference->uri),
|
||||||
$reference->range->start
|
$reference->range->start
|
||||||
)->wait();
|
);
|
||||||
$this->assertEquals($this->getDefinitionLocation('TestClass'), $result);
|
$this->assertEquals($this->getDefinitionLocation('TestClass'), $result);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ declare(strict_types = 1);
|
||||||
|
|
||||||
namespace LanguageServer\Tests\Server\TextDocument;
|
namespace LanguageServer\Tests\Server\TextDocument;
|
||||||
|
|
||||||
|
use Amp\Loop;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use LanguageServer\Tests\MockProtocolStream;
|
use LanguageServer\Tests\MockProtocolStream;
|
||||||
use LanguageServer\{
|
use LanguageServer\{
|
||||||
|
@ -21,6 +22,7 @@ class DidChangeTest extends TestCase
|
||||||
{
|
{
|
||||||
public function test()
|
public function test()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
$projectIndex = new ProjectIndex(new Index, new DependenciesIndex);
|
$projectIndex = new ProjectIndex(new Index, new DependenciesIndex);
|
||||||
$client = new LanguageClient(new MockProtocolStream, new MockProtocolStream);
|
$client = new LanguageClient(new MockProtocolStream, new MockProtocolStream);
|
||||||
$definitionResolver = new DefinitionResolver($projectIndex);
|
$definitionResolver = new DefinitionResolver($projectIndex);
|
||||||
|
@ -34,8 +36,9 @@ class DidChangeTest extends TestCase
|
||||||
$changeEvent->rangeLength = 9999;
|
$changeEvent->rangeLength = 9999;
|
||||||
$changeEvent->text = "<?php\necho 'Goodbye, World'\n";
|
$changeEvent->text = "<?php\necho 'Goodbye, World'\n";
|
||||||
|
|
||||||
$textDocument->didChange($identifier, [$changeEvent]);
|
yield $textDocument->didChange($identifier, [$changeEvent]);
|
||||||
|
|
||||||
$this->assertEquals("<?php\necho 'Goodbye, World'\n", $phpDocument->getContent());
|
$this->assertEquals("<?php\necho 'Goodbye, World'\n", $phpDocument->getContent());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ declare(strict_types = 1);
|
||||||
|
|
||||||
namespace LanguageServer\Tests\Server\TextDocument;
|
namespace LanguageServer\Tests\Server\TextDocument;
|
||||||
|
|
||||||
|
use Amp\Loop;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use LanguageServer\Tests\MockProtocolStream;
|
use LanguageServer\Tests\MockProtocolStream;
|
||||||
use LanguageServer\{
|
use LanguageServer\{
|
||||||
|
@ -16,6 +17,7 @@ class DidCloseTest extends TestCase
|
||||||
{
|
{
|
||||||
public function test()
|
public function test()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
$projectIndex = new ProjectIndex(new Index, new DependenciesIndex);
|
$projectIndex = new ProjectIndex(new Index, new DependenciesIndex);
|
||||||
$client = new LanguageClient(new MockProtocolStream, new MockProtocolStream);
|
$client = new LanguageClient(new MockProtocolStream, new MockProtocolStream);
|
||||||
$definitionResolver = new DefinitionResolver($projectIndex);
|
$definitionResolver = new DefinitionResolver($projectIndex);
|
||||||
|
@ -33,5 +35,6 @@ class DidCloseTest extends TestCase
|
||||||
$textDocument->didClose(new TextDocumentIdentifier($textDocumentItem->uri));
|
$textDocument->didClose(new TextDocumentIdentifier($textDocumentItem->uri));
|
||||||
|
|
||||||
$this->assertFalse($loader->isOpen($textDocumentItem->uri));
|
$this->assertFalse($loader->isOpen($textDocumentItem->uri));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ declare(strict_types = 1);
|
||||||
|
|
||||||
namespace LanguageServer\Tests\Server\TextDocument;
|
namespace LanguageServer\Tests\Server\TextDocument;
|
||||||
|
|
||||||
|
use Amp\Loop;
|
||||||
use LanguageServer\Tests\Server\ServerTestCase;
|
use LanguageServer\Tests\Server\ServerTestCase;
|
||||||
use LanguageServer\Tests\MockProtocolStream;
|
use LanguageServer\Tests\MockProtocolStream;
|
||||||
use LanguageServer\{Server, LanguageClient, Project};
|
use LanguageServer\{Server, LanguageClient, Project};
|
||||||
|
@ -13,9 +14,10 @@ class DocumentSymbolTest extends ServerTestCase
|
||||||
{
|
{
|
||||||
public function test()
|
public function test()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
// Request symbols
|
// Request symbols
|
||||||
$uri = pathToUri(realpath(__DIR__ . '/../../../fixtures/symbols.php'));
|
$uri = pathToUri(realpath(__DIR__ . '/../../../fixtures/symbols.php'));
|
||||||
$result = $this->textDocument->documentSymbol(new TextDocumentIdentifier($uri))->wait();
|
$result = yield $this->textDocument->documentSymbol(new TextDocumentIdentifier($uri));
|
||||||
// @codingStandardsIgnoreStart
|
// @codingStandardsIgnoreStart
|
||||||
$this->assertEquals([
|
$this->assertEquals([
|
||||||
new SymbolInformation('TestNamespace', SymbolKind::NAMESPACE, $this->getDefinitionLocation('TestNamespace'), ''),
|
new SymbolInformation('TestNamespace', SymbolKind::NAMESPACE, $this->getDefinitionLocation('TestNamespace'), ''),
|
||||||
|
@ -37,5 +39,6 @@ class DocumentSymbolTest extends ServerTestCase
|
||||||
new SymbolInformation('InnerClass', SymbolKind::CLASS_, $this->getDefinitionLocation('TestNamespace\\InnerNamespace\\InnerClass'), 'TestNamespace\\InnerNamespace'),
|
new SymbolInformation('InnerClass', SymbolKind::CLASS_, $this->getDefinitionLocation('TestNamespace\\InnerNamespace\\InnerClass'), 'TestNamespace\\InnerNamespace'),
|
||||||
], $result);
|
], $result);
|
||||||
// @codingStandardsIgnoreEnd
|
// @codingStandardsIgnoreEnd
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ declare(strict_types = 1);
|
||||||
|
|
||||||
namespace LanguageServer\Tests\Server\TextDocument;
|
namespace LanguageServer\Tests\Server\TextDocument;
|
||||||
|
|
||||||
|
use Amp\Loop;
|
||||||
use LanguageServer\Tests\MockProtocolStream;
|
use LanguageServer\Tests\MockProtocolStream;
|
||||||
use LanguageServer\Tests\Server\ServerTestCase;
|
use LanguageServer\Tests\Server\ServerTestCase;
|
||||||
use LanguageServer\{Server, LanguageClient, Project};
|
use LanguageServer\{Server, LanguageClient, Project};
|
||||||
|
@ -13,13 +14,14 @@ class HoverTest extends ServerTestCase
|
||||||
{
|
{
|
||||||
public function testHoverForClassLike()
|
public function testHoverForClassLike()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
// $obj = new TestClass();
|
// $obj = new TestClass();
|
||||||
// Get hover for TestClass
|
// Get hover for TestClass
|
||||||
$reference = $this->getReferenceLocations('TestClass')[1];
|
$reference = $this->getReferenceLocations('TestClass')[1];
|
||||||
$result = $this->textDocument->hover(
|
$result = yield $this->textDocument->hover(
|
||||||
new TextDocumentIdentifier($reference->uri),
|
new TextDocumentIdentifier($reference->uri),
|
||||||
$reference->range->start
|
$reference->range->start
|
||||||
)->wait();
|
);
|
||||||
$this->assertEquals(new Hover([
|
$this->assertEquals(new Hover([
|
||||||
new MarkedString('php', "<?php\nclass TestClass implements TestInterface"),
|
new MarkedString('php', "<?php\nclass TestClass implements TestInterface"),
|
||||||
'Pariatur ut laborum tempor voluptate consequat ea deserunt.' . "\n\n" .
|
'Pariatur ut laborum tempor voluptate consequat ea deserunt.' . "\n\n" .
|
||||||
|
@ -29,17 +31,19 @@ class HoverTest extends ServerTestCase
|
||||||
'consequat sunt culpa exercitation pariatur id reprehenderit nisi incididunt Lorem' . "\n" .
|
'consequat sunt culpa exercitation pariatur id reprehenderit nisi incididunt Lorem' . "\n" .
|
||||||
'sint. Officia culpa pariatur laborum nostrud cupidatat consequat mollit.'
|
'sint. Officia culpa pariatur laborum nostrud cupidatat consequat mollit.'
|
||||||
], $reference->range), $result);
|
], $reference->range), $result);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testHoverForClassLikeDefinition()
|
public function testHoverForClassLikeDefinition()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
// class TestClass implements TestInterface
|
// class TestClass implements TestInterface
|
||||||
// Get hover for TestClass
|
// Get hover for TestClass
|
||||||
$definition = $this->getDefinitionLocation('TestClass');
|
$definition = $this->getDefinitionLocation('TestClass');
|
||||||
$result = $this->textDocument->hover(
|
$result = yield $this->textDocument->hover(
|
||||||
new TextDocumentIdentifier($definition->uri),
|
new TextDocumentIdentifier($definition->uri),
|
||||||
$definition->range->start
|
$definition->range->start
|
||||||
)->wait();
|
);
|
||||||
$this->assertEquals(new Hover([
|
$this->assertEquals(new Hover([
|
||||||
new MarkedString('php', "<?php\nclass TestClass implements TestInterface"),
|
new MarkedString('php', "<?php\nclass TestClass implements TestInterface"),
|
||||||
'Pariatur ut laborum tempor voluptate consequat ea deserunt.' . "\n\n" .
|
'Pariatur ut laborum tempor voluptate consequat ea deserunt.' . "\n\n" .
|
||||||
|
@ -49,147 +53,173 @@ class HoverTest extends ServerTestCase
|
||||||
'consequat sunt culpa exercitation pariatur id reprehenderit nisi incididunt Lorem' . "\n" .
|
'consequat sunt culpa exercitation pariatur id reprehenderit nisi incididunt Lorem' . "\n" .
|
||||||
'sint. Officia culpa pariatur laborum nostrud cupidatat consequat mollit.'
|
'sint. Officia culpa pariatur laborum nostrud cupidatat consequat mollit.'
|
||||||
], $definition->range), $result);
|
], $definition->range), $result);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testHoverForMethod()
|
public function testHoverForMethod()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
// $obj->testMethod();
|
// $obj->testMethod();
|
||||||
// Get hover for testMethod
|
// Get hover for testMethod
|
||||||
$reference = $this->getReferenceLocations('TestClass::testMethod()')[0];
|
$reference = $this->getReferenceLocations('TestClass::testMethod()')[0];
|
||||||
$result = $this->textDocument->hover(
|
$result = yield $this->textDocument->hover(
|
||||||
new TextDocumentIdentifier($reference->uri),
|
new TextDocumentIdentifier($reference->uri),
|
||||||
$reference->range->end
|
$reference->range->end
|
||||||
)->wait();
|
);
|
||||||
$this->assertEquals(new Hover([
|
$this->assertEquals(new Hover([
|
||||||
new MarkedString('php', "<?php\npublic function testMethod(\$testParameter): TestInterface"),
|
new MarkedString('php', "<?php\npublic function testMethod(\$testParameter): TestInterface"),
|
||||||
'Non culpa nostrud mollit esse sunt laboris in irure ullamco cupidatat amet.'
|
'Non culpa nostrud mollit esse sunt laboris in irure ullamco cupidatat amet.'
|
||||||
], $reference->range), $result);
|
], $reference->range), $result);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testHoverForProperty()
|
public function testHoverForProperty()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
// echo $obj->testProperty;
|
// echo $obj->testProperty;
|
||||||
// Get hover for testProperty
|
// Get hover for testProperty
|
||||||
$reference = $this->getReferenceLocations('TestClass::testProperty')[0];
|
$reference = $this->getReferenceLocations('TestClass::testProperty')[0];
|
||||||
$result = $this->textDocument->hover(
|
$result = yield $this->textDocument->hover(
|
||||||
new TextDocumentIdentifier($reference->uri),
|
new TextDocumentIdentifier($reference->uri),
|
||||||
$reference->range->end
|
$reference->range->end
|
||||||
)->wait();
|
);
|
||||||
$this->assertEquals(new Hover([
|
$this->assertEquals(new Hover([
|
||||||
new MarkedString('php', "<?php\npublic \$testProperty;"),
|
new MarkedString('php', "<?php\npublic \$testProperty;"),
|
||||||
'Reprehenderit magna velit mollit ipsum do.'
|
'Reprehenderit magna velit mollit ipsum do.'
|
||||||
], $reference->range), $result);
|
], $reference->range), $result);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testHoverForStaticMethod()
|
public function testHoverForStaticMethod()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
// TestClass::staticTestMethod();
|
// TestClass::staticTestMethod();
|
||||||
// Get hover for staticTestMethod
|
// Get hover for staticTestMethod
|
||||||
$reference = $this->getReferenceLocations('TestClass::staticTestMethod()')[0];
|
$reference = $this->getReferenceLocations('TestClass::staticTestMethod()')[0];
|
||||||
$result = $this->textDocument->hover(
|
$result = yield $this->textDocument->hover(
|
||||||
new TextDocumentIdentifier($reference->uri),
|
new TextDocumentIdentifier($reference->uri),
|
||||||
$reference->range->end
|
$reference->range->end
|
||||||
)->wait();
|
);
|
||||||
$this->assertEquals(new Hover([
|
$this->assertEquals(new Hover([
|
||||||
new MarkedString('php', "<?php\npublic static function staticTestMethod()"),
|
new MarkedString('php', "<?php\npublic static function staticTestMethod()"),
|
||||||
'Do magna consequat veniam minim proident eiusmod incididunt aute proident.'
|
'Do magna consequat veniam minim proident eiusmod incididunt aute proident.'
|
||||||
], $reference->range), $result);
|
], $reference->range), $result);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testHoverForStaticProperty()
|
public function testHoverForStaticProperty()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
// echo TestClass::staticTestProperty;
|
// echo TestClass::staticTestProperty;
|
||||||
// Get hover for staticTestProperty
|
// Get hover for staticTestProperty
|
||||||
$reference = $this->getReferenceLocations('TestClass::staticTestProperty')[0];
|
$reference = $this->getReferenceLocations('TestClass::staticTestProperty')[0];
|
||||||
$result = $this->textDocument->hover(
|
$result = yield $this->textDocument->hover(
|
||||||
new TextDocumentIdentifier($reference->uri),
|
new TextDocumentIdentifier($reference->uri),
|
||||||
$reference->range->end
|
$reference->range->end
|
||||||
)->wait();
|
);
|
||||||
$this->assertEquals(new Hover([
|
$this->assertEquals(new Hover([
|
||||||
new MarkedString('php', "<?php\npublic static \$staticTestProperty;"),
|
new MarkedString('php', "<?php\npublic static \$staticTestProperty;"),
|
||||||
'Lorem excepteur officia sit anim velit veniam enim.'
|
'Lorem excepteur officia sit anim velit veniam enim.'
|
||||||
], $reference->range), $result);
|
], $reference->range), $result);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testHoverForClassConstant()
|
public function testHoverForClassConstant()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
// echo TestClass::TEST_CLASS_CONST;
|
// echo TestClass::TEST_CLASS_CONST;
|
||||||
// Get hover for TEST_CLASS_CONST
|
// Get hover for TEST_CLASS_CONST
|
||||||
$reference = $this->getReferenceLocations('TestClass::TEST_CLASS_CONST')[0];
|
$reference = $this->getReferenceLocations('TestClass::TEST_CLASS_CONST')[0];
|
||||||
$result = $this->textDocument->hover(
|
$result = yield $this->textDocument->hover(
|
||||||
new TextDocumentIdentifier($reference->uri),
|
new TextDocumentIdentifier($reference->uri),
|
||||||
$reference->range->end
|
$reference->range->end
|
||||||
)->wait();
|
);
|
||||||
$this->assertEquals(new Hover([
|
$this->assertEquals(new Hover([
|
||||||
new MarkedString('php', "<?php\nconst TEST_CLASS_CONST = 123;"),
|
new MarkedString('php', "<?php\nconst TEST_CLASS_CONST = 123;"),
|
||||||
'Anim labore veniam consectetur laboris minim quis aute aute esse nulla ad.'
|
'Anim labore veniam consectetur laboris minim quis aute aute esse nulla ad.'
|
||||||
], $reference->range), $result);
|
], $reference->range), $result);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testHoverForFunction()
|
public function testHoverForFunction()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
// test_function();
|
// test_function();
|
||||||
// Get hover for test_function
|
// Get hover for test_function
|
||||||
$reference = $this->getReferenceLocations('test_function()')[0];
|
$reference = $this->getReferenceLocations('test_function()')[0];
|
||||||
$result = $this->textDocument->hover(
|
$result = yield $this->textDocument->hover(
|
||||||
new TextDocumentIdentifier($reference->uri),
|
new TextDocumentIdentifier($reference->uri),
|
||||||
$reference->range->end
|
$reference->range->end
|
||||||
)->wait();
|
);
|
||||||
$this->assertEquals(new Hover([
|
$this->assertEquals(new Hover([
|
||||||
new MarkedString('php', "<?php\nfunction test_function()"),
|
new MarkedString('php', "<?php\nfunction test_function()"),
|
||||||
'Officia aliquip adipisicing et nulla et laboris dolore labore.'
|
'Officia aliquip adipisicing et nulla et laboris dolore labore.'
|
||||||
], $reference->range), $result);
|
], $reference->range), $result);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testHoverForConstant()
|
public function testHoverForConstant()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
// echo TEST_CONST;
|
// echo TEST_CONST;
|
||||||
// Get hover for TEST_CONST
|
// Get hover for TEST_CONST
|
||||||
$reference = $this->getReferenceLocations('TEST_CONST')[0];
|
$reference = $this->getReferenceLocations('TEST_CONST')[0];
|
||||||
$result = $this->textDocument->hover(
|
$result = yield $this->textDocument->hover(
|
||||||
new TextDocumentIdentifier($reference->uri),
|
new TextDocumentIdentifier($reference->uri),
|
||||||
$reference->range->end
|
$reference->range->end
|
||||||
)->wait();
|
);
|
||||||
$this->assertEquals(new Hover([
|
$this->assertEquals(new Hover([
|
||||||
new MarkedString('php', "<?php\nconst TEST_CONST = 123;"),
|
new MarkedString('php', "<?php\nconst TEST_CONST = 123;"),
|
||||||
'Esse commodo excepteur pariatur Lorem est aute incididunt reprehenderit.'
|
'Esse commodo excepteur pariatur Lorem est aute incididunt reprehenderit.'
|
||||||
], $reference->range), $result);
|
], $reference->range), $result);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testHoverForGlobalConstant()
|
public function testHoverForGlobalConstant()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
// print TEST_DEFINE_CONSTANT ? 'true' : 'false';
|
// print TEST_DEFINE_CONSTANT ? 'true' : 'false';
|
||||||
// Get hover for TEST_DEFINE_CONSTANT
|
// Get hover for TEST_DEFINE_CONSTANT
|
||||||
$reference = $this->getReferenceLocations('TEST_DEFINE_CONSTANT')[0];
|
$reference = $this->getReferenceLocations('TEST_DEFINE_CONSTANT')[0];
|
||||||
$result = $this->textDocument->hover(
|
$result = yield $this->textDocument->hover(
|
||||||
new TextDocumentIdentifier($reference->uri),
|
new TextDocumentIdentifier($reference->uri),
|
||||||
$reference->range->end
|
$reference->range->end
|
||||||
)->wait();
|
);
|
||||||
// TODO - should pretty print with fqns, like \define, \false. Not yet supported by tolerant-php-parser
|
// TODO - should pretty print with fqns, like \define, \false. Not yet supported by tolerant-php-parser
|
||||||
$this->assertEquals(new Hover([
|
$this->assertEquals(new Hover([
|
||||||
new MarkedString('php', "<?php\ndefine('TEST_DEFINE_CONSTANT', false)"),
|
new MarkedString('php', "<?php\ndefine('TEST_DEFINE_CONSTANT', false)"),
|
||||||
'Lorem ipsum dolor sit amet, consectetur.'
|
'Lorem ipsum dolor sit amet, consectetur.'
|
||||||
], $reference->range), $result);
|
], $reference->range), $result);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testHoverForVariable()
|
public function testHoverForVariable()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
// echo $var;
|
// echo $var;
|
||||||
// Get hover for $var
|
// Get hover for $var
|
||||||
$uri = pathToUri(realpath(__DIR__ . '/../../../fixtures/references.php'));
|
$uri = pathToUri(realpath(__DIR__ . '/../../../fixtures/references.php'));
|
||||||
$result = $this->textDocument->hover(new TextDocumentIdentifier($uri), new Position(13, 7))->wait();
|
$result = yield $this->textDocument->hover(
|
||||||
|
new TextDocumentIdentifier($uri),
|
||||||
|
new Position(13, 7)
|
||||||
|
);
|
||||||
$this->assertEquals(new Hover(
|
$this->assertEquals(new Hover(
|
||||||
[new MarkedString('php', "<?php\n\$var = 123")],
|
[new MarkedString('php', "<?php\n\$var = 123")],
|
||||||
new Range(new Position(13, 5), new Position(13, 9))
|
new Range(new Position(13, 5), new Position(13, 9))
|
||||||
), $result);
|
), $result);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testHoverForParam()
|
public function testHoverForParam()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
// echo $param;
|
// echo $param;
|
||||||
// Get hover for $param
|
// Get hover for $param
|
||||||
$uri = pathToUri(realpath(__DIR__ . '/../../../fixtures/references.php'));
|
$uri = pathToUri(realpath(__DIR__ . '/../../../fixtures/references.php'));
|
||||||
$result = $this->textDocument->hover(new TextDocumentIdentifier($uri), new Position(22, 11))->wait();
|
$result = yield $this->textDocument->hover(
|
||||||
|
new TextDocumentIdentifier($uri),
|
||||||
|
new Position(22, 11)
|
||||||
|
);
|
||||||
$this->assertEquals(new Hover(
|
$this->assertEquals(new Hover(
|
||||||
[
|
[
|
||||||
new MarkedString('php', "<?php\nTestClass \$param"),
|
new MarkedString('php', "<?php\nTestClass \$param"),
|
||||||
|
@ -197,14 +227,19 @@ class HoverTest extends ServerTestCase
|
||||||
],
|
],
|
||||||
new Range(new Position(22, 9), new Position(22, 15))
|
new Range(new Position(22, 9), new Position(22, 15))
|
||||||
), $result);
|
), $result);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testHoverForThis()
|
public function testHoverForThis()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
// $this;
|
// $this;
|
||||||
// Get hover for $this
|
// Get hover for $this
|
||||||
$uri = pathToUri(realpath(__DIR__ . '/../../../fixtures/global_symbols.php'));
|
$uri = pathToUri(realpath(__DIR__ . '/../../../fixtures/global_symbols.php'));
|
||||||
$result = $this->textDocument->hover(new TextDocumentIdentifier($uri), new Position(59, 11))->wait();
|
$result = yield $this->textDocument->hover(
|
||||||
|
new TextDocumentIdentifier($uri),
|
||||||
|
new Position(59, 11)
|
||||||
|
);
|
||||||
$this->assertEquals(new Hover([
|
$this->assertEquals(new Hover([
|
||||||
new MarkedString('php', "<?php\nclass TestClass implements TestInterface"),
|
new MarkedString('php', "<?php\nclass TestClass implements TestInterface"),
|
||||||
'Pariatur ut laborum tempor voluptate consequat ea deserunt.' . "\n\n" .
|
'Pariatur ut laborum tempor voluptate consequat ea deserunt.' . "\n\n" .
|
||||||
|
@ -214,5 +249,6 @@ class HoverTest extends ServerTestCase
|
||||||
'consequat sunt culpa exercitation pariatur id reprehenderit nisi incididunt Lorem' . "\n" .
|
'consequat sunt culpa exercitation pariatur id reprehenderit nisi incididunt Lorem' . "\n" .
|
||||||
'sint. Officia culpa pariatur laborum nostrud cupidatat consequat mollit.'
|
'sint. Officia culpa pariatur laborum nostrud cupidatat consequat mollit.'
|
||||||
], new Range(new Position(59, 8), new Position(59, 13))), $result);
|
], new Range(new Position(59, 8), new Position(59, 13))), $result);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,16 +3,16 @@ declare(strict_types = 1);
|
||||||
|
|
||||||
namespace LanguageServer\Tests\Server\TextDocument;
|
namespace LanguageServer\Tests\Server\TextDocument;
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use Amp\Deferred;
|
||||||
use LanguageServer\Tests\MockProtocolStream;
|
use Amp\Delayed;
|
||||||
use LanguageServer\{
|
use Amp\Loop;
|
||||||
Server, Client, LanguageClient, ClientHandler, PhpDocumentLoader, DefinitionResolver
|
|
||||||
};
|
|
||||||
use LanguageServer\Index\{Index, ProjectIndex, DependenciesIndex};
|
|
||||||
use LanguageServer\ContentRetriever\FileSystemContentRetriever;
|
|
||||||
use LanguageServerProtocol\{TextDocumentItem, DiagnosticSeverity};
|
|
||||||
use Sabre\Event\Promise;
|
|
||||||
use JsonMapper;
|
use JsonMapper;
|
||||||
|
use LanguageServer\{Client, ClientHandler, DefinitionResolver, LanguageClient, PhpDocumentLoader, Server};
|
||||||
|
use LanguageServer\ContentRetriever\FileSystemContentRetriever;
|
||||||
|
use LanguageServer\Index\{DependenciesIndex, Index, ProjectIndex};
|
||||||
|
use LanguageServer\Tests\MockProtocolStream;
|
||||||
|
use LanguageServerProtocol\{DiagnosticSeverity, TextDocumentItem};
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
class ParseErrorsTest extends TestCase
|
class ParseErrorsTest extends TestCase
|
||||||
{
|
{
|
||||||
|
@ -21,22 +21,31 @@ class ParseErrorsTest extends TestCase
|
||||||
*/
|
*/
|
||||||
private $textDocument;
|
private $textDocument;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Deferred
|
||||||
|
*/
|
||||||
private $args;
|
private $args;
|
||||||
|
|
||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
$client = new LanguageClient(new MockProtocolStream, new MockProtocolStream);
|
$client = new LanguageClient(new MockProtocolStream, new MockProtocolStream);
|
||||||
$client->textDocument = new class($this->args) extends Client\TextDocument {
|
$this->args = new Deferred();
|
||||||
|
$client->textDocument = new class($this->args) extends Client\TextDocument
|
||||||
|
{
|
||||||
|
/** @var Deferred */
|
||||||
private $args;
|
private $args;
|
||||||
public function __construct(&$args)
|
|
||||||
|
public function __construct($args)
|
||||||
{
|
{
|
||||||
parent::__construct(new ClientHandler(new MockProtocolStream, new MockProtocolStream), new JsonMapper);
|
parent::__construct(new ClientHandler(new MockProtocolStream, new MockProtocolStream), new JsonMapper);
|
||||||
$this->args = &$args;
|
$this->args = $args;
|
||||||
}
|
}
|
||||||
public function publishDiagnostics(string $uri, array $diagnostics): Promise
|
|
||||||
|
public function publishDiagnostics(string $uri, array $diagnostics): \Generator
|
||||||
{
|
{
|
||||||
$this->args = func_get_args();
|
$this->args->resolve(func_get_args());
|
||||||
return Promise\resolve(null);
|
yield new Delayed(0);
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
$projectIndex = new ProjectIndex(new Index, new DependenciesIndex);
|
$projectIndex = new ProjectIndex(new Index, new DependenciesIndex);
|
||||||
|
@ -57,6 +66,7 @@ class ParseErrorsTest extends TestCase
|
||||||
|
|
||||||
public function testParseErrorsArePublishedAsDiagnostics()
|
public function testParseErrorsArePublishedAsDiagnostics()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
$this->openFile(__DIR__ . '/../../../fixtures/invalid_file.php');
|
$this->openFile(__DIR__ . '/../../../fixtures/invalid_file.php');
|
||||||
$this->assertEquals([
|
$this->assertEquals([
|
||||||
'whatever',
|
'whatever',
|
||||||
|
@ -124,13 +134,15 @@ class ParseErrorsTest extends TestCase
|
||||||
'source' => 'php',
|
'source' => 'php',
|
||||||
'message' => "'Name' expected."
|
'message' => "'Name' expected."
|
||||||
]]
|
]]
|
||||||
], json_decode(json_encode($this->args), true));
|
], json_decode(json_encode(yield $this->args->promise()), true));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testParseErrorsWithOnlyStartLine()
|
public function testParseErrorsWithOnlyStartLine()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
$this->markTestIncomplete('This diagnostic not yet implemented in tolerant-php-parser');
|
$this->markTestIncomplete('This diagnostic not yet implemented in tolerant-php-parser');
|
||||||
$this->openFile(__DIR__ . '/../../../fixtures/namespace_not_first.php');
|
yield $this->openFile(__DIR__ . '/../../../fixtures/namespace_not_first.php');
|
||||||
$this->assertEquals([
|
$this->assertEquals([
|
||||||
'whatever',
|
'whatever',
|
||||||
[[
|
[[
|
||||||
|
@ -149,6 +161,7 @@ class ParseErrorsTest extends TestCase
|
||||||
'source' => 'php',
|
'source' => 'php',
|
||||||
'message' => "Namespace declaration statement has to be the very first statement in the script"
|
'message' => "Namespace declaration statement has to be the very first statement in the script"
|
||||||
]]
|
]]
|
||||||
], json_decode(json_encode($this->args), true));
|
], json_decode(json_encode(yield $this->args->promise()), true));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ declare(strict_types = 1);
|
||||||
|
|
||||||
namespace LanguageServer\Tests\Server\TextDocument\References;
|
namespace LanguageServer\Tests\Server\TextDocument\References;
|
||||||
|
|
||||||
|
use Amp\Loop;
|
||||||
use LanguageServer\{
|
use LanguageServer\{
|
||||||
LanguageClient, PhpDocumentLoader, Server, DefinitionResolver
|
LanguageClient, PhpDocumentLoader, Server, DefinitionResolver
|
||||||
};
|
};
|
||||||
|
@ -32,37 +33,43 @@ class GlobalFallbackTest extends ServerTestCase
|
||||||
|
|
||||||
public function testClassDoesNotFallback()
|
public function testClassDoesNotFallback()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
// class TestClass implements TestInterface
|
// class TestClass implements TestInterface
|
||||||
// Get references for TestClass
|
// Get references for TestClass
|
||||||
$result = $this->textDocument->references(
|
$result = yield $this->textDocument->references(
|
||||||
new ReferenceContext,
|
new ReferenceContext,
|
||||||
new TextDocumentIdentifier('global_symbols'),
|
new TextDocumentIdentifier('global_symbols'),
|
||||||
new Position(6, 9)
|
new Position(6, 9)
|
||||||
)->wait();
|
);
|
||||||
$this->assertEquals([], $result);
|
$this->assertEquals([], $result);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testFallsBackForConstants()
|
public function testFallsBackForConstants()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
// const TEST_CONST = 123;
|
// const TEST_CONST = 123;
|
||||||
// Get references for TEST_CONST
|
// Get references for TEST_CONST
|
||||||
$result = $this->textDocument->references(
|
$result = yield $this->textDocument->references(
|
||||||
new ReferenceContext,
|
new ReferenceContext,
|
||||||
new TextDocumentIdentifier('global_symbols'),
|
new TextDocumentIdentifier('global_symbols'),
|
||||||
new Position(9, 13)
|
new Position(9, 13)
|
||||||
)->wait();
|
);
|
||||||
$this->assertEquals([new Location('global_fallback', new Range(new Position(6, 5), new Position(6, 15)))], $result);
|
$this->assertEquals([new Location('global_fallback', new Range(new Position(6, 5), new Position(6, 15)))], $result);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testFallsBackForFunctions()
|
public function testFallsBackForFunctions()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
// function test_function()
|
// function test_function()
|
||||||
// Get references for test_function
|
// Get references for test_function
|
||||||
$result = $this->textDocument->references(
|
$result = yield $this->textDocument->references(
|
||||||
new ReferenceContext,
|
new ReferenceContext,
|
||||||
new TextDocumentIdentifier('global_symbols'),
|
new TextDocumentIdentifier('global_symbols'),
|
||||||
new Position(78, 16)
|
new Position(78, 16)
|
||||||
)->wait();
|
);
|
||||||
$this->assertEquals([new Location('global_fallback', new Range(new Position(5, 0), new Position(5, 13)))], $result);
|
$this->assertEquals([new Location('global_fallback', new Range(new Position(5, 0), new Position(5, 13)))], $result);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ declare(strict_types = 1);
|
||||||
|
|
||||||
namespace LanguageServer\Tests\Server\TextDocument\References;
|
namespace LanguageServer\Tests\Server\TextDocument\References;
|
||||||
|
|
||||||
|
use Amp\Loop;
|
||||||
use LanguageServerProtocol\{TextDocumentIdentifier, Position, ReferenceContext, Location, Range};
|
use LanguageServerProtocol\{TextDocumentIdentifier, Position, ReferenceContext, Location, Range};
|
||||||
use LanguageServer\Tests\Server\ServerTestCase;
|
use LanguageServer\Tests\Server\ServerTestCase;
|
||||||
use function LanguageServer\pathToUri;
|
use function LanguageServer\pathToUri;
|
||||||
|
@ -11,191 +12,219 @@ class GlobalTest extends ServerTestCase
|
||||||
{
|
{
|
||||||
public function testReferencesForClassLike()
|
public function testReferencesForClassLike()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
// class TestClass implements TestInterface
|
// class TestClass implements TestInterface
|
||||||
// Get references for TestClass
|
// Get references for TestClass
|
||||||
$definition = $this->getDefinitionLocation('TestClass');
|
$definition = $this->getDefinitionLocation('TestClass');
|
||||||
$result = $this->textDocument->references(
|
$result = yield $this->textDocument->references(
|
||||||
new ReferenceContext,
|
new ReferenceContext,
|
||||||
new TextDocumentIdentifier($definition->uri),
|
new TextDocumentIdentifier($definition->uri),
|
||||||
$definition->range->start
|
$definition->range->start
|
||||||
)->wait();
|
);
|
||||||
$this->assertEquals($this->getReferenceLocations('TestClass'), $result);
|
$this->assertEquals($this->getReferenceLocations('TestClass'), $result);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testReferencesForClassConstants()
|
public function testReferencesForClassConstants()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
// const TEST_CLASS_CONST = 123;
|
// const TEST_CLASS_CONST = 123;
|
||||||
// Get references for TEST_CLASS_CONST
|
// Get references for TEST_CLASS_CONST
|
||||||
$definition = $this->getDefinitionLocation('TestClass::TEST_CLASS_CONST');
|
$definition = $this->getDefinitionLocation('TestClass::TEST_CLASS_CONST');
|
||||||
$result = $this->textDocument->references(
|
$result = yield $this->textDocument->references(
|
||||||
new ReferenceContext,
|
new ReferenceContext,
|
||||||
new TextDocumentIdentifier($definition->uri),
|
new TextDocumentIdentifier($definition->uri),
|
||||||
$definition->range->start
|
$definition->range->start
|
||||||
)->wait();
|
);
|
||||||
$this->assertEquals($this->getReferenceLocations('TestClass::TEST_CLASS_CONST'), $result);
|
$this->assertEquals($this->getReferenceLocations('TestClass::TEST_CLASS_CONST'), $result);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testReferencesForConstants()
|
public function testReferencesForConstants()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
// const TEST_CONST = 123;
|
// const TEST_CONST = 123;
|
||||||
// Get references for TEST_CONST
|
// Get references for TEST_CONST
|
||||||
$definition = $this->getDefinitionLocation('TEST_CONST');
|
$definition = $this->getDefinitionLocation('TEST_CONST');
|
||||||
$result = $this->textDocument->references(
|
$result = yield $this->textDocument->references(
|
||||||
new ReferenceContext,
|
new ReferenceContext,
|
||||||
new TextDocumentIdentifier($definition->uri),
|
new TextDocumentIdentifier($definition->uri),
|
||||||
$definition->range->start
|
$definition->range->start
|
||||||
)->wait();
|
);
|
||||||
$this->assertEquals($this->getReferenceLocations('TEST_CONST'), $result);
|
$this->assertEquals($this->getReferenceLocations('TEST_CONST'), $result);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testReferencesForStaticMethods()
|
public function testReferencesForStaticMethods()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
// public static function staticTestMethod()
|
// public static function staticTestMethod()
|
||||||
// Get references for staticTestMethod
|
// Get references for staticTestMethod
|
||||||
$definition = $this->getDefinitionLocation('TestClass::staticTestMethod()');
|
$definition = $this->getDefinitionLocation('TestClass::staticTestMethod()');
|
||||||
$result = $this->textDocument->references(
|
$result = yield $this->textDocument->references(
|
||||||
new ReferenceContext,
|
new ReferenceContext,
|
||||||
new TextDocumentIdentifier($definition->uri),
|
new TextDocumentIdentifier($definition->uri),
|
||||||
$definition->range->start
|
$definition->range->start
|
||||||
)->wait();
|
);
|
||||||
$this->assertEquals($this->getReferenceLocations('TestClass::staticTestMethod()'), $result);
|
$this->assertEquals($this->getReferenceLocations('TestClass::staticTestMethod()'), $result);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testReferencesForStaticProperties()
|
public function testReferencesForStaticProperties()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
// public static $staticTestProperty;
|
// public static $staticTestProperty;
|
||||||
// Get references for $staticTestProperty
|
// Get references for $staticTestProperty
|
||||||
$definition = $this->getDefinitionLocation('TestClass::staticTestProperty');
|
$definition = $this->getDefinitionLocation('TestClass::staticTestProperty');
|
||||||
$result = $this->textDocument->references(
|
$result = yield $this->textDocument->references(
|
||||||
new ReferenceContext,
|
new ReferenceContext,
|
||||||
new TextDocumentIdentifier($definition->uri),
|
new TextDocumentIdentifier($definition->uri),
|
||||||
$definition->range->start
|
$definition->range->start
|
||||||
)->wait();
|
);
|
||||||
$this->assertEquals($this->getReferenceLocations('TestClass::staticTestProperty'), $result);
|
$this->assertEquals($this->getReferenceLocations('TestClass::staticTestProperty'), $result);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testReferencesForMethods()
|
public function testReferencesForMethods()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
// public function testMethod($testParameter)
|
// public function testMethod($testParameter)
|
||||||
// Get references for testMethod
|
// Get references for testMethod
|
||||||
$definition = $this->getDefinitionLocation('TestClass::testMethod()');
|
$definition = $this->getDefinitionLocation('TestClass::testMethod()');
|
||||||
$result = $this->textDocument->references(
|
$result = yield $this->textDocument->references(
|
||||||
new ReferenceContext,
|
new ReferenceContext,
|
||||||
new TextDocumentIdentifier($definition->uri),
|
new TextDocumentIdentifier($definition->uri),
|
||||||
$definition->range->start
|
$definition->range->start
|
||||||
)->wait();
|
);
|
||||||
$this->assertEquals($this->getReferenceLocations('TestClass::testMethod()'), $result);
|
$this->assertEquals($this->getReferenceLocations('TestClass::testMethod()'), $result);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testReferencesForProperties()
|
public function testReferencesForProperties()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
// public $testProperty;
|
// public $testProperty;
|
||||||
// Get references for testProperty
|
// Get references for testProperty
|
||||||
$definition = $this->getDefinitionLocation('TestClass::testProperty');
|
$definition = $this->getDefinitionLocation('TestClass::testProperty');
|
||||||
$result = $this->textDocument->references(
|
$result = yield $this->textDocument->references(
|
||||||
new ReferenceContext,
|
new ReferenceContext,
|
||||||
new TextDocumentIdentifier($definition->uri),
|
new TextDocumentIdentifier($definition->uri),
|
||||||
$definition->range->start
|
$definition->range->start
|
||||||
)->wait();
|
);
|
||||||
$this->assertEquals($this->getReferenceLocations('TestClass::testProperty'), $result);
|
$this->assertEquals($this->getReferenceLocations('TestClass::testProperty'), $result);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testReferencesForVariables()
|
public function testReferencesForVariables()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
// $var = 123;
|
// $var = 123;
|
||||||
// Get definition for $var
|
// Get definition for $var
|
||||||
$uri = pathToUri(realpath(__DIR__ . '/../../../../fixtures/references.php'));
|
$uri = pathToUri(realpath(__DIR__ . '/../../../../fixtures/references.php'));
|
||||||
$result = $this->textDocument->references(
|
$result = yield $this->textDocument->references(
|
||||||
new ReferenceContext,
|
new ReferenceContext,
|
||||||
new TextDocumentIdentifier($uri),
|
new TextDocumentIdentifier($uri),
|
||||||
new Position(12, 3)
|
new Position(12, 3)
|
||||||
)->wait();
|
);
|
||||||
$this->assertEquals([
|
$this->assertEquals([
|
||||||
new Location($uri, new Range(new Position(12, 0), new Position(12, 4))),
|
new Location($uri, new Range(new Position(12, 0), new Position(12, 4))),
|
||||||
new Location($uri, new Range(new Position(13, 5), new Position(13, 9))),
|
new Location($uri, new Range(new Position(13, 5), new Position(13, 9))),
|
||||||
new Location($uri, new Range(new Position(26, 9), new Position(26, 13)))
|
new Location($uri, new Range(new Position(26, 9), new Position(26, 13)))
|
||||||
], $result);
|
], $result);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testReferencesForFunctionParams()
|
public function testReferencesForFunctionParams()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
// function whatever(TestClass $param): TestClass
|
// function whatever(TestClass $param): TestClass
|
||||||
// Get references for $param
|
// Get references for $param
|
||||||
$uri = pathToUri(realpath(__DIR__ . '/../../../../fixtures/references.php'));
|
$uri = pathToUri(realpath(__DIR__ . '/../../../../fixtures/references.php'));
|
||||||
$result = $this->textDocument->references(
|
$result = yield $this->textDocument->references(
|
||||||
new ReferenceContext,
|
new ReferenceContext,
|
||||||
new TextDocumentIdentifier($uri),
|
new TextDocumentIdentifier($uri),
|
||||||
new Position(21, 32)
|
new Position(21, 32)
|
||||||
)->wait();
|
);
|
||||||
$this->assertEquals([new Location($uri, new Range(new Position(22, 9), new Position(22, 15)))], $result);
|
$this->assertEquals([new Location($uri, new Range(new Position(22, 9), new Position(22, 15)))], $result);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testReferencesForFunctions()
|
public function testReferencesForFunctions()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
// function test_function()
|
// function test_function()
|
||||||
// Get references for test_function
|
// Get references for test_function
|
||||||
$referencesUri = pathToUri(realpath(__DIR__ . '/../../../../fixtures/references.php'));
|
$referencesUri = pathToUri(realpath(__DIR__ . '/../../../../fixtures/references.php'));
|
||||||
$symbolsUri = pathToUri(realpath(__DIR__ . '/../../../../fixtures/symbols.php'));
|
$symbolsUri = pathToUri(realpath(__DIR__ . '/../../../../fixtures/symbols.php'));
|
||||||
$result = $this->textDocument->references(
|
$result = yield $this->textDocument->references(
|
||||||
new ReferenceContext,
|
new ReferenceContext,
|
||||||
new TextDocumentIdentifier($symbolsUri),
|
new TextDocumentIdentifier($symbolsUri),
|
||||||
new Position(78, 16)
|
new Position(78, 16)
|
||||||
)->wait();
|
);
|
||||||
$this->assertEquals([
|
$this->assertEquals([
|
||||||
new Location($referencesUri, new Range(new Position(10, 0), new Position(10, 13))),
|
new Location($referencesUri, new Range(new Position(10, 0), new Position(10, 13))),
|
||||||
new Location($referencesUri, new Range(new Position(31, 13), new Position(31, 40)))
|
new Location($referencesUri, new Range(new Position(31, 13), new Position(31, 40)))
|
||||||
], $result);
|
], $result);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testReferencesForReference()
|
public function testReferencesForReference()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
// $obj = new TestClass();
|
// $obj = new TestClass();
|
||||||
// Get references for TestClass
|
// Get references for TestClass
|
||||||
$reference = $this->getReferenceLocations('TestClass')[1];
|
$reference = $this->getReferenceLocations('TestClass')[1];
|
||||||
$result = $this->textDocument->references(
|
$result = yield $this->textDocument->references(
|
||||||
new ReferenceContext,
|
new ReferenceContext,
|
||||||
new TextDocumentIdentifier($reference->uri),
|
new TextDocumentIdentifier($reference->uri),
|
||||||
$reference->range->start
|
$reference->range->start
|
||||||
)->wait();
|
);
|
||||||
$this->assertEquals($this->getReferenceLocations('TestClass'), $result);
|
$this->assertEquals($this->getReferenceLocations('TestClass'), $result);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testReferencesForUnusedClass()
|
public function testReferencesForUnusedClass()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
// class UnusedClass
|
// class UnusedClass
|
||||||
// Get references for UnusedClass
|
// Get references for UnusedClass
|
||||||
$symbolsUri = pathToUri(realpath(__DIR__ . '/../../../../fixtures/global_symbols.php'));
|
$symbolsUri = pathToUri(realpath(__DIR__ . '/../../../../fixtures/global_symbols.php'));
|
||||||
$result = $this->textDocument->references(
|
$result = yield $this->textDocument->references(
|
||||||
new ReferenceContext,
|
new ReferenceContext,
|
||||||
new TextDocumentIdentifier($symbolsUri),
|
new TextDocumentIdentifier($symbolsUri),
|
||||||
new Position(111, 10)
|
new Position(111, 10)
|
||||||
)->wait();
|
);
|
||||||
$this->assertEquals([], $result);
|
$this->assertEquals([], $result);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testReferencesForUnusedProperty()
|
public function testReferencesForUnusedProperty()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
// public $unusedProperty
|
// public $unusedProperty
|
||||||
// Get references for unusedProperty
|
// Get references for unusedProperty
|
||||||
$symbolsUri = pathToUri(realpath(__DIR__ . '/../../../../fixtures/global_symbols.php'));
|
$symbolsUri = pathToUri(realpath(__DIR__ . '/../../../../fixtures/global_symbols.php'));
|
||||||
$result = $this->textDocument->references(
|
$result = yield $this->textDocument->references(
|
||||||
new ReferenceContext,
|
new ReferenceContext,
|
||||||
new TextDocumentIdentifier($symbolsUri),
|
new TextDocumentIdentifier($symbolsUri),
|
||||||
new Position(113, 18)
|
new Position(113, 18)
|
||||||
)->wait();
|
);
|
||||||
$this->assertEquals([], $result);
|
$this->assertEquals([], $result);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testReferencesForUnusedMethod()
|
public function testReferencesForUnusedMethod()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
// public function unusedMethod()
|
// public function unusedMethod()
|
||||||
// Get references for unusedMethod
|
// Get references for unusedMethod
|
||||||
$symbolsUri = pathToUri(realpath(__DIR__ . '/../../../../fixtures/global_symbols.php'));
|
$symbolsUri = pathToUri(realpath(__DIR__ . '/../../../../fixtures/global_symbols.php'));
|
||||||
$result = $this->textDocument->references(
|
$result = yield $this->textDocument->references(
|
||||||
new ReferenceContext,
|
new ReferenceContext,
|
||||||
new TextDocumentIdentifier($symbolsUri),
|
new TextDocumentIdentifier($symbolsUri),
|
||||||
new Position(115, 26)
|
new Position(115, 26)
|
||||||
)->wait();
|
);
|
||||||
$this->assertEquals([], $result);
|
$this->assertEquals([], $result);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ declare(strict_types = 1);
|
||||||
|
|
||||||
namespace LanguageServer\Tests\Server\TextDocument\References;
|
namespace LanguageServer\Tests\Server\TextDocument\References;
|
||||||
|
|
||||||
|
use Amp\Loop;
|
||||||
use LanguageServerProtocol\{TextDocumentIdentifier, Position, ReferenceContext, Location, Range};
|
use LanguageServerProtocol\{TextDocumentIdentifier, Position, ReferenceContext, Location, Range};
|
||||||
use function LanguageServer\pathToUri;
|
use function LanguageServer\pathToUri;
|
||||||
|
|
||||||
|
@ -20,14 +21,16 @@ class NamespacedTest extends GlobalTest
|
||||||
|
|
||||||
public function testReferencesForNamespaces()
|
public function testReferencesForNamespaces()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
// namespace TestNamespace;
|
// namespace TestNamespace;
|
||||||
// Get references for TestNamespace
|
// Get references for TestNamespace
|
||||||
$definition = parent::getDefinitionLocation('TestNamespace');
|
$definition = parent::getDefinitionLocation('TestNamespace');
|
||||||
$result = $this->textDocument->references(
|
$result = yield $this->textDocument->references(
|
||||||
new ReferenceContext,
|
new ReferenceContext,
|
||||||
new TextDocumentIdentifier($definition->uri),
|
new TextDocumentIdentifier($definition->uri),
|
||||||
$definition->range->end
|
$definition->range->end
|
||||||
)->wait();
|
);
|
||||||
$this->assertEquals(parent::getReferenceLocations('TestNamespace'), $result);
|
$this->assertEquals(parent::getReferenceLocations('TestNamespace'), $result);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ declare(strict_types = 1);
|
||||||
|
|
||||||
namespace LanguageServer\Tests\Server\TextDocument;
|
namespace LanguageServer\Tests\Server\TextDocument;
|
||||||
|
|
||||||
|
use Amp\Loop;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use LanguageServer\Tests\MockProtocolStream;
|
use LanguageServer\Tests\MockProtocolStream;
|
||||||
use LanguageServer\{
|
use LanguageServer\{
|
||||||
|
@ -50,13 +51,15 @@ class SignatureHelpTest extends TestCase
|
||||||
*/
|
*/
|
||||||
public function testSignatureHelp(Position $position, SignatureHelp $expectedSignature)
|
public function testSignatureHelp(Position $position, SignatureHelp $expectedSignature)
|
||||||
{
|
{
|
||||||
|
Loop::run(function () use ($position, $expectedSignature) {
|
||||||
$callsUri = pathToUri(__DIR__ . '/../../../fixtures/signature_help/calls.php');
|
$callsUri = pathToUri(__DIR__ . '/../../../fixtures/signature_help/calls.php');
|
||||||
$this->loader->open($callsUri, file_get_contents($callsUri));
|
$this->loader->open($callsUri, file_get_contents($callsUri));
|
||||||
$signatureHelp = $this->textDocument->signatureHelp(
|
$signatureHelp = yield $this->textDocument->signatureHelp(
|
||||||
new TextDocumentIdentifier($callsUri),
|
new TextDocumentIdentifier($callsUri),
|
||||||
$position
|
$position
|
||||||
)->wait();
|
);
|
||||||
$this->assertEquals($expectedSignature, $signatureHelp);
|
$this->assertEquals($expectedSignature, $signatureHelp);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function signatureHelpProvider(): array
|
public function signatureHelpProvider(): array
|
||||||
|
|
|
@ -3,20 +3,22 @@ declare(strict_types = 1);
|
||||||
|
|
||||||
namespace LanguageServer\Tests\Server\Workspace;
|
namespace LanguageServer\Tests\Server\Workspace;
|
||||||
|
|
||||||
|
use Amp\Deferred;
|
||||||
|
use Amp\Loop;
|
||||||
use LanguageServer\ContentRetriever\FileSystemContentRetriever;
|
use LanguageServer\ContentRetriever\FileSystemContentRetriever;
|
||||||
use LanguageServer\{DefinitionResolver, LanguageClient, PhpDocumentLoader, Server};
|
use LanguageServer\{DefinitionResolver, Event\MessageEvent, LanguageClient, PhpDocumentLoader, Server};
|
||||||
use LanguageServer\Index\{DependenciesIndex, Index, ProjectIndex};
|
use LanguageServer\Index\{DependenciesIndex, Index, ProjectIndex};
|
||||||
use LanguageServerProtocol\{FileChangeType, FileEvent};
|
use LanguageServerProtocol\{FileChangeType, FileEvent};
|
||||||
use LanguageServer\Message;
|
use LanguageServer\Message;
|
||||||
use LanguageServer\Tests\MockProtocolStream;
|
use LanguageServer\Tests\MockProtocolStream;
|
||||||
use LanguageServer\Tests\Server\ServerTestCase;
|
use LanguageServer\Tests\Server\ServerTestCase;
|
||||||
use LanguageServer\Server\Workspace;
|
use LanguageServer\Server\Workspace;
|
||||||
use Sabre\Event\Loop;
|
|
||||||
|
|
||||||
class DidChangeWatchedFilesTest extends ServerTestCase
|
class DidChangeWatchedFilesTest extends ServerTestCase
|
||||||
{
|
{
|
||||||
public function testDeletingFileClearsAllDiagnostics()
|
public function testDeletingFileClearsAllDiagnostics()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
$client = new LanguageClient(new MockProtocolStream(), $writer = new MockProtocolStream());
|
$client = new LanguageClient(new MockProtocolStream(), $writer = new MockProtocolStream());
|
||||||
$projectIndex = new ProjectIndex($sourceIndex = new Index(), $dependenciesIndex = new DependenciesIndex());
|
$projectIndex = new ProjectIndex($sourceIndex = new Index(), $dependenciesIndex = new DependenciesIndex());
|
||||||
$definitionResolver = new DefinitionResolver($projectIndex);
|
$definitionResolver = new DefinitionResolver($projectIndex);
|
||||||
|
@ -26,17 +28,19 @@ class DidChangeWatchedFilesTest extends ServerTestCase
|
||||||
$fileEvent = new FileEvent('my uri', FileChangeType::DELETED);
|
$fileEvent = new FileEvent('my uri', FileChangeType::DELETED);
|
||||||
|
|
||||||
$isDiagnosticsCleared = false;
|
$isDiagnosticsCleared = false;
|
||||||
$writer->on('message', function (Message $message) use ($fileEvent, &$isDiagnosticsCleared) {
|
$deferred = new Deferred();
|
||||||
|
$writer->addListener('message', function (MessageEvent $messageEvent) use ($deferred, $fileEvent, &$isDiagnosticsCleared) {
|
||||||
|
$message = $messageEvent->getMessage();
|
||||||
if ($message->body->method === "textDocument/publishDiagnostics") {
|
if ($message->body->method === "textDocument/publishDiagnostics") {
|
||||||
$this->assertEquals($message->body->params->uri, $fileEvent->uri);
|
$this->assertEquals($message->body->params->uri, $fileEvent->uri);
|
||||||
$this->assertEquals($message->body->params->diagnostics, []);
|
$this->assertEquals($message->body->params->diagnostics, []);
|
||||||
$isDiagnosticsCleared = true;
|
$deferred->resolve(true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$workspace->didChangeWatchedFiles([$fileEvent]);
|
$workspace->didChangeWatchedFiles([$fileEvent]);
|
||||||
Loop\tick(true);
|
|
||||||
|
|
||||||
$this->assertTrue($isDiagnosticsCleared, "Deleting file should clear all diagnostics.");
|
$this->assertTrue(yield $deferred->promise(), "Deleting file should clear all diagnostics.");
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ declare(strict_types = 1);
|
||||||
|
|
||||||
namespace LanguageServer\Tests\Server\Workspace;
|
namespace LanguageServer\Tests\Server\Workspace;
|
||||||
|
|
||||||
|
use Amp\Loop;
|
||||||
use LanguageServer\Tests\MockProtocolStream;
|
use LanguageServer\Tests\MockProtocolStream;
|
||||||
use LanguageServer\Tests\Server\ServerTestCase;
|
use LanguageServer\Tests\Server\ServerTestCase;
|
||||||
use LanguageServer\{Server, Client, LanguageClient, Project, PhpDocument};
|
use LanguageServer\{Server, Client, LanguageClient, Project, PhpDocument};
|
||||||
|
@ -24,8 +25,9 @@ class SymbolTest extends ServerTestCase
|
||||||
{
|
{
|
||||||
public function testEmptyQueryReturnsAllSymbols()
|
public function testEmptyQueryReturnsAllSymbols()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
// Request symbols
|
// Request symbols
|
||||||
$result = $this->workspace->symbol('')->wait();
|
$result = yield $this->workspace->symbol('');
|
||||||
$referencesUri = pathToUri(realpath(__DIR__ . '/../../../fixtures/references.php'));
|
$referencesUri = pathToUri(realpath(__DIR__ . '/../../../fixtures/references.php'));
|
||||||
|
|
||||||
// @codingStandardsIgnoreStart
|
// @codingStandardsIgnoreStart
|
||||||
|
@ -70,12 +72,14 @@ class SymbolTest extends ServerTestCase
|
||||||
new SymbolInformation('SecondTestNamespace', SymbolKind::NAMESPACE, $this->getDefinitionLocation('SecondTestNamespace'), ''),
|
new SymbolInformation('SecondTestNamespace', SymbolKind::NAMESPACE, $this->getDefinitionLocation('SecondTestNamespace'), ''),
|
||||||
], $result);
|
], $result);
|
||||||
// @codingStandardsIgnoreEnd
|
// @codingStandardsIgnoreEnd
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testQueryFiltersResults()
|
public function testQueryFiltersResults()
|
||||||
{
|
{
|
||||||
|
Loop::run(function () {
|
||||||
// Request symbols
|
// Request symbols
|
||||||
$result = $this->workspace->symbol('testmethod')->wait();
|
$result = yield $this->workspace->symbol('testmethod');
|
||||||
// @codingStandardsIgnoreStart
|
// @codingStandardsIgnoreStart
|
||||||
$this->assertEquals([
|
$this->assertEquals([
|
||||||
new SymbolInformation('staticTestMethod', SymbolKind::METHOD, $this->getDefinitionLocation('TestNamespace\\TestClass::staticTestMethod()'), 'TestNamespace\\TestClass'),
|
new SymbolInformation('staticTestMethod', SymbolKind::METHOD, $this->getDefinitionLocation('TestNamespace\\TestClass::staticTestMethod()'), 'TestNamespace\\TestClass'),
|
||||||
|
@ -84,5 +88,6 @@ class SymbolTest extends ServerTestCase
|
||||||
new SymbolInformation('testMethod', SymbolKind::METHOD, $this->getDefinitionLocation('TestClass::testMethod()'), 'TestClass')
|
new SymbolInformation('testMethod', SymbolKind::METHOD, $this->getDefinitionLocation('TestClass::testMethod()'), 'TestClass')
|
||||||
], $result);
|
], $result);
|
||||||
// @codingStandardsIgnoreEnd
|
// @codingStandardsIgnoreEnd
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
|
||||||
use function LanguageServer\{pathToUri, timeout};
|
use function LanguageServer\{pathToUri};
|
||||||
|
|
|
@ -5,9 +5,6 @@
|
||||||
],
|
],
|
||||||
"LanguageServer\\pathToUri()": [
|
"LanguageServer\\pathToUri()": [
|
||||||
"./functionUse2.php"
|
"./functionUse2.php"
|
||||||
],
|
|
||||||
"LanguageServer\\timeout()": [
|
|
||||||
"./functionUse2.php"
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"definitions": []
|
"definitions": []
|
||||||
|
|
Loading…
Reference in New Issue