felixfbecker / php-language-server

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

Crash passing parse-by-reference param: strpos() expects parameter 1 to be string, null given #648

Open ghost opened 6 years ago

ghost commented 6 years ago
[Info  - 16:55:28] All 1797 PHP files parsed in 1682 seconds. 172 MiB allocated.
[Error - 12:28:49] Request textDocument/completion failed.
  Message: TypeError: strpos() expects parameter 1 to be string, null given in C:\Users\etien\.vscode\extensions\felixfbecker.php-intellisense-2.3.2\vendor\felixfbecker\language-server\src\CompletionProvider.php:470
Stack trace:
#0 C:\Users\etien\.vscode\extensions\felixfbecker.php-intellisense-2.3.2\vendor\felixfbecker\language-server\src\CompletionProvider.php(470): strpos(NULL, 'this')
#1 C:\Users\etien\.vscode\extensions\felixfbecker.php-intellisense-2.3.2\vendor\felixfbecker\language-server\src\CompletionProvider.php(215): LanguageServer\CompletionProvider->suggestVariablesAtNode(Object(Microsoft\PhpParser\Node\Expression\Variable), 'this')
#2 C:\Users\etien\.vscode\extensions\felixfbecker.php-intellisense-2.3.2\vendor\felixfbecker\language-server\src\Server\TextDocument.php(369): LanguageServer\CompletionProvider->provideCompletion(Object(LanguageServer\PhpDocument), Object(LanguageServer\Protocol\Position), NULL)
#3 [internal function]: LanguageServer\Server\TextDocument->LanguageServer\Server\{closure}()
#4 C:\Users\etien\.vscode\extensions\felixfbecker.php-intellisense-2.3.2\vendor\sabre\event\lib\coroutine.php(70): Generator->send(Object(LanguageServer\PhpDocument))
#5 C:\Users\etien\.vscode\extensions\felixfbecker.php-intellisense-2.3.2\vendor\sabre\event\lib\Promise.php(242): Sabre\Event\{closure}(Object(LanguageServer\PhpDocument))
#6 C:\Users\etien\.vscode\extensions\felixfbecker.php-intellisense-2.3.2\vendor\sabre\event\lib\Loop\Loop.php(261): Sabre\Event\Promise->Sabre\Event\{closure}()
#7 C:\Users\etien\.vscode\extensions\felixfbecker.php-intellisense-2.3.2\vendor\sabre\event\lib\Loop\Loop.php(215): Sabre\Event\Loop\Loop->runNextTicks()
#8 C:\Users\etien\.vscode\extensions\felixfbecker.php-intellisense-2.3.2\vendor\sabre\event\lib\Loop\Loop.php(194): Sabre\Event\Loop\Loop->tick(true)
#9 C:\Users\etien\.vscode\extensions\felixfbecker.php-intellisense-2.3.2\vendor\sabre\event\lib\Loop\functions.php(122): Sabre\Event\Loop\Loop->run()
#10 C:\Users\etien\.vscode\extensions\felixfbecker.php-intellisense-2.3.2\vendor\felixfbecker\language-server\bin\php-language-server.php(55): Sabre\Event\Loop\run()
#11 {main}
  Code: -32603 
Elfennacht commented 6 years ago

Same error here, comes when editing a function like the following: function test($p2) {} to function test(&$p1, $p2) {} When you type &$ in front of $p2 (&$$p2) the completion crash.

Looks like the parser doesn't like the string &$$ in function parameters

staabm commented 6 years ago

Looks like the parser doesn't like the string &$$ in function parameters

not only the parser doesnt like this kind of syntax ;-)

Elfennacht commented 6 years ago

I meant while typing, if you want to add a new variable passed by reference before an existing one, it will make the completion crash like seen above. I'll edit my previous comment to make it more understandable

felixfbecker commented 6 years ago

Does this still happen?

Elfennacht commented 6 years ago

It did for me. Nothing change.

felixfbecker commented 6 years ago

I would need a PHP file that reproduces the problem

Elfennacht commented 6 years ago

Here a gist to reproduce the problem: gist

felixfbecker commented 6 years ago

Thanks!