diff --git a/fixtures/signature/methodActiveParam.php b/fixtures/signature/methodActiveParam.php new file mode 100644 index 0000000..c100c7a --- /dev/null +++ b/fixtures/signature/methodActiveParam.php @@ -0,0 +1,15 @@ +method(); + } +} + +$a = new HelpClass5; +$a->method("asdf", 123, true); \ No newline at end of file diff --git a/src/SignatureHelpProvider.php b/src/SignatureHelpProvider.php index a16f83a..18cc1a8 100644 --- a/src/SignatureHelpProvider.php +++ b/src/SignatureHelpProvider.php @@ -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) { diff --git a/tests/Server/TextDocument/SignatureHelpTest.php b/tests/Server/TextDocument/SignatureHelpTest.php index 76613e1..832a88e 100644 --- a/tests/Server/TextDocument/SignatureHelpTest.php +++ b/tests/Server/TextDocument/SignatureHelpTest.php @@ -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); + } }