improved param counting
parent
b2056c1f87
commit
1c714f98b7
|
@ -0,0 +1,15 @@
|
|||
<?php
|
||||
|
||||
class HelpClass5
|
||||
{
|
||||
public function method(string $param = "", int $count = 0, bool $test = null)
|
||||
{
|
||||
}
|
||||
public function test()
|
||||
{
|
||||
$this->method();
|
||||
}
|
||||
}
|
||||
|
||||
$a = new HelpClass5;
|
||||
$a->method("asdf", 123, true);
|
|
@ -46,12 +46,14 @@ class SignatureHelpProvider
|
|||
public function provideSignature(PhpDocument $doc, Position $pos) : SignatureHelp
|
||||
{
|
||||
$node = $doc->getNodeAtPosition($pos);
|
||||
$nodes = [$node];
|
||||
while ($node &&
|
||||
!($node instanceof ArgumentExpressionList) &&
|
||||
!($node instanceof CallExpression) &&
|
||||
$node->parent
|
||||
) {
|
||||
$node = $node->parent;
|
||||
$nodes[] = $node;
|
||||
}
|
||||
if (!($node instanceof ArgumentExpressionList) &&
|
||||
!($node instanceof CallExpression)
|
||||
|
@ -62,6 +64,9 @@ class SignatureHelpProvider
|
|||
if ($node instanceof ArgumentExpressionList) {
|
||||
$count = 0;
|
||||
foreach ($node->getElements() as $param) {
|
||||
if (in_array($param, $nodes)) {
|
||||
break;
|
||||
}
|
||||
$count ++;
|
||||
}
|
||||
while ($node && !($node instanceof CallExpression) && $node->parent) {
|
||||
|
|
|
@ -219,4 +219,30 @@ class SignatureHelpTest extends TestCase
|
|||
]
|
||||
), $result);
|
||||
}
|
||||
|
||||
public function testMethodActiveParam()
|
||||
{
|
||||
$completionUri = pathToUri(__DIR__ . '/../../../fixtures/signature/methodActiveParam.php');
|
||||
$this->loader->open($completionUri, file_get_contents($completionUri));
|
||||
$result = $this->textDocument->signatureHelp(
|
||||
new TextDocumentIdentifier($completionUri),
|
||||
new Position(14, 21)
|
||||
)->wait();
|
||||
|
||||
$this->assertEquals(new SignatureHelp(
|
||||
[
|
||||
new SignatureInformation(
|
||||
'method(string $param = "", int $count = 0, bool $test = null)',
|
||||
null,
|
||||
[
|
||||
new ParameterInformation('string $param = ""'),
|
||||
new ParameterInformation('int $count = 0'),
|
||||
new ParameterInformation('bool $test = null')
|
||||
]
|
||||
)
|
||||
],
|
||||
0,
|
||||
1
|
||||
), $result);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue