phpstan-vscode icon indicating copy to clipboard operation
phpstan-vscode copied to clipboard

Option to scan only current project on save

Open BlackLanzer opened this issue 5 months ago • 3 comments

I'm working on some projects where inside the main project I also have some packages source code.
These packages have their phpstan.neon referencing some vendor/xxx, but vendor doesn't exist because only the root project has vendor folder.

When I save the extension check all the projects and stops at the first error, so if it first check one of the packages it just stops.

Is it possibile to add an option to just scan current project on save? Or don't stop on first error.

BlackLanzer avatar Sep 03 '25 10:09 BlackLanzer

Issues go stale after too much time without activity. If inactive for another 7 days this issue will be closed.

github-actions[bot] avatar Nov 03 '25 02:11 github-actions[bot]

Hey sorry for not responding, I've been a bit busy. That should be possible, will implement it when I find the time.

SanderRonde avatar Nov 03 '25 09:11 SanderRonde

I looked into it some more. It looks like the extension doesn't actually scan all projects when one changes. On-save it only scans the project that belongs to the saved file. It actually doesn't know about the existence of the other projects in the workspace and only does a lookup on-save. Are you sure this is the current behavior? Is it not PHPStan doing this itself?

SanderRonde avatar Nov 03 '25 15:11 SanderRonde

I made some better testing.

This is my current folder structure:

project/
├── phpstan.neon
├── app.php
└── libs/
    ├── mylib1/
    |   ├── mylib.php
    │   └── phpstan.neon
    ├── mylib2/
    │   └── phpstan.neon

This structure is needed so I can edit the libraries while workin on the main project, but the libraries can live on their own, so they have their own phpstan.neon.
On the main phpstan.neon I have libs/ in the path, so they get scanned.

Inside every phpstan.neon there is a includes: vendor/....

Problem:

  • When I'm inside project/app.php and I save, extension runs phpstan on current project, with project/phpstan.neon, and everything is good.
  • When I'm inside mylib1/mylib.php and I save, extension runs phpstan with mylib1/phpstan.neon. In this case phpstan looks for mylib1/vendor/... and can't find it, crashing and resetting all the other errors.
  • When I run manually "Scan project for errors" it tries to run all the phpstan.neon files, crashing on the libraries and resetting all the other errors

I don't know what's the best way to make this work. Maybe an option to force a specific phpstan.neon in the workspace?

BlackLanzer avatar Nov 06 '25 10:11 BlackLanzer