SanderRonde / phpstan-vscode

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

Error with stock config : At least one path must be specified to analyse #69

Closed lcharette closed 7 months ago

lcharette commented 7 months ago

I've recently switched laptop and for some reason, this extension doesn't work on the new one. Note that both laptop are using the same config, the same PHP project, and the same PHPStan config. Nothing fancy, phpstan is in vendor/bin/phpstan, source code in src/, no Docker or anything similar. PHP installed locally using Homebrew on a Mac. A very basic setup, where everything should work out of the box.

Complete error, using stock :

[file-watcher] Document changed, triggering
[check:5] Check started for project
[status-bar] Showing status bar
[check:5] Spawning PHPStan with the following configuration:  {"binStr":"/Users/malou/GitHub/userfrosting/framework/vendor/bin/phpstan","args":["analyse","-c","/Users/malou/GitHub/userfrosting/framework/phpstan.neon","--error-format=json","--no-interaction","--memory-limit=1G"]}
[process-spawner] Spawning process 5372 with timeout 900000
[check:5] PHPStan process exited with error  filteredErr=At least one path must be specified to analyse.  rawErr=At least one path must be specified to analyse.
  data=
[status-bar] Hiding status bar, last operation result = Error
[check:5] Check completed for project, errors= {"fileSpecificErrors":{},"notFileSpecificErrors":[]}

Same when doing a project scan :

[check:7] Check started for project
[status-bar] Showing status bar
[check:7] Spawning PHPStan with the following configuration:  {"binStr":"/Users/malou/GitHub/userfrosting/framework/vendor/bin/phpstan","args":["analyse","-c","/Users/malou/GitHub/userfrosting/framework/phpstan.neon","--error-format=json","--no-interaction","--memory-limit=1G"]}
[process-spawner] Spawning process 5949 with timeout 900000
[check:7] PHPStan process exited with error  filteredErr=At least one path must be specified to analyse.  rawErr=At least one path must be specified to analyse.
  data=
[status-bar] Hiding status bar, last operation result = Error
[check:7] Check completed for project, errors= {"fileSpecificErrors":{},"notFileSpecificErrors":[]}

Any tip ?

SanderRonde commented 7 months ago

What might explain the difference in behaviors might be that one of your devices is using the old version of the extension (2.0.X) and the other the new version (3.0.X). Can you check for me which one is using which? That could help me debug a bit.

That reported error does look like something PHPStan itself would spit out. Could you do these things?:

lcharette commented 7 months ago

I don't have access to the old laptop right now to confirm the version, but new one does have v3.0.7 Old laptop was indeed running 2.2.21, and the new one 3.0.7

  1. https://github.com/userfrosting/framework/blob/5.1/phpstan.neon
  2. Command line works fine :
    
    $ /Users/malou/GitHub/userfrosting/framework/vendor/bin/phpstan analyse src/UserFrosting.php -c /Users/malou/GitHub/userfrost
    ing/framework/phpstan.neon --error-format=json --no-interaction --memory-limit=1G
    1/1 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%

{"totals":{"errors":0,"file_errors":0},"files":[],"errors":[]}


3. Already disabled
lcharette commented 7 months ago

Note 2.2.26 does work. Here's the log from 2.2.26. The file path is missing from the arguments in 3.0.7...

[check:10] Spawning PHPStan with the following configuration:  {"binCmd":"/Users/malou/GitHub/userfrosting/framework/vendor/bin/phpstan","args":["analyse","-c","/Users/malou/GitHub/userfrosting/framework/phpstan.neon","--error-format=raw","--no-interaction","--memory-limit=1G","--no-progress","/Users/malou/GitHub/userfrosting/framework/src/UserFrosting.php"]}
[check:10] PHPStan process exited succesfully
SanderRonde commented 7 months ago

Ah that sort of makes sense. At least one path should indeed be specified to analyze, and if your config.neon does not specify one then one must be provided when running. The new version of the extension no longer does per-file checking since the author of PHPStan warns against doing so. Instead it checks the entire project at once, using the PHPStan-builtin cache to ensure only relevant files are checked.

How do you normally run this in something like a CI, where you want to check the entire project? Or do you only run this per individual file?

lcharette commented 7 months ago

CI example can be found here : https://github.com/userfrosting/framework/blob/5.1/.github/workflows/PHPStan.yml

For my local workflow, I'm used to individual files being checked on save. But I'm open to improve to what's best.

SanderRonde commented 7 months ago

Ah okay. I think this can be fixed pretty easily. If you add the src and tests directories as paths in your phpstan.neon then it'll work again. This will both allow you to remove those paths from the workflow file (since it automatically does those) and will still allow you to check individual files still if you provide them as commandline arguments. Let me know if that works!

lcharette commented 7 months ago

Alright. This works, thanks for the quick support, very appreciated !