SanderRonde / phpstan-vscode

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

Extension doesn't recognize that PHPStan Pro is running #82

Closed klunejko closed 1 month ago

klunejko commented 3 months ago

With pro disabled, everything works.

However, after I've enabled pro, the extension fails to pick up that the process spawned (and is running) and instead fails with: "Failed to start PHPStan Pro: Failed to launch PHPStan pro (tmp folder does not exist)".

Log shows the following [server] Language server ready [server] Language server started [pro] Spawning PHPStan Pro with the following configuration: {"binStr":"d:\local\dir\vendor\bin\phpstan","args":["analyse","-c","d:\local\dir\phpstan.dist.neon","--error-format=json","--no-interaction","--memory-limit=1G","--no-progress","--watch"],"tmpDir":"d:\local\dir\var\cache\phpstan"} [process-spawner] Spawning process 29160 with timeout 0 [server] PHPStan version: PHPStan - PHP Static Analysis Tool 1.11.5 [pro] PHPStan Pro: Open your web browser at: http://127.0.0.1:53042

System is W10 22H2, VS Code 1.90.2

SanderRonde commented 3 months ago

Hmm PHPStan should be creating some data over at ${tmpDir}/phpstan-fixer. Is that not the case for you? Is there something else (any folder) in that folder that the extension should be reading from? Or is the PHPStan Pro data itself maybe already in that tmp folder?

klunejko commented 3 months ago

PHPStan is running without any issues and can also access the cache folders. The extension also launches PHPStan successfully, but returns the above error, so it never actually runs in VS Code.

phpstan config:

parameters:
    tmpDir: var/cache/phpstan
    pro:
        tmpDir: var/cache/phpstan-pro

There might be an issue with parsing the tmp dir folder on the pro server? binPath for example is parsed and sent correctly, tmpDir isn't:

settings.json

"phpstan.binPath": "vendor/bin/phpstan",
"phpstan.tmpDir": "var/cache/phpstan"

Output

[client] Starting extension with configuration: {
    "binPath": "vendor/bin/phpstan",
    "pro": true,
    "tmpDir": "var/cache/phpstan",
    "checkValidity": true
}
[pro] Spawning PHPStan Pro with the following configuration:  {
"binStr":"d:\\local\\dir\\vendor\\bin\\phpstan",
"args":["analyse","-c","d:\\local\\dir\\phpstan.dist.neon","--error-format=json","--no-interaction","--memory-limit=1G","--no-progress","--watch"],
"tmpDir":"var/cache/phpstan"
}

And getting the same error, regardless of the format used:

settings.json "phpstan.tmpDir": "${workspaceFolder}/var/cache/phpstan"

Output

[client] Starting extension with configuration: {
"tmpDir": "${workspaceFolder}/var/cache/phpstan",
}

[pro] Spawning PHPStan Pro with the following configuration:  {
"tmpDir":"d:\\local\\dir/var/cache/phpstan"
}

settings.json "phpstan.tmpDir": "${workspaceFolder}\var\cache\phpstan"

Output

[client] Starting extension with configuration: {
"tmpDir": "${workspaceFolder}\\var\\cache\\phpstan",
}

[pro] Spawning PHPStan Pro with the following configuration:  {
"tmpDir":"d:\\local\\dir\\var\\cache\\phpstan"
}

settings.json "phpstan.tmpDir": "D:\local\dir\var\cache\phpstan"

Output

[client] Starting extension with configuration: {
"tmpDir": "D:\\local\\dir\\var\\cache\\phpstan",
}

[pro] Spawning PHPStan Pro with the following configuration:  {
"tmpDir":"d:\\local\\dir\\var\\cache\\phpstan"
}
SanderRonde commented 3 months ago

Ahh could be that the extension doesn't actually know to check the phpstan-pro tmp folder. It doesn't actually parse the .neon file itself, it relies on the settings. Since you're passing /var/cache/phpstan as the tmpdir it checks that. (or am I missing something)

So possible fixes would be:

Right?

klunejko commented 3 months ago

Ah, didn't realize the .neon isn't used/checked at all.

And looking at pro.ts (server/src/lib/phpstan/pro/pro.ts), it is indeed hardcoded to phpstan-fixer (within the tmpDir) and fails if that folder doesn't exist. Might be enough to change the order of the check? "Open your web browser" = launched successfully, everything else ist most likely an error.

And/or maybe include the directory that is missing, might save someone else some time in the feature ;)

'Failed to launch PHPStan Pro (tmp folder does not exist: ' + configDirPath +')'

SanderRonde commented 3 months ago

Yeah checking the neon file is actually surprisingly hard so I decided to leave it all to manual settings.

Not entirely sure what you mean with changing the order of the check. Indeed it printing "open your web browser" means that everything went well when it comes to starting PHPStan pro. However only at that point can we check whether the folder actually exists, since PHPStan will wait with creating the folder until it's actually started up completely. Checking the existence of the folder earlier is likely to cause the check to fail since the folder is yet to be created.

And/or maybe include the directory that is missing, might save someone else some time in the feature ;)

Hmm fair point, I do agree that the error message is not super helpful. Will update it.

Back to your issue though, are you able to fix it or is there something I should change in the extension to facilitate that? I think the easiest fix is for you to use the same tmpDir for pro and non-pro PHPStan. But I am wondering why you've chosen to use different tmpDirs for both. Alternatively I'd have to add a setting for setting the pro tmpDir separately from the regular one, but I'd rather not add more options if it's not strictly necessary.

SanderRonde commented 1 month ago

I'll close this issue for now since it's gone stale, feel free to re-open of course