SanderRonde / phpstan-vscode

PHPStan plugin for VSCode
https://marketplace.visualstudio.com/items?itemName=SanderRonde.phpstan-vscode
MIT License
37 stars 7 forks source link

Language server crash on vscode linux #83

Closed apss-pohl closed 1 week ago

apss-pohl commented 1 week ago

I get constant crashes. Problem is this:

SyntaxError: Unexpected token '/', "/mnt/share"... is not valid JSON

I added a console.log to "/home/sven/.vscode/extensions/sanderronde.phpstan-vscode-3.1.12/out/server.js:76:1909" Find the ouptu below.

[check:1] Check started for file: file:///mnt/share/dev/code/freeclimber-gtk3/dev/test.php
[check:1] Spawning PHPStan with the following configuration:  {"binStr":"/mnt/share/dev/code/bin/library-dev/vendor/bin/phpstan","args":["analyse","-c","/mnt/share/dev/code/phpstan.neon","--error-format=json","--no-interaction","--memory-limit=2G","--no-progress","--debug","--error-format=table","/mnt/share/dev/code/dev/test.php"],"tmpDir":"/tmp/phpstan"}
[server] PHPStan version: PHPStan - PHP Static Analysis Tool 1.11.6

[check:1] PHPStan process exited succesfully
/mnt/share/dev/code/dev/test.php

 [OK] No errors                                                                 

 2
undefined:1
/mnt/share/dev/code/dev/test.php
^

SyntaxError: Unexpected token '/', "/mnt/share"... is not valid JSON
    at JSON.parse (<anonymous>)
    at ChildProcess.<anonymous> (/home/sven/.vscode/extensions/sanderronde.phpstan-vscode-3.1.12/out/server.js:76:1909)

Node.js v20.9.0
[Info  - 10:30:46 AM] Connection to server got closed. Server will restart.
SanderRonde commented 1 week ago

What logging did you add exactly? So what values is it logging? The line number you shared is the line of minified code in the bundle so I don't really know what should be on that line. A screenshot of the logging code might be a bit nicer if that's possible.

apss-pohl commented 1 week ago

image I did the log in the minified code, maybe this picture might help you to find it?

SanderRonde commented 1 week ago

I think that's the output of the PHPStan process being parsed, which is expected to be JSON. If that's for some reason invalid then something must have gone wrong. You can check it pretty easily by running PHPStan by itself on the commandline with the args that are listed there. Then you can see what it outputs and whether it's an error.

apss-pohl commented 1 week ago

I just figured it: "--error-format=table" together with "--debug" is causing it. Sorry, my bad! I was trying to somehow understand why phpstan doesn't recognize the classes when pulled in as a global. php storm seems to be capable but vscode not, even tho the highlighting seems to know everything. In this example i would expect a complaint that there is only one param: image It is working if i annotate: image But the real project is huge and i cant annotate in every file.

SanderRonde commented 1 week ago

Ahh good to know you figured out the issue. I'll close this issue for now to signal you figured it out :)

Regarding PHPStan not detecting the import. That might be related to the global not being included or something. But not too sure, the global-patten isn't one I use that often.