use a coroutine instead of using ->wait()
parent
5ba7724a5c
commit
fa561f8481
|
@ -12,6 +12,8 @@ use LanguageServer\Protocol\{
|
||||||
};
|
};
|
||||||
use Microsoft\PhpParser;
|
use Microsoft\PhpParser;
|
||||||
use Microsoft\PhpParser\Node;
|
use Microsoft\PhpParser\Node;
|
||||||
|
use Sabre\Event\Promise;
|
||||||
|
use function Sabre\Event\coroutine;
|
||||||
|
|
||||||
class SignatureHelpProvider
|
class SignatureHelpProvider
|
||||||
{
|
{
|
||||||
|
@ -44,42 +46,44 @@ class SignatureHelpProvider
|
||||||
* @param PhpDocument $doc The document the position belongs to
|
* @param PhpDocument $doc The document the position belongs to
|
||||||
* @param Position $position The position to detect a call from
|
* @param Position $position The position to detect a call from
|
||||||
*
|
*
|
||||||
* @return SignatureHelp
|
* @return Promise <SignatureHelp>
|
||||||
*/
|
*/
|
||||||
public function getSignatureHelp(PhpDocument $doc, Position $position): SignatureHelp
|
public function getSignatureHelp(PhpDocument $doc, Position $position): Promise
|
||||||
{
|
{
|
||||||
// Find the node under the cursor
|
return coroutine(function () use ($doc, $position) {
|
||||||
$node = $doc->getNodeAtPosition($position);
|
// Find the node under the cursor
|
||||||
|
$node = $doc->getNodeAtPosition($position);
|
||||||
|
|
||||||
// Find the definition of the item being called
|
// Find the definition of the item being called
|
||||||
list($def, $argumentExpressionList) = $this->getCallingInfo($node);
|
list($def, $argumentExpressionList) = $this->getCallingInfo($node);
|
||||||
|
|
||||||
if (!$def) {
|
if (!$def) {
|
||||||
return new SignatureHelp();
|
return new SignatureHelp();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find the active parameter
|
// Get information from the item being called to build the signature information
|
||||||
$activeParam = $argumentExpressionList
|
$calledDoc = yield $this->documentLoader->getOrLoad($def->symbolInformation->location->uri);
|
||||||
? $this->findActiveParameter($argumentExpressionList, $position, $doc)
|
if (!$calledDoc) {
|
||||||
: 0;
|
return new SignatureHelp();
|
||||||
|
}
|
||||||
|
$calledNode = $calledDoc->getNodeAtPosition($def->symbolInformation->location->range->start);
|
||||||
|
$params = $this->getParameters($calledNode, $calledDoc);
|
||||||
|
$label = $this->getLabel($calledNode, $params, $calledDoc);
|
||||||
|
|
||||||
// Get information from the item being called to build the signature information
|
// Find the active parameter
|
||||||
$calledDoc = $this->documentLoader->getOrLoad($def->symbolInformation->location->uri)->wait();
|
$activeParam = $argumentExpressionList
|
||||||
if (!$calledDoc) {
|
? $this->findActiveParameter($argumentExpressionList, $position, $doc)
|
||||||
return new SignatureHelp();
|
: 0;
|
||||||
}
|
|
||||||
$calledNode = $calledDoc->getNodeAtPosition($def->symbolInformation->location->range->start);
|
|
||||||
$params = $this->getParameters($calledNode, $calledDoc);
|
|
||||||
$label = $this->getLabel($calledNode, $params, $calledDoc);
|
|
||||||
|
|
||||||
$signatureInformation = new SignatureInformation(
|
$signatureInformation = new SignatureInformation(
|
||||||
$label,
|
$label,
|
||||||
$params,
|
$params,
|
||||||
$this->definitionResolver->getDocumentationFromNode($calledNode)
|
$this->definitionResolver->getDocumentationFromNode($calledNode)
|
||||||
);
|
);
|
||||||
$signatureHelp = new SignatureHelp([$signatureInformation], 0, $activeParam);
|
$signatureHelp = new SignatureHelp([$signatureInformation], 0, $activeParam);
|
||||||
|
|
||||||
return $signatureHelp;
|
return $signatureHelp;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue