From fa561f84819253428af047f63a5d6c6e99b28eb2 Mon Sep 17 00:00:00 2001 From: Philip Nelson Date: Tue, 5 Dec 2017 11:37:52 +1100 Subject: [PATCH] use a coroutine instead of using ->wait() --- src/SignatureHelpProvider.php | 60 +++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/src/SignatureHelpProvider.php b/src/SignatureHelpProvider.php index ccfca28..ca25e53 100644 --- a/src/SignatureHelpProvider.php +++ b/src/SignatureHelpProvider.php @@ -12,6 +12,8 @@ use LanguageServer\Protocol\{ }; use Microsoft\PhpParser; use Microsoft\PhpParser\Node; +use Sabre\Event\Promise; +use function Sabre\Event\coroutine; class SignatureHelpProvider { @@ -44,42 +46,44 @@ class SignatureHelpProvider * @param PhpDocument $doc The document the position belongs to * @param Position $position The position to detect a call from * - * @return SignatureHelp + * @return Promise */ - public function getSignatureHelp(PhpDocument $doc, Position $position): SignatureHelp + public function getSignatureHelp(PhpDocument $doc, Position $position): Promise { - // Find the node under the cursor - $node = $doc->getNodeAtPosition($position); + return coroutine(function () use ($doc, $position) { + // Find the node under the cursor + $node = $doc->getNodeAtPosition($position); - // Find the definition of the item being called - list($def, $argumentExpressionList) = $this->getCallingInfo($node); + // Find the definition of the item being called + list($def, $argumentExpressionList) = $this->getCallingInfo($node); - if (!$def) { - return new SignatureHelp(); - } + if (!$def) { + return new SignatureHelp(); + } - // Find the active parameter - $activeParam = $argumentExpressionList - ? $this->findActiveParameter($argumentExpressionList, $position, $doc) - : 0; + // Get information from the item being called to build the signature information + $calledDoc = yield $this->documentLoader->getOrLoad($def->symbolInformation->location->uri); + if (!$calledDoc) { + 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 - $calledDoc = $this->documentLoader->getOrLoad($def->symbolInformation->location->uri)->wait(); - if (!$calledDoc) { - return new SignatureHelp(); - } - $calledNode = $calledDoc->getNodeAtPosition($def->symbolInformation->location->range->start); - $params = $this->getParameters($calledNode, $calledDoc); - $label = $this->getLabel($calledNode, $params, $calledDoc); + // Find the active parameter + $activeParam = $argumentExpressionList + ? $this->findActiveParameter($argumentExpressionList, $position, $doc) + : 0; - $signatureInformation = new SignatureInformation( - $label, - $params, - $this->definitionResolver->getDocumentationFromNode($calledNode) - ); - $signatureHelp = new SignatureHelp([$signatureInformation], 0, $activeParam); + $signatureInformation = new SignatureInformation( + $label, + $params, + $this->definitionResolver->getDocumentationFromNode($calledNode) + ); + $signatureHelp = new SignatureHelp([$signatureInformation], 0, $activeParam); - return $signatureHelp; + return $signatureHelp; + }); } /**