felixfbecker / php-language-server

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

Error when using namespaces. #577

Open PandarinDev opened 6 years ago

PandarinDev commented 6 years ago

Disclaimer: I'm using php-language-server with your VS Code extension, and I'm not 100% sure that it is a language server bug as it could be a problem in the extension. However, since the error is thrown by the language server I decided to open an issue on this project.

Platform: Windows 10 x64 Config: php.executablePath and php.validate.executablePath in VS Code settings are both set to where php.exe is on my system (using version 7.2, non-threadsafe x64).

Whenever I try to use namespaces I get the following error:

[Info  - 14:16:19] 1 files total
[Info  - 14:16:19] Indexing project for definitions and static references
Parsing file:///c:/Projects/Legacy/Source/Index.php
[Info  - 14:16:19] Indexing project for dynamic references
[Info  - 14:16:19] 0 Packages
[Info  - 14:16:19] All 1 PHP files parsed in 0 seconds. 124 MiB allocated.
[Error - 14:19:12] Request textDocument/completion failed.
  Message: ErrorException: Invalid argument supplied for foreach() in C:\Users\Pandarin\.vscode\extensions\felixfbecker.php-intellisense-2.2.5\vendor\microsoft\tolerant-php-parser\src\Node.php:491
Stack trace:
#0 C:\Users\Pandarin\.vscode\extensions\felixfbecker.php-intellisense-2.2.5\vendor\microsoft\tolerant-php-parser\src\Node.php(491): {closure}(2, 'Invalid argumen...', 'C:\\Users\\Pandar...', 491, Array)
#1 C:\Users\Pandarin\.vscode\extensions\felixfbecker.php-intellisense-2.2.5\vendor\felixfbecker\language-server\src\CompletionProvider.php(311): Microsoft\PhpParser\Node->getImportTablesForCurrentScope()
#2 C:\Users\Pandarin\.vscode\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\Pandarin\.vscode\extensions\felixfbecker.php-intellisense-2.2.5\vendor\sabre\event\lib\coroutine.php(70): Generator->send(Object(LanguageServer\PhpDocument))
#5 C:\Users\Pandarin\.vscode\extensions\felixfbecker.php-intellisense-2.2.5\vendor\sabre\event\lib\Promise.php(242): Sabre\Event\{closure}(Object(LanguageServer\PhpDocument))
#6 C:\Users\Pandarin\.vscode\extensions\felixfbecker.php-intellisense-2.2.5\vendor\sabre\event\lib\Loop\Loop.php(261): Sabre\Event\Promise->Sabre\Event\{closure}()
#7 C:\Users\Pandarin\.vscode\extensions\felixfbecker.php-intellisense-2.2.5\vendor\sabre\event\lib\Loop\Loop.php(215): Sabre\Event\Loop\Loop->runNextTicks()
#8 C:\Users\Pandarin\.vscode\extensions\felixfbecker.php-intellisense-2.2.5\vendor\sabre\event\lib\Loop\Loop.php(194): Sabre\Event\Loop\Loop->tick(true)
#9 C:\Users\Pandarin\.vscode\extensions\felixfbecker.php-intellisense-2.2.5\vendor\sabre\event\lib\Loop\functions.php(122): Sabre\Event\Loop\Loop->run()
#10 C:\Users\Pandarin\.vscode\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 

Consistently reproducible on my system, I just have to open a .php file in VS Code and type the keyword namespace and the moment I write something after that I get a stacktrace similar to the above.

Thanks for your hard work, just wanted to let you know your tools are really useful to a lot of people. Cheers!

PandarinDev commented 6 years ago

Any updates on this?

felixfbecker commented 6 years ago

Is this still happening?

maknapp commented 5 years ago

This is still happening for me. This error only seems to happen if you write php closing tags first, and then go back and write the namespace in.

<?php

?>

then the moment you type T the error occurs:

<?php
namespace T
?>

I was on PHP v7.1.6 and was getting an undefined object error with the same tolerant-php-parser\src\Node.php file. I just now updated to PHP v7.3.2 and got the same error as OP Invalid argument supplied for foreach(). It seems like this is an issue with Microsoft/tolerant-php-parser.