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;
use Microsoft\PhpParser\Node; use Microsoft\PhpParser\Node;
use Sabre\Event\Promise;
use function Sabre\Event\coroutine;
class SignatureHelpProvider class SignatureHelpProvider
{ {
@ -44,10 +46,11 @@ 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
{ {
return coroutine(function () use ($doc, $position) {
// Find the node under the cursor // Find the node under the cursor
$node = $doc->getNodeAtPosition($position); $node = $doc->getNodeAtPosition($position);
@ -58,13 +61,8 @@ class SignatureHelpProvider
return new SignatureHelp(); 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 // 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) { if (!$calledDoc) {
return new SignatureHelp(); return new SignatureHelp();
} }
@ -72,6 +70,11 @@ class SignatureHelpProvider
$params = $this->getParameters($calledNode, $calledDoc); $params = $this->getParameters($calledNode, $calledDoc);
$label = $this->getLabel($calledNode, $params, $calledDoc); $label = $this->getLabel($calledNode, $params, $calledDoc);
// Find the active parameter
$activeParam = $argumentExpressionList
? $this->findActiveParameter($argumentExpressionList, $position, $doc)
: 0;
$signatureInformation = new SignatureInformation( $signatureInformation = new SignatureInformation(
$label, $label,
$params, $params,
@ -80,6 +83,7 @@ class SignatureHelpProvider
$signatureHelp = new SignatureHelp([$signatureInformation], 0, $activeParam); $signatureHelp = new SignatureHelp([$signatureInformation], 0, $activeParam);
return $signatureHelp; return $signatureHelp;
});
} }
/** /**