Remove wait(), async everything
parent
9a13d641fd
commit
1080d63fcf
|
@ -167,7 +167,7 @@ class LanguageServer extends AdvancedJsonRpc\Dispatcher
|
|||
*
|
||||
* @return Promise <void>
|
||||
*/
|
||||
private function indexProject()
|
||||
private function indexProject(): Promise
|
||||
{
|
||||
return coroutine(function () {
|
||||
$textDocuments = yield $this->globWorkspace('**/*.php');
|
||||
|
@ -175,16 +175,24 @@ class LanguageServer extends AdvancedJsonRpc\Dispatcher
|
|||
|
||||
$startTime = microtime(true);
|
||||
|
||||
foreach ($textDocuments as $i => $textDocument) {
|
||||
// Give LS to the chance to handle requests while indexing
|
||||
yield timeout();
|
||||
$this->client->window->logMessage(MessageType::INFO, "Parsing file $i/$count: {$textDocument->uri}");
|
||||
try {
|
||||
$this->project->loadDocument($textDocument->uri);
|
||||
} catch (Exception $e) {
|
||||
$this->client->window->logMessage(MessageType::ERROR, "Error parsing file $shortName: " . (string)$e);
|
||||
}
|
||||
}
|
||||
yield Promise\all(array_map(function ($textDocument, $i) use ($count) {
|
||||
return coroutine(function () use ($textDocument, $i, $count) {
|
||||
// Give LS to the chance to handle requests while indexing
|
||||
yield timeout();
|
||||
$this->client->window->logMessage(
|
||||
MessageType::INFO,
|
||||
"Parsing file $i/$count: {$textDocument->uri}"
|
||||
);
|
||||
try {
|
||||
yield $this->project->loadDocument($textDocument->uri);
|
||||
} catch (Exception $e) {
|
||||
$this->client->window->logMessage(
|
||||
MessageType::ERROR,
|
||||
"Error parsing file $shortName: " . (string)$e
|
||||
);
|
||||
}
|
||||
});
|
||||
}, $textDocuments, array_keys($textDocuments)));
|
||||
|
||||
$duration = (int)(microtime(true) - $startTime);
|
||||
$mem = (int)(memory_get_usage(true) / (1024 * 1024));
|
||||
|
|
|
@ -17,6 +17,8 @@ use PhpParser\{Error, ErrorHandler, Node, NodeTraverser};
|
|||
use PhpParser\NodeVisitor\NameResolver;
|
||||
use phpDocumentor\Reflection\DocBlockFactory;
|
||||
use function LanguageServer\Fqn\{getDefinedFqn, getVariableDefinition, getReferencedFqn};
|
||||
use Sabre\Event\Promise;
|
||||
use function Sabre\Event\coroutine;
|
||||
|
||||
class PhpDocument
|
||||
{
|
||||
|
@ -314,34 +316,36 @@ class PhpDocument
|
|||
* The definition node MAY be in another document, check the ownerDocument attribute
|
||||
*
|
||||
* @param Node $node
|
||||
* @return Node|null
|
||||
* @return Promise <Node|null>
|
||||
*/
|
||||
public function getDefinitionByNode(Node $node)
|
||||
public function getDefinitionByNode(Node $node): Promise
|
||||
{
|
||||
// Variables always stay in the boundary of the file and need to be searched inside their function scope
|
||||
// by traversing the AST
|
||||
if ($node instanceof Node\Expr\Variable) {
|
||||
return getVariableDefinition($node);
|
||||
}
|
||||
$fqn = getReferencedFqn($node);
|
||||
if (!isset($fqn)) {
|
||||
return null;
|
||||
}
|
||||
$document = $this->project->getDefinitionDocument($fqn);
|
||||
if (!isset($document)) {
|
||||
// If the node is a function or constant, it could be namespaced, but PHP falls back to global
|
||||
// http://php.net/manual/en/language.namespaces.fallback.php
|
||||
$parent = $node->getAttribute('parentNode');
|
||||
if ($parent instanceof Node\Expr\ConstFetch || $parent instanceof Node\Expr\FuncCall) {
|
||||
$parts = explode('\\', $fqn);
|
||||
$fqn = end($parts);
|
||||
$document = $this->project->getDefinitionDocument($fqn);
|
||||
return coroutine(function () use ($node) {
|
||||
// Variables always stay in the boundary of the file and need to be searched inside their function scope
|
||||
// by traversing the AST
|
||||
if ($node instanceof Node\Expr\Variable) {
|
||||
return getVariableDefinition($node);
|
||||
}
|
||||
}
|
||||
if (!isset($document)) {
|
||||
return null;
|
||||
}
|
||||
return $document->getDefinitionByFqn($fqn);
|
||||
$fqn = getReferencedFqn($node);
|
||||
if (!isset($fqn)) {
|
||||
return null;
|
||||
}
|
||||
$document = yield $this->project->getDefinitionDocument($fqn);
|
||||
if (!isset($document)) {
|
||||
// If the node is a function or constant, it could be namespaced, but PHP falls back to global
|
||||
// http://php.net/manual/en/language.namespaces.fallback.php
|
||||
$parent = $node->getAttribute('parentNode');
|
||||
if ($parent instanceof Node\Expr\ConstFetch || $parent instanceof Node\Expr\FuncCall) {
|
||||
$parts = explode('\\', $fqn);
|
||||
$fqn = end($parts);
|
||||
$document = yield $this->project->getDefinitionDocument($fqn);
|
||||
}
|
||||
}
|
||||
if (!isset($document)) {
|
||||
return null;
|
||||
}
|
||||
return $document->getDefinitionByFqn($fqn);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -349,45 +353,47 @@ class PhpDocument
|
|||
* The references node MAY be in other documents, check the ownerDocument attribute
|
||||
*
|
||||
* @param Node $node
|
||||
* @return Node[]
|
||||
* @return Promise <Node[]>
|
||||
*/
|
||||
public function getReferencesByNode(Node $node)
|
||||
public function getReferencesByNode(Node $node): Promise
|
||||
{
|
||||
// Variables always stay in the boundary of the file and need to be searched inside their function scope
|
||||
// by traversing the AST
|
||||
if ($node instanceof Node\Expr\Variable || $node instanceof Node\Param) {
|
||||
if ($node->name instanceof Node\Expr) {
|
||||
return null;
|
||||
return coroutine(function () use ($node) {
|
||||
// Variables always stay in the boundary of the file and need to be searched inside their function scope
|
||||
// by traversing the AST
|
||||
if ($node instanceof Node\Expr\Variable || $node instanceof Node\Param) {
|
||||
if ($node->name instanceof Node\Expr) {
|
||||
return null;
|
||||
}
|
||||
// Find function/method/closure scope
|
||||
$n = $node;
|
||||
while (isset($n) && !($n instanceof Node\FunctionLike)) {
|
||||
$n = $n->getAttribute('parentNode');
|
||||
}
|
||||
if (!isset($n)) {
|
||||
$n = $node->getAttribute('ownerDocument');
|
||||
}
|
||||
$traverser = new NodeTraverser;
|
||||
$refCollector = new VariableReferencesCollector($node->name);
|
||||
$traverser->addVisitor($refCollector);
|
||||
$traverser->traverse($n->getStmts());
|
||||
return $refCollector->references;
|
||||
}
|
||||
// Find function/method/closure scope
|
||||
$n = $node;
|
||||
while (isset($n) && !($n instanceof Node\FunctionLike)) {
|
||||
$n = $n->getAttribute('parentNode');
|
||||
// Definition with a global FQN
|
||||
$fqn = getDefinedFqn($node);
|
||||
if ($fqn === null) {
|
||||
return [];
|
||||
}
|
||||
if (!isset($n)) {
|
||||
$n = $node->getAttribute('ownerDocument');
|
||||
}
|
||||
$traverser = new NodeTraverser;
|
||||
$refCollector = new VariableReferencesCollector($node->name);
|
||||
$traverser->addVisitor($refCollector);
|
||||
$traverser->traverse($n->getStmts());
|
||||
return $refCollector->references;
|
||||
}
|
||||
// Definition with a global FQN
|
||||
$fqn = getDefinedFqn($node);
|
||||
if ($fqn === null) {
|
||||
return [];
|
||||
}
|
||||
$refDocuments = $this->project->getReferenceDocuments($fqn);
|
||||
$nodes = [];
|
||||
foreach ($refDocuments as $document) {
|
||||
$refs = $document->getReferencesByFqn($fqn);
|
||||
if ($refs !== null) {
|
||||
foreach ($refs as $ref) {
|
||||
$nodes[] = $ref;
|
||||
$refDocuments = yield $this->project->getReferenceDocuments($fqn);
|
||||
$nodes = [];
|
||||
foreach ($refDocuments as $document) {
|
||||
$refs = $document->getReferencesByFqn($fqn);
|
||||
if ($refs !== null) {
|
||||
foreach ($refs as $ref) {
|
||||
$nodes[] = $ref;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $nodes;
|
||||
return $nodes;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,8 @@ namespace LanguageServer;
|
|||
|
||||
use LanguageServer\Protocol\{SymbolInformation, TextDocumentIdentifier, ClientCapabilities};
|
||||
use phpDocumentor\Reflection\DocBlockFactory;
|
||||
use Sabre\Event\Promise;
|
||||
use function Sabre\Event\coroutine;
|
||||
|
||||
class Project
|
||||
{
|
||||
|
@ -68,18 +70,26 @@ class Project
|
|||
|
||||
/**
|
||||
* Returns the document indicated by uri.
|
||||
* If the document is not open, tries to read it from disk, but the document is not added the list of open documents.
|
||||
* Returns null if the document if not loaded.
|
||||
*
|
||||
* @param string $uri
|
||||
* @return LanguageServer\PhpDocument
|
||||
* @return PhpDocument|null
|
||||
*/
|
||||
public function getDocument(string $uri)
|
||||
{
|
||||
if (!isset($this->documents[$uri])) {
|
||||
return $this->loadDocument($uri);
|
||||
} else {
|
||||
return $this->documents[$uri];
|
||||
}
|
||||
return $this->documents[$uri] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the document indicated by uri.
|
||||
* If the document is not open, loads it.
|
||||
*
|
||||
* @param string $uri
|
||||
* @return Promise <PhpDocument>
|
||||
*/
|
||||
public function getOrLoadDocument(string $uri)
|
||||
{
|
||||
return isset($this->documents[$uri]) ? Promise\resolve($this->documents[$uri]) : $this->loadDocument($uri);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -87,23 +97,24 @@ class Project
|
|||
* The document is NOT added to the list of open documents, but definitions are registered.
|
||||
*
|
||||
* @param string $uri
|
||||
* @return Promise <LanguageServer\PhpDocument>
|
||||
* @return Promise <PhpDocument>
|
||||
*/
|
||||
public function loadDocument(string $uri)
|
||||
public function loadDocument(string $uri): Promise
|
||||
{
|
||||
if ($this->clientCapabilities->xcontentProvider) {
|
||||
// TODO: make this whole method async instead of calling wait()
|
||||
$content = $this->client->textDocument->xcontent(new TextDocumentIdentifier($uri))->wait()->text;
|
||||
} else {
|
||||
$content = file_get_contents(uriToPath($uri));
|
||||
}
|
||||
if (isset($this->documents[$uri])) {
|
||||
$document = $this->documents[$uri];
|
||||
$document->updateContent($content);
|
||||
} else {
|
||||
$document = new PhpDocument($uri, $content, $this, $this->client, $this->parser, $this->docBlockFactory);
|
||||
}
|
||||
return $document;
|
||||
return coroutine(function () use ($uri) {
|
||||
if ($this->clientCapabilities->xcontentProvider) {
|
||||
$content = (yield $this->client->textDocument->xcontent(new TextDocumentIdentifier($uri)))->text;
|
||||
} else {
|
||||
$content = file_get_contents(uriToPath($uri));
|
||||
}
|
||||
if (isset($this->documents[$uri])) {
|
||||
$document = $this->documents[$uri];
|
||||
$document->updateContent($content);
|
||||
} else {
|
||||
$document = new PhpDocument($uri, $content, $this, $this->client, $this->parser, $this->docBlockFactory);
|
||||
}
|
||||
return $document;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -234,14 +245,14 @@ class Project
|
|||
* Returns all documents that reference a symbol
|
||||
*
|
||||
* @param string $fqn The fully qualified name of the symbol
|
||||
* @return PhpDocument[]
|
||||
* @return Promise <PhpDocument[]>
|
||||
*/
|
||||
public function getReferenceDocuments(string $fqn)
|
||||
public function getReferenceDocuments(string $fqn): Promise
|
||||
{
|
||||
if (!isset($this->references[$fqn])) {
|
||||
return [];
|
||||
return Promise\resolve([]);
|
||||
}
|
||||
return array_map([$this, 'getDocument'], $this->references[$fqn]);
|
||||
return Promise\all(array_map([$this, 'getOrLoadDocument'], $this->references[$fqn]));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -270,11 +281,14 @@ class Project
|
|||
* Returns the document where a symbol is defined
|
||||
*
|
||||
* @param string $fqn The fully qualified name of the symbol
|
||||
* @return PhpDocument|null
|
||||
* @return Promise <PhpDocument|null>
|
||||
*/
|
||||
public function getDefinitionDocument(string $fqn)
|
||||
public function getDefinitionDocument(string $fqn): Promise
|
||||
{
|
||||
return isset($this->symbols[$fqn]) ? $this->getDocument($this->symbols[$fqn]->location->uri) : null;
|
||||
if (!isset($this->symbols[$fqn])) {
|
||||
return Promise\resolve(null);
|
||||
}
|
||||
return $this->getOrLoadDocument($this->symbols[$fqn]->location->uri);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -3,7 +3,7 @@ declare(strict_types = 1);
|
|||
|
||||
namespace LanguageServer\Server;
|
||||
|
||||
use LanguageServer\{LanguageClient, Project};
|
||||
use LanguageServer\{LanguageClient, Project, PhpDocument};
|
||||
use PhpParser\PrettyPrinter\Standard as PrettyPrinter;
|
||||
use PhpParser\Node;
|
||||
use LanguageServer\Protocol\{
|
||||
|
@ -20,6 +20,8 @@ use LanguageServer\Protocol\{
|
|||
Hover,
|
||||
MarkedString
|
||||
};
|
||||
use Sabre\Event\Promise;
|
||||
use function Sabre\Event\coroutine;
|
||||
|
||||
/**
|
||||
* Provides method handlers for all textDocument/* methods
|
||||
|
@ -55,11 +57,13 @@ class TextDocument
|
|||
* document.
|
||||
*
|
||||
* @param \LanguageServer\Protocol\TextDocumentIdentifier $textDocument
|
||||
* @return SymbolInformation[]
|
||||
* @return Promise <SymbolInformation[]>
|
||||
*/
|
||||
public function documentSymbol(TextDocumentIdentifier $textDocument): array
|
||||
public function documentSymbol(TextDocumentIdentifier $textDocument): Promise
|
||||
{
|
||||
return array_values($this->project->getDocument($textDocument->uri)->getSymbols());
|
||||
return $this->project->getOrLoadDocument($textDocument->uri)->then(function (PhpDocument $document) {
|
||||
return array_values($document->getSymbols());
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -105,11 +109,13 @@ class TextDocument
|
|||
*
|
||||
* @param TextDocumentIdentifier $textDocument The document to format
|
||||
* @param FormattingOptions $options The format options
|
||||
* @return TextEdit[]
|
||||
* @return Promise <TextEdit[]>
|
||||
*/
|
||||
public function formatting(TextDocumentIdentifier $textDocument, FormattingOptions $options)
|
||||
{
|
||||
return $this->project->getDocument($textDocument->uri)->getFormattedText();
|
||||
return $this->project->getOrLoadDocument($textDocument->uri)->then(function (PhpDocument $document) {
|
||||
return $document->getFormattedText();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -117,21 +123,26 @@ class TextDocument
|
|||
* denoted by the given text document position.
|
||||
*
|
||||
* @param ReferenceContext $context
|
||||
* @return Location[]
|
||||
* @return Promise <Location[]>
|
||||
*/
|
||||
public function references(ReferenceContext $context, TextDocumentIdentifier $textDocument, Position $position): array
|
||||
{
|
||||
$document = $this->project->getDocument($textDocument->uri);
|
||||
$node = $document->getNodeAtPosition($position);
|
||||
if ($node === null) {
|
||||
return [];
|
||||
}
|
||||
$refs = $document->getReferencesByNode($node);
|
||||
$locations = [];
|
||||
foreach ($refs as $ref) {
|
||||
$locations[] = Location::fromNode($ref);
|
||||
}
|
||||
return $locations;
|
||||
public function references(
|
||||
ReferenceContext $context,
|
||||
TextDocumentIdentifier $textDocument,
|
||||
Position $position
|
||||
): Promise {
|
||||
return coroutine(function () use ($textDocument, $position) {
|
||||
$document = yield $this->project->getOrLoadDocument($textDocument->uri);
|
||||
$node = $document->getNodeAtPosition($position);
|
||||
if ($node === null) {
|
||||
return [];
|
||||
}
|
||||
$refs = yield $document->getReferencesByNode($node);
|
||||
$locations = [];
|
||||
foreach ($refs as $ref) {
|
||||
$locations[] = Location::fromNode($ref);
|
||||
}
|
||||
return $locations;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -140,20 +151,22 @@ class TextDocument
|
|||
*
|
||||
* @param TextDocumentIdentifier $textDocument The text document
|
||||
* @param Position $position The position inside the text document
|
||||
* @return Location|Location[]
|
||||
* @return Promise <Location|Location[]>
|
||||
*/
|
||||
public function definition(TextDocumentIdentifier $textDocument, Position $position)
|
||||
public function definition(TextDocumentIdentifier $textDocument, Position $position): Promise
|
||||
{
|
||||
$document = $this->project->getDocument($textDocument->uri);
|
||||
$node = $document->getNodeAtPosition($position);
|
||||
if ($node === null) {
|
||||
return [];
|
||||
}
|
||||
$def = $document->getDefinitionByNode($node);
|
||||
if ($def === null) {
|
||||
return [];
|
||||
}
|
||||
return Location::fromNode($def);
|
||||
return coroutine(function () use ($textDocument, $position) {
|
||||
$document = yield $this->project->getOrLoadDocument($textDocument->uri);
|
||||
$node = $document->getNodeAtPosition($position);
|
||||
if ($node === null) {
|
||||
return [];
|
||||
}
|
||||
$def = yield $document->getDefinitionByNode($node);
|
||||
if ($def === null) {
|
||||
return [];
|
||||
}
|
||||
return Location::fromNode($def);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -161,66 +174,68 @@ class TextDocument
|
|||
*
|
||||
* @param TextDocumentIdentifier $textDocument The text document
|
||||
* @param Position $position The position inside the text document
|
||||
* @return Hover
|
||||
* @return Promise <Hover>
|
||||
*/
|
||||
public function hover(TextDocumentIdentifier $textDocument, Position $position): Hover
|
||||
public function hover(TextDocumentIdentifier $textDocument, Position $position): Promise
|
||||
{
|
||||
$document = $this->project->getDocument($textDocument->uri);
|
||||
// Find the node under the cursor
|
||||
$node = $document->getNodeAtPosition($position);
|
||||
if ($node === null) {
|
||||
return new Hover([]);
|
||||
}
|
||||
$range = Range::fromNode($node);
|
||||
// Get the definition node for whatever node is under the cursor
|
||||
$def = $document->getDefinitionByNode($node);
|
||||
if ($def === null) {
|
||||
return new Hover([], $range);
|
||||
}
|
||||
$contents = [];
|
||||
return coroutine(function () use ($textDocument, $position) {
|
||||
$document = yield $this->project->getOrLoadDocument($textDocument->uri);
|
||||
// Find the node under the cursor
|
||||
$node = $document->getNodeAtPosition($position);
|
||||
if ($node === null) {
|
||||
return new Hover([]);
|
||||
}
|
||||
$range = Range::fromNode($node);
|
||||
// Get the definition node for whatever node is under the cursor
|
||||
$def = yield $document->getDefinitionByNode($node);
|
||||
if ($def === null) {
|
||||
return new Hover([], $range);
|
||||
}
|
||||
$contents = [];
|
||||
|
||||
// Build a declaration string
|
||||
if ($def instanceof Node\Stmt\PropertyProperty || $def instanceof Node\Const_) {
|
||||
// Properties and constants can have multiple declarations
|
||||
// Use the parent node (that includes the modifiers), but only render the requested declaration
|
||||
$child = $def;
|
||||
$def = $def->getAttribute('parentNode');
|
||||
$defLine = clone $def;
|
||||
$defLine->props = [$child];
|
||||
} else {
|
||||
$defLine = clone $def;
|
||||
}
|
||||
// Don't include the docblock in the declaration string
|
||||
$defLine->setAttribute('comments', []);
|
||||
if (isset($defLine->stmts)) {
|
||||
$defLine->stmts = [];
|
||||
}
|
||||
$defText = $this->prettyPrinter->prettyPrint([$defLine]);
|
||||
$lines = explode("\n", $defText);
|
||||
if (isset($lines[0])) {
|
||||
$contents[] = new MarkedString('php', "<?php\n" . $lines[0]);
|
||||
}
|
||||
// Build a declaration string
|
||||
if ($def instanceof Node\Stmt\PropertyProperty || $def instanceof Node\Const_) {
|
||||
// Properties and constants can have multiple declarations
|
||||
// Use the parent node (that includes the modifiers), but only render the requested declaration
|
||||
$child = $def;
|
||||
$def = $def->getAttribute('parentNode');
|
||||
$defLine = clone $def;
|
||||
$defLine->props = [$child];
|
||||
} else {
|
||||
$defLine = clone $def;
|
||||
}
|
||||
// Don't include the docblock in the declaration string
|
||||
$defLine->setAttribute('comments', []);
|
||||
if (isset($defLine->stmts)) {
|
||||
$defLine->stmts = [];
|
||||
}
|
||||
$defText = $this->prettyPrinter->prettyPrint([$defLine]);
|
||||
$lines = explode("\n", $defText);
|
||||
if (isset($lines[0])) {
|
||||
$contents[] = new MarkedString('php', "<?php\n" . $lines[0]);
|
||||
}
|
||||
|
||||
// Get the documentation string
|
||||
if ($def instanceof Node\Param) {
|
||||
$fn = $def->getAttribute('parentNode');
|
||||
$docBlock = $fn->getAttribute('docBlock');
|
||||
if ($docBlock !== null) {
|
||||
$tags = $docBlock->getTagsByName('param');
|
||||
foreach ($tags as $tag) {
|
||||
if ($tag->getVariableName() === $def->name) {
|
||||
$contents[] = $tag->getDescription()->render();
|
||||
break;
|
||||
// Get the documentation string
|
||||
if ($def instanceof Node\Param) {
|
||||
$fn = $def->getAttribute('parentNode');
|
||||
$docBlock = $fn->getAttribute('docBlock');
|
||||
if ($docBlock !== null) {
|
||||
$tags = $docBlock->getTagsByName('param');
|
||||
foreach ($tags as $tag) {
|
||||
if ($tag->getVariableName() === $def->name) {
|
||||
$contents[] = $tag->getDescription()->render();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$docBlock = $def->getAttribute('docBlock');
|
||||
if ($docBlock !== null) {
|
||||
$contents[] = $docBlock->getSummary();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$docBlock = $def->getAttribute('docBlock');
|
||||
if ($docBlock !== null) {
|
||||
$contents[] = $docBlock->getSummary();
|
||||
}
|
||||
}
|
||||
|
||||
return new Hover($contents, $range);
|
||||
return new Hover($contents, $range);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ class DefinitionCollectorTest extends TestCase
|
|||
$project = new Project($client, new ClientCapabilities);
|
||||
$parser = new Parser;
|
||||
$uri = pathToUri(realpath(__DIR__ . '/../../fixtures/symbols.php'));
|
||||
$document = $project->loadDocument($uri);
|
||||
$document = $project->loadDocument($uri)->wait();
|
||||
$traverser = new NodeTraverser;
|
||||
$traverser->addVisitor(new NameResolver);
|
||||
$traverser->addVisitor(new ReferencesAdder($document));
|
||||
|
@ -59,7 +59,7 @@ class DefinitionCollectorTest extends TestCase
|
|||
$project = new Project($client, new ClientCapabilities);
|
||||
$parser = new Parser;
|
||||
$uri = pathToUri(realpath(__DIR__ . '/../../fixtures/references.php'));
|
||||
$document = $project->loadDocument($uri);
|
||||
$document = $project->loadDocument($uri)->wait();
|
||||
$traverser = new NodeTraverser;
|
||||
$traverser->addVisitor(new NameResolver);
|
||||
$traverser->addVisitor(new ReferencesAdder($document));
|
||||
|
|
|
@ -30,9 +30,9 @@ class ProjectTest extends TestCase
|
|||
$this->project = new Project($client, new ClientCapabilities);
|
||||
}
|
||||
|
||||
public function testGetDocumentLoadsDocument()
|
||||
public function testGetOrLoadDocumentLoadsDocument()
|
||||
{
|
||||
$document = $this->project->getDocument(pathToUri(__FILE__));
|
||||
$document = $this->project->getOrLoadDocument(pathToUri(__FILE__))->wait();
|
||||
|
||||
$this->assertNotNull($document);
|
||||
$this->assertInstanceOf(PhpDocument::class, $document);
|
||||
|
|
|
@ -8,6 +8,7 @@ use LanguageServer\Tests\MockProtocolStream;
|
|||
use LanguageServer\{Server, LanguageClient, Project};
|
||||
use LanguageServer\Protocol\{Position, Location, Range, ClientCapabilities};
|
||||
use function LanguageServer\pathToUri;
|
||||
use Sabre\Event\Promise;
|
||||
|
||||
abstract class ServerTestCase extends TestCase
|
||||
{
|
||||
|
@ -53,11 +54,13 @@ abstract class ServerTestCase extends TestCase
|
|||
$referencesUri = pathToUri(realpath(__DIR__ . '/../../fixtures/references.php'));
|
||||
$useUri = pathToUri(realpath(__DIR__ . '/../../fixtures/use.php'));
|
||||
|
||||
$this->project->loadDocument($symbolsUri);
|
||||
$this->project->loadDocument($referencesUri);
|
||||
$this->project->loadDocument($globalSymbolsUri);
|
||||
$this->project->loadDocument($globalReferencesUri);
|
||||
$this->project->loadDocument($useUri);
|
||||
Promise\all([
|
||||
$this->project->loadDocument($symbolsUri),
|
||||
$this->project->loadDocument($referencesUri),
|
||||
$this->project->loadDocument($globalSymbolsUri),
|
||||
$this->project->loadDocument($globalReferencesUri),
|
||||
$this->project->loadDocument($useUri)
|
||||
])->wait();
|
||||
|
||||
// @codingStandardsIgnoreStart
|
||||
$this->definitionLocations = [
|
||||
|
|
|
@ -7,6 +7,7 @@ use LanguageServer\Tests\MockProtocolStream;
|
|||
use LanguageServer\Tests\Server\ServerTestCase;
|
||||
use LanguageServer\{Server, LanguageClient, Project};
|
||||
use LanguageServer\Protocol\{TextDocumentIdentifier, Position, Range, Location, ClientCapabilities};
|
||||
use Sabre\Event\Promise;
|
||||
|
||||
class GlobalFallbackTest extends ServerTestCase
|
||||
{
|
||||
|
@ -23,7 +24,10 @@ class GlobalFallbackTest extends ServerTestCase
|
|||
{
|
||||
// $obj = new TestClass();
|
||||
// Get definition for TestClass should not fall back to global
|
||||
$result = $this->textDocument->definition(new TextDocumentIdentifier('global_fallback'), new Position(9, 16));
|
||||
$result = $this->textDocument->definition(
|
||||
new TextDocumentIdentifier('global_fallback'),
|
||||
new Position(9, 16)
|
||||
)->wait();
|
||||
$this->assertEquals([], $result);
|
||||
}
|
||||
|
||||
|
@ -31,7 +35,10 @@ class GlobalFallbackTest extends ServerTestCase
|
|||
{
|
||||
// echo TEST_CONST;
|
||||
// Get definition for TEST_CONST
|
||||
$result = $this->textDocument->definition(new TextDocumentIdentifier('global_fallback'), new Position(6, 10));
|
||||
$result = $this->textDocument->definition(
|
||||
new TextDocumentIdentifier('global_fallback'),
|
||||
new Position(6, 10)
|
||||
)->wait();
|
||||
$this->assertEquals(new Location('global_symbols', new Range(new Position(9, 6), new Position(9, 22))), $result);
|
||||
}
|
||||
|
||||
|
@ -39,7 +46,10 @@ class GlobalFallbackTest extends ServerTestCase
|
|||
{
|
||||
// test_function();
|
||||
// Get definition for test_function
|
||||
$result = $this->textDocument->definition(new TextDocumentIdentifier('global_fallback'), new Position(5, 6));
|
||||
$result = $this->textDocument->definition(
|
||||
new TextDocumentIdentifier('global_fallback'),
|
||||
new Position(5, 6)
|
||||
)->wait();
|
||||
$this->assertEquals(new Location('global_symbols', new Range(new Position(78, 0), new Position(81, 1))), $result);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,14 +12,20 @@ class GlobalTest extends ServerTestCase
|
|||
public function testDefinitionFileBeginning()
|
||||
{
|
||||
// |<?php
|
||||
$result = $this->textDocument->definition(new TextDocumentIdentifier(pathToUri(realpath(__DIR__ . '/../../../../fixtures/references.php'))), new Position(0, 0));
|
||||
$result = $this->textDocument->definition(
|
||||
new TextDocumentIdentifier(pathToUri(realpath(__DIR__ . '/../../../../fixtures/references.php'))),
|
||||
new Position(0, 0)
|
||||
)->wait();
|
||||
$this->assertEquals([], $result);
|
||||
}
|
||||
|
||||
public function testDefinitionEmptyResult()
|
||||
{
|
||||
// namespace keyword
|
||||
$result = $this->textDocument->definition(new TextDocumentIdentifier(pathToUri(realpath(__DIR__ . '/../../../../fixtures/references.php'))), new Position(2, 4));
|
||||
$result = $this->textDocument->definition(
|
||||
new TextDocumentIdentifier(pathToUri(realpath(__DIR__ . '/../../../../fixtures/references.php'))),
|
||||
new Position(2, 4)
|
||||
)->wait();
|
||||
$this->assertEquals([], $result);
|
||||
}
|
||||
|
||||
|
@ -28,7 +34,10 @@ class GlobalTest extends ServerTestCase
|
|||
// $obj = new TestClass();
|
||||
// Get definition for TestClass
|
||||
$reference = $this->getReferenceLocations('TestClass')[0];
|
||||
$result = $this->textDocument->definition(new TextDocumentIdentifier($reference->uri), $reference->range->start);
|
||||
$result = $this->textDocument->definition(
|
||||
new TextDocumentIdentifier($reference->uri),
|
||||
$reference->range->start
|
||||
)->wait();
|
||||
$this->assertEquals($this->getDefinitionLocation('TestClass'), $result);
|
||||
}
|
||||
|
||||
|
@ -37,7 +46,10 @@ class GlobalTest extends ServerTestCase
|
|||
// TestClass::staticTestMethod();
|
||||
// Get definition for TestClass
|
||||
$reference = $this->getReferenceLocations('TestClass')[1];
|
||||
$result = $this->textDocument->definition(new TextDocumentIdentifier($reference->uri), $reference->range->start);
|
||||
$result = $this->textDocument->definition(
|
||||
new TextDocumentIdentifier($reference->uri),
|
||||
$reference->range->start
|
||||
)->wait();
|
||||
$this->assertEquals($this->getDefinitionLocation('TestClass'), $result);
|
||||
}
|
||||
|
||||
|
@ -46,7 +58,10 @@ class GlobalTest extends ServerTestCase
|
|||
// echo TestClass::$staticTestProperty;
|
||||
// Get definition for TestClass
|
||||
$reference = $this->getReferenceLocations('TestClass')[2];
|
||||
$result = $this->textDocument->definition(new TextDocumentIdentifier($reference->uri), $reference->range->start);
|
||||
$result = $this->textDocument->definition(
|
||||
new TextDocumentIdentifier($reference->uri),
|
||||
$reference->range->start
|
||||
)->wait();
|
||||
$this->assertEquals($this->getDefinitionLocation('TestClass'), $result);
|
||||
}
|
||||
|
||||
|
@ -55,7 +70,10 @@ class GlobalTest extends ServerTestCase
|
|||
// TestClass::TEST_CLASS_CONST;
|
||||
// Get definition for TestClass
|
||||
$reference = $this->getReferenceLocations('TestClass')[3];
|
||||
$result = $this->textDocument->definition(new TextDocumentIdentifier($reference->uri), $reference->range->start);
|
||||
$result = $this->textDocument->definition(
|
||||
new TextDocumentIdentifier($reference->uri),
|
||||
$reference->range->start
|
||||
)->wait();
|
||||
$this->assertEquals($this->getDefinitionLocation('TestClass'), $result);
|
||||
}
|
||||
|
||||
|
@ -64,7 +82,10 @@ class GlobalTest extends ServerTestCase
|
|||
// class TestClass implements TestInterface
|
||||
// Get definition for TestInterface
|
||||
$reference = $this->getReferenceLocations('TestInterface')[0];
|
||||
$result = $this->textDocument->definition(new TextDocumentIdentifier($reference->uri), $reference->range->start);
|
||||
$result = $this->textDocument->definition(
|
||||
new TextDocumentIdentifier($reference->uri),
|
||||
$reference->range->start
|
||||
)->wait();
|
||||
$this->assertEquals($this->getDefinitionLocation('TestInterface'), $result);
|
||||
}
|
||||
|
||||
|
@ -73,7 +94,10 @@ class GlobalTest extends ServerTestCase
|
|||
// echo TestClass::TEST_CLASS_CONST;
|
||||
// Get definition for TEST_CLASS_CONST
|
||||
$reference = $this->getReferenceLocations('TestClass::TEST_CLASS_CONST')[1];
|
||||
$result = $this->textDocument->definition(new TextDocumentIdentifier($reference->uri), $reference->range->end);
|
||||
$result = $this->textDocument->definition(
|
||||
new TextDocumentIdentifier($reference->uri),
|
||||
$reference->range->end
|
||||
)->wait();
|
||||
$this->assertEquals($this->getDefinitionLocation('TestClass::TEST_CLASS_CONST'), $result);
|
||||
}
|
||||
|
||||
|
@ -82,7 +106,10 @@ class GlobalTest extends ServerTestCase
|
|||
// echo self::TEST_CLASS_CONST;
|
||||
// Get definition for TEST_CLASS_CONST
|
||||
$reference = $this->getReferenceLocations('TestClass::TEST_CLASS_CONST')[0];
|
||||
$result = $this->textDocument->definition(new TextDocumentIdentifier($reference->uri), $reference->range->end);
|
||||
$result = $this->textDocument->definition(
|
||||
new TextDocumentIdentifier($reference->uri),
|
||||
$reference->range->end
|
||||
)->wait();
|
||||
$this->assertEquals($this->getDefinitionLocation('TestClass::TEST_CLASS_CONST'), $result);
|
||||
}
|
||||
|
||||
|
@ -91,7 +118,10 @@ class GlobalTest extends ServerTestCase
|
|||
// echo TEST_CONST;
|
||||
// Get definition for TEST_CONST
|
||||
$reference = $this->getReferenceLocations('TEST_CONST')[1];
|
||||
$result = $this->textDocument->definition(new TextDocumentIdentifier($reference->uri), $reference->range->start);
|
||||
$result = $this->textDocument->definition(
|
||||
new TextDocumentIdentifier($reference->uri),
|
||||
$reference->range->start
|
||||
)->wait();
|
||||
$this->assertEquals($this->getDefinitionLocation('TEST_CONST'), $result);
|
||||
}
|
||||
|
||||
|
@ -100,7 +130,10 @@ class GlobalTest extends ServerTestCase
|
|||
// TestClass::staticTestMethod();
|
||||
// Get definition for staticTestMethod
|
||||
$reference = $this->getReferenceLocations('TestClass::staticTestMethod()')[0];
|
||||
$result = $this->textDocument->definition(new TextDocumentIdentifier($reference->uri), $reference->range->end);
|
||||
$result = $this->textDocument->definition(
|
||||
new TextDocumentIdentifier($reference->uri),
|
||||
$reference->range->end
|
||||
)->wait();
|
||||
$this->assertEquals($this->getDefinitionLocation('TestClass::staticTestMethod()'), $result);
|
||||
}
|
||||
|
||||
|
@ -109,7 +142,10 @@ class GlobalTest extends ServerTestCase
|
|||
// echo TestClass::$staticTestProperty;
|
||||
// Get definition for staticTestProperty
|
||||
$reference = $this->getReferenceLocations('TestClass::staticTestProperty')[0];
|
||||
$result = $this->textDocument->definition(new TextDocumentIdentifier($reference->uri), $reference->range->end);
|
||||
$result = $this->textDocument->definition(
|
||||
new TextDocumentIdentifier($reference->uri),
|
||||
$reference->range->end
|
||||
)->wait();
|
||||
$this->assertEquals($this->getDefinitionLocation('TestClass::staticTestProperty'), $result);
|
||||
}
|
||||
|
||||
|
@ -118,7 +154,10 @@ class GlobalTest extends ServerTestCase
|
|||
// $obj->testMethod();
|
||||
// Get definition for testMethod
|
||||
$reference = $this->getReferenceLocations('TestClass::testMethod()')[0];
|
||||
$result = $this->textDocument->definition(new TextDocumentIdentifier($reference->uri), $reference->range->end);
|
||||
$result = $this->textDocument->definition(
|
||||
new TextDocumentIdentifier($reference->uri),
|
||||
$reference->range->end
|
||||
)->wait();
|
||||
$this->assertEquals($this->getDefinitionLocation('TestClass::testMethod()'), $result);
|
||||
}
|
||||
|
||||
|
@ -127,7 +166,10 @@ class GlobalTest extends ServerTestCase
|
|||
// echo $obj->testProperty;
|
||||
// Get definition for testProperty
|
||||
$reference = $this->getReferenceLocations('TestClass::testProperty')[1];
|
||||
$result = $this->textDocument->definition(new TextDocumentIdentifier($reference->uri), $reference->range->end);
|
||||
$result = $this->textDocument->definition(
|
||||
new TextDocumentIdentifier($reference->uri),
|
||||
$reference->range->end
|
||||
)->wait();
|
||||
$this->assertEquals($this->getDefinitionLocation('TestClass::testProperty'), $result);
|
||||
}
|
||||
|
||||
|
@ -136,7 +178,10 @@ class GlobalTest extends ServerTestCase
|
|||
// $this->testProperty = $testParameter;
|
||||
// Get definition for testProperty
|
||||
$reference = $this->getReferenceLocations('TestClass::testProperty')[0];
|
||||
$result = $this->textDocument->definition(new TextDocumentIdentifier($reference->uri), $reference->range->end);
|
||||
$result = $this->textDocument->definition(
|
||||
new TextDocumentIdentifier($reference->uri),
|
||||
$reference->range->end
|
||||
)->wait();
|
||||
$this->assertEquals($this->getDefinitionLocation('TestClass::testProperty'), $result);
|
||||
}
|
||||
|
||||
|
@ -145,7 +190,10 @@ class GlobalTest extends ServerTestCase
|
|||
// echo $var;
|
||||
// Get definition for $var
|
||||
$uri = pathToUri(realpath(__DIR__ . '/../../../../fixtures/references.php'));
|
||||
$result = $this->textDocument->definition(new TextDocumentIdentifier($uri), new Position(13, 7));
|
||||
$result = $this->textDocument->definition(
|
||||
new TextDocumentIdentifier($uri),
|
||||
new Position(13, 7)
|
||||
)->wait();
|
||||
$this->assertEquals(new Location($uri, new Range(new Position(12, 0), new Position(12, 10))), $result);
|
||||
}
|
||||
|
||||
|
@ -154,7 +202,10 @@ class GlobalTest extends ServerTestCase
|
|||
// function whatever(TestClass $param) {
|
||||
// Get definition for TestClass
|
||||
$reference = $this->getReferenceLocations('TestClass')[4];
|
||||
$result = $this->textDocument->definition(new TextDocumentIdentifier($reference->uri), $reference->range->start);
|
||||
$result = $this->textDocument->definition(
|
||||
new TextDocumentIdentifier($reference->uri),
|
||||
$reference->range->start
|
||||
)->wait();
|
||||
$this->assertEquals($this->getDefinitionLocation('TestClass'), $result);
|
||||
}
|
||||
|
||||
|
@ -163,7 +214,10 @@ class GlobalTest extends ServerTestCase
|
|||
// function whatever(TestClass $param): TestClass {
|
||||
// Get definition for TestClass
|
||||
$reference = $this->getReferenceLocations('TestClass')[5];
|
||||
$result = $this->textDocument->definition(new TextDocumentIdentifier($reference->uri), $reference->range->start);
|
||||
$result = $this->textDocument->definition(
|
||||
new TextDocumentIdentifier($reference->uri),
|
||||
$reference->range->start
|
||||
)->wait();
|
||||
$this->assertEquals($this->getDefinitionLocation('TestClass'), $result);
|
||||
}
|
||||
|
||||
|
@ -172,7 +226,10 @@ class GlobalTest extends ServerTestCase
|
|||
// public function testMethod($testParameter): TestInterface
|
||||
// Get definition for TestInterface
|
||||
$reference = $this->getReferenceLocations('TestInterface')[1];
|
||||
$result = $this->textDocument->definition(new TextDocumentIdentifier($reference->uri), $reference->range->start);
|
||||
$result = $this->textDocument->definition(
|
||||
new TextDocumentIdentifier($reference->uri),
|
||||
$reference->range->start
|
||||
)->wait();
|
||||
$this->assertEquals($this->getDefinitionLocation('TestInterface'), $result);
|
||||
}
|
||||
|
||||
|
@ -181,7 +238,10 @@ class GlobalTest extends ServerTestCase
|
|||
// echo $param;
|
||||
// Get definition for $param
|
||||
$uri = pathToUri(realpath(__DIR__ . '/../../../../fixtures/references.php'));
|
||||
$result = $this->textDocument->definition(new TextDocumentIdentifier($uri), new Position(22, 13));
|
||||
$result = $this->textDocument->definition(
|
||||
new TextDocumentIdentifier($uri),
|
||||
new Position(22, 13)
|
||||
)->wait();
|
||||
$this->assertEquals(new Location($uri, new Range(new Position(21, 18), new Position(21, 34))), $result);
|
||||
}
|
||||
|
||||
|
@ -190,7 +250,10 @@ class GlobalTest extends ServerTestCase
|
|||
// echo $var;
|
||||
// Get definition for $var
|
||||
$uri = pathToUri(realpath(__DIR__ . '/../../../../fixtures/references.php'));
|
||||
$result = $this->textDocument->definition(new TextDocumentIdentifier($uri), new Position(26, 11));
|
||||
$result = $this->textDocument->definition(
|
||||
new TextDocumentIdentifier($uri),
|
||||
new Position(26, 11)
|
||||
)->wait();
|
||||
$this->assertEquals(new Location($uri, new Range(new Position(25, 22), new Position(25, 26))), $result);
|
||||
}
|
||||
|
||||
|
@ -199,7 +262,10 @@ class GlobalTest extends ServerTestCase
|
|||
// test_function();
|
||||
// Get definition for test_function
|
||||
$reference = $this->getReferenceLocations('test_function()')[0];
|
||||
$result = $this->textDocument->definition(new TextDocumentIdentifier($reference->uri), $reference->range->start);
|
||||
$result = $this->textDocument->definition(
|
||||
new TextDocumentIdentifier($reference->uri),
|
||||
$reference->range->start
|
||||
)->wait();
|
||||
$this->assertEquals($this->getDefinitionLocation('test_function()'), $result);
|
||||
}
|
||||
|
||||
|
@ -208,7 +274,10 @@ class GlobalTest extends ServerTestCase
|
|||
// use function test_function;
|
||||
// Get definition for test_function
|
||||
$reference = $this->getReferenceLocations('test_function()')[1];
|
||||
$result = $this->textDocument->definition(new TextDocumentIdentifier($reference->uri), $reference->range->start);
|
||||
$result = $this->textDocument->definition(
|
||||
new TextDocumentIdentifier($reference->uri),
|
||||
$reference->range->start
|
||||
)->wait();
|
||||
$this->assertEquals($this->getDefinitionLocation('test_function()'), $result);
|
||||
}
|
||||
|
||||
|
@ -217,7 +286,10 @@ class GlobalTest extends ServerTestCase
|
|||
// if ($abc instanceof TestInterface) {
|
||||
// Get definition for TestInterface
|
||||
$reference = $this->getReferenceLocations('TestInterface')[2];
|
||||
$result = $this->textDocument->definition(new TextDocumentIdentifier($reference->uri), $reference->range->start);
|
||||
$result = $this->textDocument->definition(
|
||||
new TextDocumentIdentifier($reference->uri),
|
||||
$reference->range->start
|
||||
)->wait();
|
||||
$this->assertEquals($this->getDefinitionLocation('TestInterface'), $result);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,7 +23,10 @@ class NamespacedTest extends GlobalTest
|
|||
// echo TEST_CONST;
|
||||
// Get definition for TEST_CONST
|
||||
$reference = $this->getReferenceLocations('TEST_CONST')[0];
|
||||
$result = $this->textDocument->definition(new TextDocumentIdentifier($reference->uri), $reference->range->start);
|
||||
$result = $this->textDocument->definition(
|
||||
new TextDocumentIdentifier($reference->uri),
|
||||
$reference->range->start
|
||||
)->wait();
|
||||
$this->assertEquals($this->getDefinitionLocation('TEST_CONST'), $result);
|
||||
}
|
||||
|
||||
|
@ -32,7 +35,10 @@ class NamespacedTest extends GlobalTest
|
|||
// use TestNamespace\TestClass;
|
||||
// Get definition for TestClass
|
||||
$reference = $this->getReferenceLocations('TestClass')[6];
|
||||
$result = $this->textDocument->definition(new TextDocumentIdentifier($reference->uri), $reference->range->start);
|
||||
$result = $this->textDocument->definition(
|
||||
new TextDocumentIdentifier($reference->uri),
|
||||
$reference->range->start
|
||||
)->wait();
|
||||
$this->assertEquals($this->getDefinitionLocation('TestClass'), $result);
|
||||
}
|
||||
|
||||
|
@ -41,7 +47,10 @@ class NamespacedTest extends GlobalTest
|
|||
// use TestNamespace\{TestTrait, TestInterface};
|
||||
// Get definition for TestInterface
|
||||
$reference = $this->getReferenceLocations('TestClass')[0];
|
||||
$result = $this->textDocument->definition(new TextDocumentIdentifier($reference->uri), $reference->range->start);
|
||||
$result = $this->textDocument->definition(
|
||||
new TextDocumentIdentifier($reference->uri),
|
||||
$reference->range->start
|
||||
)->wait();
|
||||
$this->assertEquals($this->getDefinitionLocation('TestClass'), $result);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ class DocumentSymbolTest extends ServerTestCase
|
|||
{
|
||||
// Request symbols
|
||||
$uri = pathToUri(realpath(__DIR__ . '/../../../fixtures/symbols.php'));
|
||||
$result = $this->textDocument->documentSymbol(new TextDocumentIdentifier($uri));
|
||||
$result = $this->textDocument->documentSymbol(new TextDocumentIdentifier($uri))->wait();
|
||||
// @codingStandardsIgnoreStart
|
||||
$this->assertEquals([
|
||||
new SymbolInformation('TEST_CONST', SymbolKind::CONSTANT, $this->getDefinitionLocation('TestNamespace\\TEST_CONST'), 'TestNamespace'),
|
||||
|
|
|
@ -6,7 +6,15 @@ namespace LanguageServer\Tests\Server\TextDocument;
|
|||
use PHPUnit\Framework\TestCase;
|
||||
use LanguageServer\Tests\MockProtocolStream;
|
||||
use LanguageServer\{Server, Client, LanguageClient, Project};
|
||||
use LanguageServer\Protocol\{TextDocumentIdentifier, TextDocumentItem, FormattingOptions, ClientCapabilities};
|
||||
use LanguageServer\Protocol\{
|
||||
TextDocumentIdentifier,
|
||||
TextDocumentItem,
|
||||
FormattingOptions,
|
||||
ClientCapabilities,
|
||||
TextEdit,
|
||||
Range,
|
||||
Position
|
||||
};
|
||||
use function LanguageServer\{pathToUri, uriToPath};
|
||||
|
||||
class FormattingTest extends TestCase
|
||||
|
@ -42,19 +50,7 @@ class FormattingTest extends TestCase
|
|||
// how code should look after formatting
|
||||
$expected = file_get_contents(__DIR__ . '/../../../fixtures/format_expected.php');
|
||||
// Request formatting
|
||||
$result = $textDocument->formatting(new TextDocumentIdentifier($uri), new FormattingOptions());
|
||||
$this->assertEquals([0 => [
|
||||
'range' => [
|
||||
'start' => [
|
||||
'line' => 0,
|
||||
'character' => 0
|
||||
],
|
||||
'end' => [
|
||||
'line' => 20,
|
||||
'character' => 0
|
||||
]
|
||||
],
|
||||
'newText' => $expected
|
||||
]], json_decode(json_encode($result), true));
|
||||
$result = $textDocument->formatting(new TextDocumentIdentifier($uri), new FormattingOptions())->wait();
|
||||
$this->assertEquals([new TextEdit(new Range(new Position(0, 0), new Position(20, 0)), $expected)], $result);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,7 +16,10 @@ class HoverTest extends ServerTestCase
|
|||
// $obj = new TestClass();
|
||||
// Get hover for TestClass
|
||||
$reference = $this->getReferenceLocations('TestClass')[0];
|
||||
$result = $this->textDocument->hover(new TextDocumentIdentifier($reference->uri), $reference->range->start);
|
||||
$result = $this->textDocument->hover(
|
||||
new TextDocumentIdentifier($reference->uri),
|
||||
$reference->range->start
|
||||
)->wait();
|
||||
$this->assertEquals(new Hover([
|
||||
new MarkedString('php', "<?php\nclass TestClass implements \\TestInterface"),
|
||||
'Pariatur ut laborum tempor voluptate consequat ea deserunt.'
|
||||
|
@ -28,7 +31,10 @@ class HoverTest extends ServerTestCase
|
|||
// $obj->testMethod();
|
||||
// Get hover for testMethod
|
||||
$reference = $this->getReferenceLocations('TestClass::testMethod()')[0];
|
||||
$result = $this->textDocument->hover(new TextDocumentIdentifier($reference->uri), $reference->range->end);
|
||||
$result = $this->textDocument->hover(
|
||||
new TextDocumentIdentifier($reference->uri),
|
||||
$reference->range->end
|
||||
)->wait();
|
||||
$this->assertEquals(new Hover([
|
||||
new MarkedString('php', "<?php\npublic function testMethod(\$testParameter) : \TestInterface"),
|
||||
'Non culpa nostrud mollit esse sunt laboris in irure ullamco cupidatat amet.'
|
||||
|
@ -40,7 +46,10 @@ class HoverTest extends ServerTestCase
|
|||
// echo $obj->testProperty;
|
||||
// Get hover for testProperty
|
||||
$reference = $this->getReferenceLocations('TestClass::testProperty')[0];
|
||||
$result = $this->textDocument->hover(new TextDocumentIdentifier($reference->uri), $reference->range->end);
|
||||
$result = $this->textDocument->hover(
|
||||
new TextDocumentIdentifier($reference->uri),
|
||||
$reference->range->end
|
||||
)->wait();
|
||||
$this->assertEquals(new Hover([
|
||||
new MarkedString('php', "<?php\npublic \$testProperty;"),
|
||||
'Reprehenderit magna velit mollit ipsum do.'
|
||||
|
@ -52,7 +61,10 @@ class HoverTest extends ServerTestCase
|
|||
// TestClass::staticTestMethod();
|
||||
// Get hover for staticTestMethod
|
||||
$reference = $this->getReferenceLocations('TestClass::staticTestMethod()')[0];
|
||||
$result = $this->textDocument->hover(new TextDocumentIdentifier($reference->uri), $reference->range->end);
|
||||
$result = $this->textDocument->hover(
|
||||
new TextDocumentIdentifier($reference->uri),
|
||||
$reference->range->end
|
||||
)->wait();
|
||||
$this->assertEquals(new Hover([
|
||||
new MarkedString('php', "<?php\npublic static function staticTestMethod()"),
|
||||
'Do magna consequat veniam minim proident eiusmod incididunt aute proident.'
|
||||
|
@ -64,7 +76,10 @@ class HoverTest extends ServerTestCase
|
|||
// echo TestClass::staticTestProperty;
|
||||
// Get hover for staticTestProperty
|
||||
$reference = $this->getReferenceLocations('TestClass::staticTestProperty')[0];
|
||||
$result = $this->textDocument->hover(new TextDocumentIdentifier($reference->uri), $reference->range->end);
|
||||
$result = $this->textDocument->hover(
|
||||
new TextDocumentIdentifier($reference->uri),
|
||||
$reference->range->end
|
||||
)->wait();
|
||||
$this->assertEquals(new Hover([
|
||||
new MarkedString('php', "<?php\npublic static \$staticTestProperty;"),
|
||||
'Lorem excepteur officia sit anim velit veniam enim.'
|
||||
|
@ -76,7 +91,10 @@ class HoverTest extends ServerTestCase
|
|||
// echo TestClass::TEST_CLASS_CONST;
|
||||
// Get hover for TEST_CLASS_CONST
|
||||
$reference = $this->getReferenceLocations('TestClass::TEST_CLASS_CONST')[0];
|
||||
$result = $this->textDocument->hover(new TextDocumentIdentifier($reference->uri), $reference->range->end);
|
||||
$result = $this->textDocument->hover(
|
||||
new TextDocumentIdentifier($reference->uri),
|
||||
$reference->range->end
|
||||
)->wait();
|
||||
$this->assertEquals(new Hover([
|
||||
new MarkedString('php', "<?php\nconst TEST_CLASS_CONST = 123;"),
|
||||
'Anim labore veniam consectetur laboris minim quis aute aute esse nulla ad.'
|
||||
|
@ -88,7 +106,10 @@ class HoverTest extends ServerTestCase
|
|||
// test_function();
|
||||
// Get hover for test_function
|
||||
$reference = $this->getReferenceLocations('test_function()')[0];
|
||||
$result = $this->textDocument->hover(new TextDocumentIdentifier($reference->uri), $reference->range->end);
|
||||
$result = $this->textDocument->hover(
|
||||
new TextDocumentIdentifier($reference->uri),
|
||||
$reference->range->end
|
||||
)->wait();
|
||||
$this->assertEquals(new Hover([
|
||||
new MarkedString('php', "<?php\nfunction test_function()"),
|
||||
'Officia aliquip adipisicing et nulla et laboris dolore labore.'
|
||||
|
@ -100,7 +121,10 @@ class HoverTest extends ServerTestCase
|
|||
// echo TEST_CONST;
|
||||
// Get hover for TEST_CONST
|
||||
$reference = $this->getReferenceLocations('TEST_CONST')[0];
|
||||
$result = $this->textDocument->hover(new TextDocumentIdentifier($reference->uri), $reference->range->end);
|
||||
$result = $this->textDocument->hover(
|
||||
new TextDocumentIdentifier($reference->uri),
|
||||
$reference->range->end
|
||||
)->wait();
|
||||
$this->assertEquals(new Hover([
|
||||
new MarkedString('php', "<?php\nconst TEST_CONST = 123;"),
|
||||
'Esse commodo excepteur pariatur Lorem est aute incididunt reprehenderit.'
|
||||
|
@ -112,7 +136,7 @@ class HoverTest extends ServerTestCase
|
|||
// echo $var;
|
||||
// Get hover for $var
|
||||
$uri = pathToUri(realpath(__DIR__ . '/../../../fixtures/references.php'));
|
||||
$result = $this->textDocument->hover(new TextDocumentIdentifier($uri), new Position(13, 7));
|
||||
$result = $this->textDocument->hover(new TextDocumentIdentifier($uri), new Position(13, 7))->wait();
|
||||
$this->assertEquals(new Hover(
|
||||
[new MarkedString('php', "<?php\n\$var = 123;")],
|
||||
new Range(new Position(13, 5), new Position(13, 9))
|
||||
|
@ -124,7 +148,7 @@ class HoverTest extends ServerTestCase
|
|||
// echo $param;
|
||||
// Get hover for $param
|
||||
$uri = pathToUri(realpath(__DIR__ . '/../../../fixtures/references.php'));
|
||||
$result = $this->textDocument->hover(new TextDocumentIdentifier($uri), new Position(22, 11));
|
||||
$result = $this->textDocument->hover(new TextDocumentIdentifier($uri), new Position(22, 11))->wait();
|
||||
$this->assertEquals(new Hover(
|
||||
[
|
||||
new MarkedString('php', "<?php\n\TestNamespace\TestClass \$param"),
|
||||
|
|
|
@ -24,7 +24,11 @@ class GlobalFallbackTest extends ServerTestCase
|
|||
{
|
||||
// class TestClass implements TestInterface
|
||||
// Get references for TestClass
|
||||
$result = $this->textDocument->references(new ReferenceContext, new TextDocumentIdentifier('global_symbols'), new Position(6, 9));
|
||||
$result = $this->textDocument->references(
|
||||
new ReferenceContext,
|
||||
new TextDocumentIdentifier('global_symbols'),
|
||||
new Position(6, 9)
|
||||
)->wait();
|
||||
$this->assertEquals([], $result);
|
||||
}
|
||||
|
||||
|
@ -32,7 +36,11 @@ class GlobalFallbackTest extends ServerTestCase
|
|||
{
|
||||
// const TEST_CONST = 123;
|
||||
// Get references for TEST_CONST
|
||||
$result = $this->textDocument->references(new ReferenceContext, new TextDocumentIdentifier('global_symbols'), new Position(9, 13));
|
||||
$result = $this->textDocument->references(
|
||||
new ReferenceContext,
|
||||
new TextDocumentIdentifier('global_symbols'),
|
||||
new Position(9, 13)
|
||||
)->wait();
|
||||
$this->assertEquals([new Location('global_fallback', new Range(new Position(6, 5), new Position(6, 15)))], $result);
|
||||
}
|
||||
|
||||
|
@ -40,7 +48,11 @@ class GlobalFallbackTest extends ServerTestCase
|
|||
{
|
||||
// function test_function()
|
||||
// Get references for test_function
|
||||
$result = $this->textDocument->references(new ReferenceContext, new TextDocumentIdentifier('global_symbols'), new Position(78, 16));
|
||||
$result = $this->textDocument->references(
|
||||
new ReferenceContext,
|
||||
new TextDocumentIdentifier('global_symbols'),
|
||||
new Position(78, 16)
|
||||
)->wait();
|
||||
$this->assertEquals([new Location('global_fallback', new Range(new Position(5, 0), new Position(5, 13)))], $result);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,11 @@ class GlobalTest extends ServerTestCase
|
|||
// class TestClass implements TestInterface
|
||||
// Get references for TestClass
|
||||
$definition = $this->getDefinitionLocation('TestClass');
|
||||
$result = $this->textDocument->references(new ReferenceContext, new TextDocumentIdentifier($definition->uri), $definition->range->start);
|
||||
$result = $this->textDocument->references(
|
||||
new ReferenceContext,
|
||||
new TextDocumentIdentifier($definition->uri),
|
||||
$definition->range->start
|
||||
)->wait();
|
||||
$this->assertEquals($this->getReferenceLocations('TestClass'), $result);
|
||||
}
|
||||
|
||||
|
@ -23,7 +27,11 @@ class GlobalTest extends ServerTestCase
|
|||
// const TEST_CLASS_CONST = 123;
|
||||
// Get references for TEST_CLASS_CONST
|
||||
$definition = $this->getDefinitionLocation('TestClass::TEST_CLASS_CONST');
|
||||
$result = $this->textDocument->references(new ReferenceContext, new TextDocumentIdentifier($definition->uri), $definition->range->start);
|
||||
$result = $this->textDocument->references(
|
||||
new ReferenceContext,
|
||||
new TextDocumentIdentifier($definition->uri),
|
||||
$definition->range->start
|
||||
)->wait();
|
||||
$this->assertEquals($this->getReferenceLocations('TestClass::TEST_CLASS_CONST'), $result);
|
||||
}
|
||||
|
||||
|
@ -32,7 +40,11 @@ class GlobalTest extends ServerTestCase
|
|||
// const TEST_CONST = 123;
|
||||
// Get references for TEST_CONST
|
||||
$definition = $this->getDefinitionLocation('TEST_CONST');
|
||||
$result = $this->textDocument->references(new ReferenceContext, new TextDocumentIdentifier($definition->uri), $definition->range->start);
|
||||
$result = $this->textDocument->references(
|
||||
new ReferenceContext,
|
||||
new TextDocumentIdentifier($definition->uri),
|
||||
$definition->range->start
|
||||
)->wait();
|
||||
$this->assertEquals($this->getReferenceLocations('TEST_CONST'), $result);
|
||||
}
|
||||
|
||||
|
@ -41,7 +53,11 @@ class GlobalTest extends ServerTestCase
|
|||
// public static function staticTestMethod()
|
||||
// Get references for staticTestMethod
|
||||
$definition = $this->getDefinitionLocation('TestClass::staticTestMethod()');
|
||||
$result = $this->textDocument->references(new ReferenceContext, new TextDocumentIdentifier($definition->uri), $definition->range->start);
|
||||
$result = $this->textDocument->references(
|
||||
new ReferenceContext,
|
||||
new TextDocumentIdentifier($definition->uri),
|
||||
$definition->range->start
|
||||
)->wait();
|
||||
$this->assertEquals($this->getReferenceLocations('TestClass::staticTestMethod()'), $result);
|
||||
}
|
||||
|
||||
|
@ -50,7 +66,11 @@ class GlobalTest extends ServerTestCase
|
|||
// public static $staticTestProperty;
|
||||
// Get references for $staticTestProperty
|
||||
$definition = $this->getDefinitionLocation('TestClass::staticTestProperty');
|
||||
$result = $this->textDocument->references(new ReferenceContext, new TextDocumentIdentifier($definition->uri), $definition->range->start);
|
||||
$result = $this->textDocument->references(
|
||||
new ReferenceContext,
|
||||
new TextDocumentIdentifier($definition->uri),
|
||||
$definition->range->start
|
||||
)->wait();
|
||||
$this->assertEquals($this->getReferenceLocations('TestClass::staticTestProperty'), $result);
|
||||
}
|
||||
|
||||
|
@ -59,7 +79,11 @@ class GlobalTest extends ServerTestCase
|
|||
// public function testMethod($testParameter)
|
||||
// Get references for testMethod
|
||||
$definition = $this->getDefinitionLocation('TestClass::testMethod()');
|
||||
$result = $this->textDocument->references(new ReferenceContext, new TextDocumentIdentifier($definition->uri), $definition->range->start);
|
||||
$result = $this->textDocument->references(
|
||||
new ReferenceContext,
|
||||
new TextDocumentIdentifier($definition->uri),
|
||||
$definition->range->start
|
||||
)->wait();
|
||||
$this->assertEquals($this->getReferenceLocations('TestClass::testMethod()'), $result);
|
||||
}
|
||||
|
||||
|
@ -68,7 +92,11 @@ class GlobalTest extends ServerTestCase
|
|||
// public $testProperty;
|
||||
// Get references for testProperty
|
||||
$definition = $this->getDefinitionLocation('TestClass::testProperty');
|
||||
$result = $this->textDocument->references(new ReferenceContext, new TextDocumentIdentifier($definition->uri), $definition->range->start);
|
||||
$result = $this->textDocument->references(
|
||||
new ReferenceContext,
|
||||
new TextDocumentIdentifier($definition->uri),
|
||||
$definition->range->start
|
||||
)->wait();
|
||||
$this->assertEquals($this->getReferenceLocations('TestClass::testProperty'), $result);
|
||||
}
|
||||
|
||||
|
@ -77,7 +105,11 @@ class GlobalTest extends ServerTestCase
|
|||
// $var = 123;
|
||||
// Get definition for $var
|
||||
$uri = pathToUri(realpath(__DIR__ . '/../../../../fixtures/references.php'));
|
||||
$result = $this->textDocument->references(new ReferenceContext, new TextDocumentIdentifier($uri), new Position(12, 3));
|
||||
$result = $this->textDocument->references(
|
||||
new ReferenceContext,
|
||||
new TextDocumentIdentifier($uri),
|
||||
new Position(12, 3)
|
||||
)->wait();
|
||||
$this->assertEquals([
|
||||
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))),
|
||||
|
@ -90,7 +122,11 @@ class GlobalTest extends ServerTestCase
|
|||
// function whatever(TestClass $param): TestClass
|
||||
// Get references for $param
|
||||
$uri = pathToUri(realpath(__DIR__ . '/../../../../fixtures/references.php'));
|
||||
$result = $this->textDocument->references(new ReferenceContext, new TextDocumentIdentifier($uri), new Position(21, 32));
|
||||
$result = $this->textDocument->references(
|
||||
new ReferenceContext,
|
||||
new TextDocumentIdentifier($uri),
|
||||
new Position(21, 32)
|
||||
)->wait();
|
||||
$this->assertEquals([new Location($uri, new Range(new Position(22, 9), new Position(22, 15)))], $result);
|
||||
}
|
||||
|
||||
|
@ -100,7 +136,11 @@ class GlobalTest extends ServerTestCase
|
|||
// Get references for test_function
|
||||
$referencesUri = pathToUri(realpath(__DIR__ . '/../../../../fixtures/references.php'));
|
||||
$symbolsUri = pathToUri(realpath(__DIR__ . '/../../../../fixtures/symbols.php'));
|
||||
$result = $this->textDocument->references(new ReferenceContext, new TextDocumentIdentifier($symbolsUri), new Position(78, 16));
|
||||
$result = $this->textDocument->references(
|
||||
new ReferenceContext,
|
||||
new TextDocumentIdentifier($symbolsUri),
|
||||
new Position(78, 16)
|
||||
)->wait();
|
||||
$this->assertEquals([
|
||||
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)))
|
||||
|
|
Loading…
Reference in New Issue