php-language-server
php-language-server copied to clipboard
phpDocumentor throws random RuntimeExceptions (TypeResolver failing all the time, Language Server not starting)
[Error - 20.38.18] Error parsing file:///c:/...: RuntimeException: A type is missing in an array expression in ...\felixfbecker.php-intellisense-2.3.12\vendor\phpdocumentor\type-resolver\src\TypeResolver.php:236
Apparently the phpDocumentor throws RuntimeException if there is typo or something in the doc block. Pretty bad but it can be fixed like this:
https://github.com/felixfbecker/php-language-server/blob/master/src/DefinitionResolver.php#L167
return $this->docBlockFactory->create($docCommentText, $context);
} catch (\InvalidArgumentException $e) {
return null;
}
to
return $this->docBlockFactory->create($docCommentText, $context);
} catch (\RuntimeException | \InvalidArgumentException $e) {
return null;
}
Here is a pull request: https://github.com/felixfbecker/php-language-server/pull/756
Note, the phpDocumentor puts a message to RuntimeException:
https://github.com/phpDocumentor/TypeResolver/blob/c0d13f995a30c295fa8f63d947153383d7597db5/src/TypeResolver.php#L156
E.g.
'A type is missing before a type separator' or 'Unexpected type separator' or 'Unexpected nullable character'
Maybe this could shown to user as warning if the line number can be extracted somehow. It's not a reason however to stop the whole thing from working.
I have a similar thing going on with mine. They're RuntimeExceptions, but different errors from what you're showing. They're essentially parsing errors on the doc blocks. Adding RuntimeException to the catch as shown above seems to quiet things down and keep the Output console from popping up on its own, but it would be nice to show these as warnings in the Problems console instead. I'm just not sure about the implications (or perhaps even the wisdom) of combining phpDocumenter errors with PHP errors.
Warnings would be nice, but the whole phpDocumentor is done badly, it should throw own parsing exception which contains the line number and file (or list of parsing errors). Instead it's reusing generic RuntimeException, which is not a good practice.
When running
composer run-script --working-dir=.composer/vendor/felixfbecker/language-server parse-stubs
I got a similar error message:
[RuntimeException] A type is missing before a type separator
I edited .composer/vendor/felixfbecker/language-server/src/DefinitionResolver.php
as described above (adding \RuntimeException |
to the catch
. The original command then completed.
Based on the comments above I went looking for the problem file. It seems that .composer/vendor/jetbrains/phpstorm-stubs/http/http3.php
has docblock code @deprecated
that might cause the problem, again, based on the comments of others.
I'm running "PHP 7.4.11 (cli) (built: Oct 1 2020 23:30:54) ( NTS )" if that helps.