SanderRonde / phpstan-vscode

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

PHPStan process exited with error in WSL 2 #16

Closed c3n21 closed 1 year ago

c3n21 commented 1 year ago

Hello,

when trying to run this extension inside a WSL container it gives me this error:

[check:24] Spawning PHPStan with the following configuration:  {"binCmd":"\\\\wsl.localhost\\WorkArch\\home\\zhifan\\Documents\\Projects\\magento\\hrm-training-commerce\\vendor\\bin\\phpstan","args":["analyse","-c","\\\\wsl.localhost\\WorkArch\\home\\zhifan\\Documents\\Projects\\magento\\hrm-training-commerce\\phpstan.neon","--error-format=raw","--no-interaction","--memory-limit=1G","--no-progress","\\\\wsl.localhost\\WorkArch\\home\\zhifan\\Documents\\Projects\\magento\\hrm-training-commerce\\app\\code\\HRM\\Rma\\Test\\Unit\\Observer\\RequestUpdateObserverTest.php","-a","C:\\Users\\ZHIFAN~1\\AppData\\Local\\Temp\\tmp-79096-enUzrrgevQAT\\autoload.php","-c","C:\\Users\\ZHIFAN~1\\AppData\\Local\\Temp\\tmp-79096-enUzrrgevQAT\\config.neon"]}

[check:24] PHPStan process exited with error  err= '\\wsl.localhost\WorkArch\home\zhifan\Documents\Projects\magento\hrm-training-commerce'
CMD.EXE was started with the above path as the current directory.
UNC paths are not supported.  Defaulting to Windows directory.
'\\wsl.localhost\WorkArch\home\zhifan\Documents\Projects\magento\hrm-training-commerce\vendor\bin\phpstan' is not recognized as an internal or external command,
operable program or batch file.
  data= 

Settings are the default ones.

Any tips to make this work inside WSL?

SanderRonde commented 1 year ago

Hmm are you using the WSL extension in VSCode or are you using another way of opening the WSL folder? As far as I know, when using WSL in VSCode the file paths are all relative to the WSL root and don't use windows-style paths (such as \\wsl.localhost\WorkArch). When you open a terminal in your repo and run pwd what do you get?

c3n21 commented 1 year ago

You were right I wasn't running VSCode in the "correct way"; I had to navigate to the path inside WSL and there I had to code ..

But still it errors out with this

[check:1] PHPStan process exited with error  err= Xdebug: [Step Debug] Could not connect to debugging client. Tried: localhost:9003 (through xdebug.client_host/xdebug.client_port) :-(

and I need to check PHPStan Language Server to know the errors diagnosed by PHPStan. Is this the way it is supposed to work or it should integrate with VSCode's diagnostics?

SanderRonde commented 1 year ago

It should work if you get rid of that error. I'm pretty sure it's caused by XDebug starting when it shouldn't (more info about how to fix it here). To debug it you can just try running PHPStan outside of the extension and you should run into the same error (the error isn't related to the PHPStan VSCode extension).

After this it should no longer exit with an error and exit successfully and the errors diagnosed should be integrated into VSCode's diagnostics.

c3n21 commented 1 year ago

I don't know why it throws that error but I managed to work it around.

For PHP development I'm using DDEV which is basically a wrapper around docker-compose that helps you manage PHP environments and has its own way to run xdebug.

What I had to do was to attach to the webserver container inside VSCode image

and now it works like a charm.

By the way, since this doesn't seem a fatal error, could you provide a way to ignore this error in the extensions' settings?

SanderRonde commented 1 year ago

Great to hear that it's working!

It's surprisingly hard to ignore PHPStan errors. Since you can't rely on the exit code to find out whether it exited with an error, you have to look at whether stderr was set. I could then filter out any error that contains this xdebug string but I'm sure that won't work on systems with different languages or different xdebug settings (for example in this case it's using "Step Debug", another config might not). I'll definitely keep this in mind though, and if it happens more often I'll consider adding such a feature. For now I'll hold off on adding it.

(I'll close the issue since I think your problem has been resolved)

SanderRonde commented 1 year ago

FYI I've implemented something close to what you suggested in the latest release. Instead of ignoring xdebug stuff, there's a new setting (phpstan.ignoreErrors) where you can put to-be-ignored errors.