Make PHP LSP bridge robust: filter noise + buffer JSON output#71
Make PHP LSP bridge robust: filter noise + buffer JSON output#71jan-dh wants to merge 1 commit intomoetelo:masterfrom
Conversation
|
|
||
| child.on('close', (code) => resolve({ stdout, stderr, code })); | ||
| child.on('close', (code) => { | ||
| const jsonStart = stdout.search(/[{[]/); |
There was a problem hiding this comment.
I don't really want to rely in trying to find [ or { in the stdout. Deprecation notices possibly could use these characters to format their messages, like [Deprecated]. I see that it's not the case but this solution does not seem that robust to me.
In continuation of this comment: #69 (comment)
I was expecting all the warnings go to stderr, and the rest to stdout. Now I see that running php bin/console depends on the user environment (php.ini).
According to the PHP runtime documentation, we can use the ini option display_errors to make the php executable do the expected thing.
https://www.php.net/manual/en/errorfunc.configuration.php#ini.display-errors
Value "stderr" sends the errors to
stderrinstead ofstdout.
And we can pass ini option as an argument to php using -d param:
php -d display_errors=stderr bin/console debug:twig --format json
(src: https://www.php.net/manual/en/features.commandline.options.php)
Now, if we change this:
twiggy/packages/language-server/src/phpInterop/PhpExecutor.ts
Lines 21 to 26 in c65e81f
to this:
const result = await exec(this._phpExecutable, [
'-d',
'display_errors=stderr',
command,
...args,
], {
cwd: this._workspaceDirectory
});that would hopefully to fix the issue.
PHP processes often emit deprecation warnings, notices, or other text before/after JSON LSP messages (especially on PHP 8.4+) — breaking the language server’s JSON protocol causing VSCode to crash (see #69
).