SanderRonde / phpstan-vscode

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

How to supply correct autoload file to docker? #39

Closed f-skold closed 10 months ago

f-skold commented 10 months ago

I am trying to use the extesion from a docker image, with some custom stuff for my repository. In my case it is in order to have the result of composer in the docker image since we rarely change this.

It would be nice to have som examples in the documentation about how to use it from dockerimage

I saw that there was two issues that was written with docker in focus (#1, #12, (#32) ). In #1, the opption "phpstan.paths": is mentioned, but it is hard to know what I should add there. (doc improvement)

If I add a censored block of output from the console (/efs/sandbox/username/projectname is the root of the git repo)

[check:6] Spawning PHPStan with the following configuration:  {"binCmd":"/efs/sandbox/username/projectname/meta/dev/wrappers/phpstan-docker.sh","args":["analyse","-c","/efs/sandbox/username/projectname/phpstan.neon","--error-format=raw","--no-interaction","--memory-limit=1G","--no-progress","--autoload-file","/app/shared/lib/autoprepend_phpstan.php","--debug","/efs/sandbox/username/projectname/FILE_TO_CHECK.php","-a","/tmp/tmp-11527-Pj3Q0WvKtxQ0/autoload.php","-c","/tmp/tmp-11527-Pj3Q0WvKtxQ0/config.neon"]}
[check:6] PHPStan process exited with error  filteredErr=Autoload file "/tmp/tmp-11527-Pj3Q0WvKtxQ0/autoload.php" not found.  rawErr=Autoload file "/tmp/tmp-11527-Pj3Q0WvKtxQ0/autoload.php" not found.

I am trying to supply --autoload-file, but the extension wants to supply -a. So it wolud be solved if there was an option to supply the autoload file in the extension. (So the extension could map/capy that file.

I could perhaps take a look at this myslef, put I am quite new to javascript/typescript and vs code extensions. So I would need instructions on "how to build"/package/test changes to the extension.

f-skold commented 10 months ago

Actually, when I did add path mapping, it looks much better:

    "phpstan.paths": {
        "/efs/sandbox/username/projectname": "/app"
    },

Snippet from the Output > PHPStan Client

[check:2] Spawning PHPStan with the following configuration:  {"binCmd":"/efs/sandbox/username/projectname/meta/dev/wrappers/phpstan-docker.sh","args":["analyse","-c","/app/phpstan.neon","--error-format=raw","--no-interaction","--memory-limit=1G","--no-progress","--autoload-file","/app/shared/lib/autoprepend_phpstan.php","--debug","/app/shared/lib/classes/AbstractImageManipulator.php"]}
[check:2] PHPStan process exited succesfully
SanderRonde commented 10 months ago

Ah yeah the docs are indeed a bit meh on the docker setup, largely because I don't use the docker setup myself (and haven't gotten it to work with any project) so it's a bit of guesswork for me too. There isa decent explanation of all the settings over here.

Regarding passing an autoload file, you can use the phpstan.options option and pass an autoload file that way. IIRC I made it smart enough to detect that you passed an autoload file (and made it so it does the rewriting it needs to do).

What is the current state of the issue? Does it work? From your last message it looks like it works but I'm not entirely sure :)

f-skold commented 10 months ago

It "works for me" now after adding the path mapping. Well I can see if I can sum up what I did to run it using docker.

I have a wrapper script that calls docker, set up mounts, and so on.

This is my config of the plugin.

{
    "phpstan.binPath": "/efs/sand/fredriks/skridskonet/meta/dev/wrappers/phpstan-docker.sh",
    "phpstan.options": [
        "--autoload-file",
        "/app/shared/lib/autoprepend_phpstan.php",
        "--debug"
    ],
    "phpstan.paths": {
        "/efs/sand/fredriks/skridskonet": "/app"
    },
    "phpstan.enableLanguageServer": false
}
SanderRonde commented 10 months ago

Good to hear! I'll close this issue for now then. I might dive into the docker setup and do a small writeup on the wiki at some point.