2017-01-19 20:18:14 +00:00
|
|
|
<?php
|
|
|
|
declare(strict_types = 1);
|
|
|
|
|
|
|
|
namespace LanguageServer\Tests\Server\TextDocument;
|
|
|
|
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
use LanguageServer\Tests\MockProtocolStream;
|
|
|
|
use LanguageServer\{Server, LanguageClient, PhpDocumentLoader, CompletionProvider, DefinitionResolver};
|
|
|
|
use LanguageServer\Index\{Index, ProjectIndex, DependenciesIndex, GlobalIndex, StubsIndex};
|
|
|
|
use LanguageServer\ContentRetriever\FileSystemContentRetriever;
|
|
|
|
use LanguageServer\Protocol\{
|
|
|
|
TextDocumentIdentifier,
|
|
|
|
TextEdit,
|
|
|
|
Range,
|
|
|
|
Position,
|
|
|
|
ClientCapabilities,
|
|
|
|
SignatureHelp,
|
|
|
|
SignatureInformation,
|
|
|
|
ParameterInformation
|
|
|
|
};
|
|
|
|
use function LanguageServer\pathToUri;
|
|
|
|
|
|
|
|
class SignatureHelpTest extends TestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var Server\TextDocument
|
|
|
|
*/
|
|
|
|
private $textDocument;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var PhpDocumentLoader
|
|
|
|
*/
|
|
|
|
private $loader;
|
|
|
|
|
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
$client = new LanguageClient(new MockProtocolStream, new MockProtocolStream);
|
|
|
|
$projectIndex = new ProjectIndex(new Index, new DependenciesIndex);
|
|
|
|
$definitionResolver = new DefinitionResolver($projectIndex);
|
|
|
|
$contentRetriever = new FileSystemContentRetriever;
|
|
|
|
$this->loader = new PhpDocumentLoader($contentRetriever, $projectIndex, $definitionResolver);
|
|
|
|
$this->loader->load(pathToUri(__DIR__ . '/../../../fixtures/global_symbols.php'))->wait();
|
|
|
|
$this->loader->load(pathToUri(__DIR__ . '/../../../fixtures/symbols.php'))->wait();
|
|
|
|
$this->textDocument = new Server\TextDocument($this->loader, $definitionResolver, $client, $projectIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testMethodClosed()
|
|
|
|
{
|
|
|
|
$completionUri = pathToUri(__DIR__ . '/../../../fixtures/signatureHelp/methodClosed.php');
|
|
|
|
$this->loader->open($completionUri, file_get_contents($completionUri));
|
|
|
|
$result = $this->textDocument->signatureHelp(
|
|
|
|
new TextDocumentIdentifier($completionUri),
|
|
|
|
new Position(9, 22)
|
|
|
|
)->wait();
|
|
|
|
|
|
|
|
$help = new SignatureHelp;
|
|
|
|
$help->signatures = [];
|
|
|
|
$info = new SignatureInformation;
|
|
|
|
$help->signatures[] = $info;
|
2017-01-19 21:54:05 +00:00
|
|
|
$info->label = 'method(string $param = "")';
|
|
|
|
$info->parameters = [];
|
|
|
|
$param = new ParameterInformation;
|
|
|
|
$info->parameters[] = $param;
|
|
|
|
$param->label = 'string $param = ""';
|
|
|
|
|
|
|
|
$this->assertEquals($help, $result);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testMethodClosedReference()
|
|
|
|
{
|
|
|
|
$completionUri = pathToUri(__DIR__ . '/../../../fixtures/signatureHelp/methodClosed.php');
|
|
|
|
$this->loader->open($completionUri, file_get_contents($completionUri));
|
|
|
|
$result = $this->textDocument->signatureHelp(
|
|
|
|
new TextDocumentIdentifier($completionUri),
|
2017-01-20 15:47:18 +00:00
|
|
|
new Position(14, 11)
|
2017-01-19 21:54:05 +00:00
|
|
|
)->wait();
|
|
|
|
|
|
|
|
$help = new SignatureHelp;
|
|
|
|
$help->signatures = [];
|
|
|
|
$info = new SignatureInformation;
|
|
|
|
$help->signatures[] = $info;
|
|
|
|
$info->label = 'method(string $param = "")';
|
2017-01-19 20:18:14 +00:00
|
|
|
$info->parameters = [];
|
|
|
|
$param = new ParameterInformation;
|
|
|
|
$info->parameters[] = $param;
|
|
|
|
$param->label = 'string $param = ""';
|
|
|
|
|
|
|
|
$this->assertEquals($help, $result);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testMethodNotClosed()
|
|
|
|
{
|
|
|
|
$completionUri = pathToUri(__DIR__ . '/../../../fixtures/signatureHelp/methodNotClosed.php');
|
|
|
|
$this->loader->open($completionUri, file_get_contents($completionUri));
|
|
|
|
$result = $this->textDocument->signatureHelp(
|
|
|
|
new TextDocumentIdentifier($completionUri),
|
|
|
|
new Position(9, 22)
|
|
|
|
)->wait();
|
|
|
|
|
|
|
|
$help = new SignatureHelp;
|
|
|
|
$help->signatures = [];
|
|
|
|
$info = new SignatureInformation;
|
|
|
|
$help->signatures[] = $info;
|
2017-01-19 21:54:05 +00:00
|
|
|
$info->label = 'method(string $param = "")';
|
|
|
|
$info->parameters = [];
|
|
|
|
$param = new ParameterInformation;
|
|
|
|
$info->parameters[] = $param;
|
|
|
|
$param->label = 'string $param = ""';
|
|
|
|
|
|
|
|
$this->assertEquals($help, $result);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testMethodNotClosedReference()
|
|
|
|
{
|
|
|
|
$completionUri = pathToUri(__DIR__ . '/../../../fixtures/signatureHelp/methodNotClosed.php');
|
|
|
|
$this->loader->open($completionUri, file_get_contents($completionUri));
|
|
|
|
$result = $this->textDocument->signatureHelp(
|
|
|
|
new TextDocumentIdentifier($completionUri),
|
|
|
|
new Position(14, 14)
|
|
|
|
)->wait();
|
|
|
|
|
|
|
|
$help = new SignatureHelp;
|
|
|
|
$help->signatures = [];
|
|
|
|
$info = new SignatureInformation;
|
|
|
|
$help->signatures[] = $info;
|
|
|
|
$info->label = 'method(string $param = "")';
|
2017-01-19 20:18:14 +00:00
|
|
|
$info->parameters = [];
|
|
|
|
$param = new ParameterInformation;
|
|
|
|
$info->parameters[] = $param;
|
|
|
|
$param->label = 'string $param = ""';
|
|
|
|
|
|
|
|
$this->assertEquals($help, $result);
|
|
|
|
}
|
|
|
|
|
2017-01-20 20:31:18 +00:00
|
|
|
public function testFuncClosed()
|
2017-01-19 20:18:14 +00:00
|
|
|
{
|
|
|
|
$completionUri = pathToUri(__DIR__ . '/../../../fixtures/signatureHelp/funcClosed.php');
|
|
|
|
$this->loader->open($completionUri, file_get_contents($completionUri));
|
|
|
|
$result = $this->textDocument->signatureHelp(
|
|
|
|
new TextDocumentIdentifier($completionUri),
|
2017-01-20 20:31:18 +00:00
|
|
|
new Position(6, 10)
|
2017-01-19 20:18:14 +00:00
|
|
|
)->wait();
|
|
|
|
|
|
|
|
$help = new SignatureHelp;
|
|
|
|
$help->signatures = [];
|
|
|
|
$info = new SignatureInformation;
|
|
|
|
$help->signatures[] = $info;
|
2017-01-19 21:54:05 +00:00
|
|
|
$info->label = 'helpFunc1(int $count = 0)';
|
2017-01-19 20:18:14 +00:00
|
|
|
$info->parameters = [];
|
|
|
|
$param = new ParameterInformation;
|
|
|
|
$info->parameters[] = $param;
|
|
|
|
$param->label = 'int $count = 0';
|
|
|
|
|
|
|
|
$this->assertEquals($help, $result);
|
|
|
|
}
|
|
|
|
|
2017-01-20 20:31:18 +00:00
|
|
|
public function testFuncNotClosed()
|
2017-01-19 20:18:14 +00:00
|
|
|
{
|
|
|
|
$completionUri = pathToUri(__DIR__ . '/../../../fixtures/signatureHelp/funcNotClosed.php');
|
|
|
|
$this->loader->open($completionUri, file_get_contents($completionUri));
|
|
|
|
$result = $this->textDocument->signatureHelp(
|
|
|
|
new TextDocumentIdentifier($completionUri),
|
2017-01-20 20:31:18 +00:00
|
|
|
new Position(6, 10)
|
2017-01-19 20:18:14 +00:00
|
|
|
)->wait();
|
|
|
|
|
|
|
|
$help = new SignatureHelp;
|
|
|
|
$help->signatures = [];
|
|
|
|
$info = new SignatureInformation;
|
|
|
|
$help->signatures[] = $info;
|
2017-01-19 21:54:05 +00:00
|
|
|
$info->label = 'helpFunc2(int $count = 0)';
|
2017-01-19 20:18:14 +00:00
|
|
|
$info->parameters = [];
|
|
|
|
$param = new ParameterInformation;
|
|
|
|
$info->parameters[] = $param;
|
|
|
|
$param->label = 'int $count = 0';
|
|
|
|
|
|
|
|
$this->assertEquals($help, $result);
|
|
|
|
}
|
|
|
|
|
2017-01-20 20:31:18 +00:00
|
|
|
public function testStaticClosed()
|
2017-01-19 20:18:14 +00:00
|
|
|
{
|
|
|
|
$completionUri = pathToUri(__DIR__ . '/../../../fixtures/signatureHelp/staticClosed.php');
|
|
|
|
$this->loader->open($completionUri, file_get_contents($completionUri));
|
|
|
|
$result = $this->textDocument->signatureHelp(
|
|
|
|
new TextDocumentIdentifier($completionUri),
|
|
|
|
new Position(9, 19)
|
|
|
|
)->wait();
|
|
|
|
|
|
|
|
$help = new SignatureHelp;
|
|
|
|
$help->signatures = [];
|
|
|
|
$info = new SignatureInformation;
|
|
|
|
$help->signatures[] = $info;
|
2017-01-19 21:54:05 +00:00
|
|
|
$info->label = 'method(string $param = "")';
|
2017-01-19 20:18:14 +00:00
|
|
|
$info->parameters = [];
|
|
|
|
$param = new ParameterInformation;
|
|
|
|
$info->parameters[] = $param;
|
|
|
|
$param->label = 'string $param = ""';
|
|
|
|
|
|
|
|
$this->assertEquals($help, $result);
|
|
|
|
}
|
|
|
|
|
2017-01-20 20:31:18 +00:00
|
|
|
public function testStaticNotClosed()
|
2017-01-19 20:18:14 +00:00
|
|
|
{
|
|
|
|
$completionUri = pathToUri(__DIR__ . '/../../../fixtures/signatureHelp/staticNotClosed.php');
|
|
|
|
$this->loader->open($completionUri, file_get_contents($completionUri));
|
|
|
|
$result = $this->textDocument->signatureHelp(
|
|
|
|
new TextDocumentIdentifier($completionUri),
|
|
|
|
new Position(9, 19)
|
|
|
|
)->wait();
|
|
|
|
|
|
|
|
$help = new SignatureHelp;
|
|
|
|
$help->signatures = [];
|
|
|
|
$info = new SignatureInformation;
|
|
|
|
$help->signatures[] = $info;
|
2017-01-19 21:54:05 +00:00
|
|
|
$info->label = 'method(string $param = "")';
|
2017-01-19 20:18:14 +00:00
|
|
|
$info->parameters = [];
|
|
|
|
$param = new ParameterInformation;
|
|
|
|
$info->parameters[] = $param;
|
|
|
|
$param->label = 'string $param = ""';
|
|
|
|
|
|
|
|
$this->assertEquals($help, $result);
|
|
|
|
}
|
|
|
|
}
|