felixfbecker / php-language-server

PHP Implementation of the VS Code Language Server Protocol 🆚↔🖥
ISC License
1.16k stars 185 forks source link

Missing null check in CompletionProvider when method signature is invalid #580

Open jens1o opened 6 years ago

jens1o commented 6 years ago

I changed the signature of private function convertDuration(string $rawDuration): int { to private function convertDuration(string §rawDuration): int {

and suddenly this error has popped up.

[Error - 9:45:13 PM] Request textDocument/completion failed.
  Message: TypeError: strpos() expects parameter 1 to be string, null given in C:\Users\Jens\.vscode-insiders\extensions\felixfbecker.php-intellisense-2.2.5\vendor\felixfbecker\language-server\src\CompletionProvider.php:452
Stack trace:
#0 C:\Users\Jens\.vscode-insiders\extensions\felixfbecker.php-intellisense-2.2.5\vendor\felixfbecker\language-server\src\CompletionProvider.php(452): strpos(NULL, 'rawDuration')
#1 C:\Users\Jens\.vscode-insiders\extensions\felixfbecker.php-intellisense-2.2.5\vendor\felixfbecker\language-server\src\CompletionProvider.php(197): LanguageServer\CompletionProvider->suggestVariablesAtNode(Object(Microsoft\PhpParser\Node\Expression\Variable), 'rawDuration')
#2 C:\Users\Jens\.vscode-insiders\extensions\felixfbecker.php-intellisense-2.2.5\vendor\felixfbecker\language-server\src\Server\TextDocument.php(370): LanguageServer\CompletionProvider->provideCompletion(Object(LanguageServer\PhpDocument), Object(LanguageServer\Protocol\Position), NULL)
#3 [internal function]: LanguageServer\Server\TextDocument->LanguageServer\Server\{closure}()
#4 C:\Users\Jens\.vscode-insiders\extensions\felixfbecker.php-intellisense-2.2.5\vendor\sabre\event\lib\coroutine.php(70): Generator->send(Object(LanguageServer\PhpDocument))
#5 C:\Users\Jens\.vscode-insiders\extensions\felixfbecker.php-intellisense-2.2.5\vendor\sabre\event\lib\Promise.php(242): Sabre\Event\{closure}(Object(LanguageServer\PhpDocument))
#6 C:\Users\Jens\.vscode-insiders\extensions\felixfbecker.php-intellisense-2.2.5\vendor\sabre\event\lib\Loop\Loop.php(261): Sabre\Event\Promise->Sabre\Event\{closure}()
#7 C:\Users\Jens\.vscode-insiders\extensions\felixfbecker.php-intellisense-2.2.5\vendor\sabre\event\lib\Loop\Loop.php(215): Sabre\Event\Loop\Loop->runNextTicks()
#8 C:\Users\Jens\.vscode-insiders\extensions\felixfbecker.php-intellisense-2.2.5\vendor\sabre\event\lib\Loop\Loop.php(194): Sabre\Event\Loop\Loop->tick(true)
#9 C:\Users\Jens\.vscode-insiders\extensions\felixfbecker.php-intellisense-2.2.5\vendor\sabre\event\lib\Loop\functions.php(122): Sabre\Event\Loop\Loop->run()
#10 C:\Users\Jens\.vscode-insiders\extensions\felixfbecker.php-intellisense-2.2.5\vendor\felixfbecker\language-server\bin\php-language-server.php(50): Sabre\Event\Loop\run()
#11 {main}
  Code: -32603 
cogk commented 5 years ago

(I know this issue is old)

Here is a minimal example where this error happens (notice the missing $ in the function signature):

<?php
function a(b)
{
    $c;
}