1
0
Fork 0

use a coroutine instead of using ->wait()

pull/547/head
Philip Nelson 2017-12-05 11:37:52 +11:00
parent 5ba7724a5c
commit fa561f8481
1 changed files with 32 additions and 28 deletions

View File

@ -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,10 +46,11 @@ 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 <SignatureHelp>
*/
public function getSignatureHelp(PhpDocument $doc, Position $position): SignatureHelp
public function getSignatureHelp(PhpDocument $doc, Position $position): Promise
{
return coroutine(function () use ($doc, $position) {
// Find the node under the cursor
$node = $doc->getNodeAtPosition($position);
@ -58,13 +61,8 @@ class SignatureHelpProvider
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 = $this->documentLoader->getOrLoad($def->symbolInformation->location->uri)->wait();
$calledDoc = yield $this->documentLoader->getOrLoad($def->symbolInformation->location->uri);
if (!$calledDoc) {
return new SignatureHelp();
}
@ -72,6 +70,11 @@ class SignatureHelpProvider
$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,
@ -80,6 +83,7 @@ class SignatureHelpProvider
$signatureHelp = new SignatureHelp([$signatureInformation], 0, $activeParam);
return $signatureHelp;
});
}
/**