diff --git a/fixtures/signatureHelp/funcNotClosed.php b/fixtures/signatureHelp/funcNotClosed.php index d636f42..95d7ebb 100644 --- a/fixtures/signatureHelp/funcNotClosed.php +++ b/fixtures/signatureHelp/funcNotClosed.php @@ -4,6 +4,4 @@ function helpFunc2(int $count = 0) { } -$a = 1; - helpFunc2( diff --git a/fixtures/signatureHelp/staticNotClosed.php b/fixtures/signatureHelp/staticNotClosed.php index 8f0ac96..49728aa 100644 --- a/fixtures/signatureHelp/staticNotClosed.php +++ b/fixtures/signatureHelp/staticNotClosed.php @@ -7,6 +7,4 @@ class HelpClass4 } } -HelpClass4::method(1, 2, 3 - -HelpClass4::method(1, 2, 3 +HelpClass4::method(1 diff --git a/src/SignatureHelpProvider.php b/src/SignatureHelpProvider.php index b67df97..1bfedd2 100644 --- a/src/SignatureHelpProvider.php +++ b/src/SignatureHelpProvider.php @@ -72,8 +72,13 @@ class SignatureHelpProvider $line = substr(fgets($handle), 0, $pos->character); fseek($handle, 0); + $i = 0; + $orig = null; do { $node = $doc->getNodeAtPosition($pos); + if ($node !== null) { + $orig = $node; + } $pos->character--; if ($pos->character < 0) { $pos->line --; @@ -82,22 +87,23 @@ class SignatureHelpProvider } $pos->character = $lines[$pos->line]; } - } while ($node === null); - - if ($node === null) { - fclose($handle); - return $help; - } - $i = 0; - while (!( + } while (!( $node instanceof Node\Expr\PropertyFetch || $node instanceof Node\Expr\MethodCall || $node instanceof Node\Expr\FuncCall || $node instanceof Node\Expr\ClassConstFetch || $node instanceof Node\Expr\StaticCall - ) && ++$i < 5 && $node !== null) { - $node = $node->getAttribute('parentNode'); + ) && ++$i < 120); + + if ($node === null) { + $node = $orig; } + + if ($node === null) { + fclose($handle); + return $help; + } + $params = ''; if ($node instanceof Node\Expr\PropertyFetch) { fseek($handle, $node->name->getAttribute('startFilePos')); @@ -142,7 +148,7 @@ class SignatureHelpProvider $fqn = $this->definitionResolver->resolveReferenceNodeToFqn($node->class); $def = $this->index->getDefinition($fqn.'::'.$method.'()'); } else { - if (!preg_match('(([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)\s*\((.*)$)', $line, $method)) { + if (!preg_match('(([a-zA-Z_\x7f-\xff][:a-zA-Z0-9_\x7f-\xff]*)\s*\((.*)$)', $line, $method)) { fclose($handle); return $help; } diff --git a/tests/Server/TextDocument/SignatureHelpTest.php b/tests/Server/TextDocument/SignatureHelpTest.php index 33b10f5..a6f4620 100644 --- a/tests/Server/TextDocument/SignatureHelpTest.php +++ b/tests/Server/TextDocument/SignatureHelpTest.php @@ -132,13 +132,13 @@ class SignatureHelpTest extends TestCase $this->assertEquals($help, $result); } - public function funcClosed() + public function testFuncClosed() { $completionUri = pathToUri(__DIR__ . '/../../../fixtures/signatureHelp/funcClosed.php'); $this->loader->open($completionUri, file_get_contents($completionUri)); $result = $this->textDocument->signatureHelp( new TextDocumentIdentifier($completionUri), - new Position(5, 10) + new Position(6, 10) )->wait(); $help = new SignatureHelp; @@ -154,13 +154,13 @@ class SignatureHelpTest extends TestCase $this->assertEquals($help, $result); } - public function funcNotClosed() + public function testFuncNotClosed() { $completionUri = pathToUri(__DIR__ . '/../../../fixtures/signatureHelp/funcNotClosed.php'); $this->loader->open($completionUri, file_get_contents($completionUri)); $result = $this->textDocument->signatureHelp( new TextDocumentIdentifier($completionUri), - new Position(5, 10) + new Position(6, 10) )->wait(); $help = new SignatureHelp; @@ -176,7 +176,7 @@ class SignatureHelpTest extends TestCase $this->assertEquals($help, $result); } - public function staticClosed() + public function testStaticClosed() { $completionUri = pathToUri(__DIR__ . '/../../../fixtures/signatureHelp/staticClosed.php'); $this->loader->open($completionUri, file_get_contents($completionUri)); @@ -198,7 +198,7 @@ class SignatureHelpTest extends TestCase $this->assertEquals($help, $result); } - public function staticNotClosed() + public function testStaticNotClosed() { $completionUri = pathToUri(__DIR__ . '/../../../fixtures/signatureHelp/staticNotClosed.php'); $this->loader->open($completionUri, file_get_contents($completionUri));