fixed signature helper reference
parent
fdda97c7b5
commit
16c7560993
|
@ -2,7 +2,7 @@
|
|||
|
||||
class HelpClass1
|
||||
{
|
||||
protected function method(string $param = "")
|
||||
public function method(string $param = "")
|
||||
{
|
||||
}
|
||||
public function test()
|
||||
|
@ -10,3 +10,6 @@ class HelpClass1
|
|||
$this->method();
|
||||
}
|
||||
}
|
||||
|
||||
$a = new HelpClass1;
|
||||
$a->method(1, );
|
|
@ -10,3 +10,6 @@ class HelpClass2
|
|||
$this->method(
|
||||
}
|
||||
}
|
||||
|
||||
$a = new HelpClass2;
|
||||
$a->method(1,
|
|
@ -57,8 +57,6 @@ class SignatureHelpProvider
|
|||
}
|
||||
$line = substr($line, 0, $newPos->character);
|
||||
|
||||
//echo $line . "\n";
|
||||
//die();
|
||||
$newPos->character --;
|
||||
|
||||
$node = $doc->getNodeAtPosition($newPos);
|
||||
|
@ -66,17 +64,6 @@ class SignatureHelpProvider
|
|||
if ($node instanceof Node\Expr\Error) {
|
||||
$node = $node->getAttribute('parentNode');
|
||||
}
|
||||
|
||||
//echo get_class($node);
|
||||
//die();
|
||||
//$def = $this->definitionResolver->resolveReferenceNodeToDefinition($node->var);
|
||||
//var_dump($def);
|
||||
//echo $def->fqn;
|
||||
|
||||
//echo $node->name;
|
||||
|
||||
|
||||
//die();
|
||||
|
||||
if ($node instanceof Node\Expr\Error) {
|
||||
$node = $node->getAttribute('parentNode');
|
||||
|
@ -84,7 +71,7 @@ class SignatureHelpProvider
|
|||
if ($node instanceof Node\Expr\FuncCall) {
|
||||
if ($def = $this->definitionResolver->resolveReferenceNodeToDefinition($node)) {
|
||||
$signature = new SignatureInformation;
|
||||
$signature->label = str_replace('()', '', $def->fqn);
|
||||
$signature->label = str_replace('()', '', $def->fqn) . '('.implode(', ', $def->parameters).')';
|
||||
$signature->documentation = $def->documentation;
|
||||
$signature->parameters = [];
|
||||
foreach ($def->parameters as $param) {
|
||||
|
@ -99,7 +86,7 @@ class SignatureHelpProvider
|
|||
$fqn = $method[0] . '()';
|
||||
if ($def = $this->index->getDefinition($fqn)) {
|
||||
$signature = new SignatureInformation;
|
||||
$signature->label = $method[0];
|
||||
$signature->label = $method[0] . '('.implode(', ', $def->parameters).')';
|
||||
$signature->documentation = $def->documentation;
|
||||
$signature->parameters = [];
|
||||
foreach ($def->parameters as $param) {
|
||||
|
@ -113,7 +100,7 @@ class SignatureHelpProvider
|
|||
} else if ($node instanceof Node\Expr\MethodCall) {
|
||||
if ($def = $this->definitionResolver->resolveReferenceNodeToDefinition($node)) {
|
||||
$signature = new SignatureInformation;
|
||||
$signature->label = str_replace('()', '', explode('->', $def->fqn)[1]);
|
||||
$signature->label = str_replace('()', '', explode('->', $def->fqn)[1]) . '('.implode(', ', $def->parameters).')';
|
||||
$signature->documentation = $def->documentation;
|
||||
$signature->parameters = [];
|
||||
foreach ($def->parameters as $param) {
|
||||
|
@ -125,12 +112,21 @@ class SignatureHelpProvider
|
|||
}
|
||||
} else if ($node instanceof Node\Expr\PropertyFetch) {
|
||||
if ($def = $this->definitionResolver->resolveReferenceNodeToDefinition($node->var)) {
|
||||
$fqn = $def->fqn;
|
||||
if (!$fqn) {
|
||||
$fqns = DefinitionResolver::getFqnsFromType(
|
||||
$this->definitionResolver->resolveExpressionNodeToType($node->var)
|
||||
);
|
||||
if (count($fqns)) {
|
||||
$fqn = $fqns[0];
|
||||
}
|
||||
}
|
||||
$method = trim(substr($line, strrpos($line, ">") + 1));
|
||||
if ($method) {
|
||||
$fqn = $def->fqn . '->' . $method . '()';
|
||||
if ($method && $fqn) {
|
||||
$fqn = $fqn . '->' . $method . '()';
|
||||
if ($def = $this->index->getDefinition($fqn)) {
|
||||
$signature = new SignatureInformation;
|
||||
$signature->label = str_replace('()', '', explode('->', $def->fqn)[1]);
|
||||
$signature->label = str_replace('()', '', explode('->', $def->fqn)[1]) . '('.implode(', ', $def->parameters).')';
|
||||
$signature->documentation = $def->documentation;
|
||||
$signature->parameters = [];
|
||||
foreach ($def->parameters as $param) {
|
||||
|
@ -145,7 +141,7 @@ class SignatureHelpProvider
|
|||
} else if ($node instanceof Node\Expr\StaticCall) {
|
||||
if ($def = $this->definitionResolver->resolveReferenceNodeToDefinition($node)) {
|
||||
$signature = new SignatureInformation;
|
||||
$signature->label = str_replace('()', '', explode('::', $def->fqn)[1]);
|
||||
$signature->label = str_replace('()', '', explode('::', $def->fqn)[1]) . '('.implode(', ', $def->parameters).')';
|
||||
$signature->documentation = $def->documentation;
|
||||
$signature->parameters = [];
|
||||
foreach ($def->parameters as $param) {
|
||||
|
@ -162,7 +158,7 @@ class SignatureHelpProvider
|
|||
$fqn = $def->fqn . '::' . $method . '()';
|
||||
if ($def = $this->index->getDefinition($fqn)) {
|
||||
$signature = new SignatureInformation;
|
||||
$signature->label = str_replace('()', '', explode('::', $def->fqn)[1]);
|
||||
$signature->label = str_replace('()', '', explode('::', $def->fqn)[1]) . '('.implode(', ', $def->parameters).')';
|
||||
$signature->documentation = $def->documentation;
|
||||
$signature->parameters = [];
|
||||
foreach ($def->parameters as $param) {
|
||||
|
|
|
@ -57,7 +57,29 @@ class SignatureHelpTest extends TestCase
|
|||
$help->signatures = [];
|
||||
$info = new SignatureInformation;
|
||||
$help->signatures[] = $info;
|
||||
$info->label = 'method';
|
||||
$info->label = 'method(string $param = "")';
|
||||
$info->parameters = [];
|
||||
$param = new ParameterInformation;
|
||||
$info->parameters[] = $param;
|
||||
$param->label = 'string $param = ""';
|
||||
|
||||
$this->assertEquals($help, $result);
|
||||
}
|
||||
|
||||
public function testMethodClosedReference()
|
||||
{
|
||||
$completionUri = pathToUri(__DIR__ . '/../../../fixtures/signatureHelp/methodClosed.php');
|
||||
$this->loader->open($completionUri, file_get_contents($completionUri));
|
||||
$result = $this->textDocument->signatureHelp(
|
||||
new TextDocumentIdentifier($completionUri),
|
||||
new Position(14, 14)
|
||||
)->wait();
|
||||
|
||||
$help = new SignatureHelp;
|
||||
$help->signatures = [];
|
||||
$info = new SignatureInformation;
|
||||
$help->signatures[] = $info;
|
||||
$info->label = 'method(string $param = "")';
|
||||
$info->parameters = [];
|
||||
$param = new ParameterInformation;
|
||||
$info->parameters[] = $param;
|
||||
|
@ -79,7 +101,29 @@ class SignatureHelpTest extends TestCase
|
|||
$help->signatures = [];
|
||||
$info = new SignatureInformation;
|
||||
$help->signatures[] = $info;
|
||||
$info->label = 'method';
|
||||
$info->label = 'method(string $param = "")';
|
||||
$info->parameters = [];
|
||||
$param = new ParameterInformation;
|
||||
$info->parameters[] = $param;
|
||||
$param->label = 'string $param = ""';
|
||||
|
||||
$this->assertEquals($help, $result);
|
||||
}
|
||||
|
||||
public function testMethodNotClosedReference()
|
||||
{
|
||||
$completionUri = pathToUri(__DIR__ . '/../../../fixtures/signatureHelp/methodNotClosed.php');
|
||||
$this->loader->open($completionUri, file_get_contents($completionUri));
|
||||
$result = $this->textDocument->signatureHelp(
|
||||
new TextDocumentIdentifier($completionUri),
|
||||
new Position(14, 14)
|
||||
)->wait();
|
||||
|
||||
$help = new SignatureHelp;
|
||||
$help->signatures = [];
|
||||
$info = new SignatureInformation;
|
||||
$help->signatures[] = $info;
|
||||
$info->label = 'method(string $param = "")';
|
||||
$info->parameters = [];
|
||||
$param = new ParameterInformation;
|
||||
$info->parameters[] = $param;
|
||||
|
@ -101,7 +145,7 @@ class SignatureHelpTest extends TestCase
|
|||
$help->signatures = [];
|
||||
$info = new SignatureInformation;
|
||||
$help->signatures[] = $info;
|
||||
$info->label = 'helpFunc1';
|
||||
$info->label = 'helpFunc1(int $count = 0)';
|
||||
$info->parameters = [];
|
||||
$param = new ParameterInformation;
|
||||
$info->parameters[] = $param;
|
||||
|
@ -123,7 +167,7 @@ class SignatureHelpTest extends TestCase
|
|||
$help->signatures = [];
|
||||
$info = new SignatureInformation;
|
||||
$help->signatures[] = $info;
|
||||
$info->label = 'helpFunc2';
|
||||
$info->label = 'helpFunc2(int $count = 0)';
|
||||
$info->parameters = [];
|
||||
$param = new ParameterInformation;
|
||||
$info->parameters[] = $param;
|
||||
|
@ -145,7 +189,7 @@ class SignatureHelpTest extends TestCase
|
|||
$help->signatures = [];
|
||||
$info = new SignatureInformation;
|
||||
$help->signatures[] = $info;
|
||||
$info->label = 'method';
|
||||
$info->label = 'method(string $param = "")';
|
||||
$info->parameters = [];
|
||||
$param = new ParameterInformation;
|
||||
$info->parameters[] = $param;
|
||||
|
@ -167,7 +211,7 @@ class SignatureHelpTest extends TestCase
|
|||
$help->signatures = [];
|
||||
$info = new SignatureInformation;
|
||||
$help->signatures[] = $info;
|
||||
$info->label = 'method';
|
||||
$info->label = 'method(string $param = "")';
|
||||
$info->parameters = [];
|
||||
$param = new ParameterInformation;
|
||||
$info->parameters[] = $param;
|
||||
|
|
Loading…
Reference in New Issue