-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for multiple config files based on a file pattern (different to order of precendence) #107
Comments
I do like solution 2 a lot more since it requires a lot less user effort and is less likely to go wrong. But I do have to say that I'm not super opposed to the idea anymore. A few challenges still that I'll have to think about and that this kind of hinges on:
These are kind of the two biggest implementation issues. If it turns out that one of them is just really hard to find a solution for (or it is possible but really complex) then it's probably not worth it to implement this. If they turn out to be doable then it should be rather easy to implement. So TLDR: I am open to the idea but will have to think about it a bit. Might take a while before this is implemented though since I am a bit busy in the coming weeks and since bug-fixes obviously take priority. |
I'd prefer the mutually exclusive option to not impact current user setups (I'm pretty sure I have seen other extensions do this, so that your I would say "phpstan.configFiles": [
"${workspaceFolder}/src.phpstan.neon, ${workspaceFolder}/src.phpstan.neon.dist, ${workspaceFolder}/src.phpstan.dist.neon",
"${workspaceFolder}/test.phpstan.neon, ${workspaceFolder}/test.phpstan.neon.dist, ${workspaceFolder}/test.phpstan.dist.neon"
], IE. having the below configured in "phpstan.configFile": "${workspaceFolder}/src.phpstan.neon, ${workspaceFolder}/test.phpstan.neon",
"phpstan.configFiles": [
"${workspaceFolder}/src.phpstan.neon",
"${workspaceFolder}/test.phpstan.neon"
],
It could be worth just having a small PHP script that will take a The compute shouldn't be that taxing at all for this, so shouldn't impact run time and could probably be done as a pre-task to every run of the extension. As much as it pains me, I do understand the low priority. Thank you for all the effort, know that it is very much appreciated. |
Hmm yeah I agree that using an array of comma-separated values is probably the best. I'm also considering just switching to
Maybe good to get the scenarios as to which one is evaluated when clear:
I'm a bit wary of this for a couple of reasons:
I completely agree that this would be ideal and would be a great match to what PHPStan does, but I'm thinking this is likely to cause a lot of edge cases with system setups to pop up. Maybe simpler to just build a JS implementation of the neon parser (possibly porting it with ✨AI✨) and keep it all in-extension. |
Well I've just found a neon parser in JS so that's no longer a problem. That's pretty nice |
I've implemented it and I think it works (tested it with the new |
Sorry for the late response! For me whilst this does work, it doesn't really suit my purpose since I have certain folders as set up as different workspaces in vscode. I see that this extension doesn't support multi-root workspaces (and only supports the first workspace shown), but was wondering if we could have an override to enable per-workspace scans? My phpstan config files point to these different roots, so even if we ran all of these phpstan processes on different workspaces at the same time: I wouldn't have any crosstalk. But it is not possible to do so atm. I can see why you didn't support multi-root in the first place, with cache invalidation probably being a big drive, but if you configure your stan configs correctly to point to the right directories, then it should just work. |
Hmm that does complicate things a bit, largely because configuration right now is all relative to the current workspace. But it may be doable to fit this into the current model. As multiple configs are now supported in this branch, it uses the currently scanned file to determine the neon file. It's not a massive stretch to also use that file to determine its workspace folder to base the config off of. Some questions though to understand:
|
I do have some projects with multiple neon files in them for scanning different directories of the same project. Wheras I have a separate application that is still a part of the same overall project, so it is a separate root workspace in vscode. https://code.visualstudio.com/docs/editor/multi-root-workspaces. I could place all of my .neon config files from all of my projects in the new "phpstan.configFiles" setting, however only changes in the first workspace root will trigger this extension to start scanning. Wheras I would be looking for an override to allow it to trigger on changes to any workspace root. in my workspace: ...
"folders": [
{
"name": "primary",
"path": "../primary"
},
{
"name": "secondary",
"path": "../secondary"
},
],
... Any changes in the "../primary" directory will trigger phpstan scans, this will also scan the "../secondary" directory as expected (due to the new and shiny multi-config file support) - However nothing you ever do in the "../secondary" directory could trigger the extension to start a scan, even if your setup could handle it.
Most extension handle this with path mappings. For instance: "phpunit.paths": {
"${workspaceFolder:primary}": "/var/www/primary",
"${workspaceFolder:secondary}": "/var/www/secondary",
} It could be something like: "phpstan.paths": {
"${workspaceFolder:primary}": [
"config/primary.1.neon",
"config/primary.2.neon",
"config/primary.3.neon"
],
"${workspaceFolder:secondary}": [
"config/secondary.src.neon",
"config/secondary.tests.neon"
]
} Although just allowing the scan to be triggered from any workspace root sounds like a simpler solution that would also work for me :) |
The new version actually doesn't seem to work as expected in terms of this feature, the scan never completes when I use more than one config, when each works individually on their own. See my attached video 2024-10-07.11-56-43.mp4 |
I've just added multi-workspace support, I think it works (I've tested it on a demo project and it worked). Could you give it a try? Regarding the testing not succeeding when using multiple configs, could you send along the logs of the extension ( Regarding my questioning of how to configure this, I did not know that VSCode allows for per-workspace settings that would then space multiple workspace roots. So indeed configuring it in the workspace settings is entirely fine. I've right now allowed for |
This issue exists to diverge this discussion to it's own issue
The problem:
There is currently no way to allow this extension to use a different config file based on directory of the file that was saved.
Solution 1:
I propose a new setting where we can map our configs to directories.
this example would be mutually exclusive with
phpstan.configFile
Solution 2:
We could instead just read the parameters.paths & paramerers.excludePaths values in the PHPStan config files, since it is just using the
fnmatch()
function to interpret them, we could do the same process to receive the same result without needing to define a new setting.The text was updated successfully, but these errors were encountered: