SanderRonde / phpstan-vscode

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

"tmpDir" within *.neon files are not respected due to phpstan-vscode "phpstan.tmpDir" config #85

Closed Sectimus closed 1 month ago

Sectimus commented 1 month ago

When the vscode setting "phpstan.tmpDir" is unset, we should not default to /tmp/phpstan. We should instead honor the tmpDir setting in each of the passed config files:

parameters:
    paths:
        ...
    excludePaths:
       ...
    tmpDir: ../../.phpstan.cache/tests

Currently we ignore this value altogether and attempt to set the cache to /tmp/phpstan which can cause really awful performance on docker environments since we won't have a prebuilt cache there on container start (unless we bind the /tmp/phpstan directory to somewhere on the host. And this is also wiped on restart of the container, causing every first run (after opening vscode) to take exceedingly long.

This also means if we are using more than one config file via "phpstan.configFile" then every single run is going to never use the cache, since they both try to write to the same cache, which causes it to be invalid as per the PHPStan result cache docs:

Analysis variables used to invalidate a stale cache. If any of these values change, full analysis is performed again.

PHPStan version PHP version Loaded PHP extensions Rule level Configuration files hashes Analysed paths composer.lock files hashes Stub files hashes Bootstrap files hashes Autoload file hash

Sectimus commented 1 month ago

Just to add with a few changes it does look like it actually reads the correct file, it's just the output of the extension that is printing the wrong information [check:2] Spawning PHPStan with the following configuration: {"binStr":"docker","args":["exec","-t","REDACTED_apiphp-1","php","/var/www/REDACTED/vendor/bin/phpstan","analyse","-c","/var/www/REDACTED/build/phpstan/tests.2.neon.dist","--error-format=json","--no-interaction","--memory-limit=4096M"],"tmpDir":"**/tmp/phpstan_**"}

SanderRonde commented 1 month ago

Ah yeah that would explain it. It was intentional that the tmpDir wasn't being used since it's not trivial to parse a neon file, but indeed on machines/docker-images that reboot often, storing cache in tmp will cause a lot of full checks.

Will try to fix this but again I'm a bit busy currently. But thanks for the report!

SanderRonde commented 1 month ago

Turns out I didn't need to parse the neon file, the default wasn't needed at all and I just removed it. Will ship this in a release soon, I'll try to tackle the other issue first to get them shipped together.