phpactor / phpactor

Mainly a PHP Language Server with more features than you can shake a stick at
MIT License
1.37k stars 126 forks source link

Issue in VSCode: DiagnosticsParser.php, Could not decode expected PHPStan JSON string #2332

Open ckilb opened 1 year ago

ckilb commented 1 year ago

New installation of PHPActor in VSCode breaks with:

[Info  - 14:06:32] Connection to server got closed. Server will restart.
Starting language server, use -vvv for verbose output

In DiagnosticsParser.php line 46:

  Could not decode expected PHPStan JSON string ""  

Any idea how to fix this?

dantleech commented 1 year ago

Is this a regression with today's release?

ckilb commented 1 year ago

Closing this. PHPActor by default takes PHPStan from the project dir which - in my case - includes a binary for another platform.

dantleech commented 1 year ago

ok, it probably shouldn't crash however

leo-unglaub commented 1 year ago

I just ran into the same issue while beeing on 1869936f5bd01515ddc8ada0928e9458dfd9a6e1. This causes

Starting language server, use -vvv for verbose output
In DiagnosticsParser.php line 46:

  Could not decode expected PHPStan JSON string ""  

language-server [--address ADDRESS] [--no-loop]

[Info  - 15:33:44] Connection to server got closed. Server will restart.
[Error - 15:33:44] Request textDocument/codeAction failed.

This causes the server to crash and then it triggers phpactor/phpactor/issues/2358.

dantleech commented 1 year ago

Whatever the cause it shouldn't crash the server

scippio commented 2 months ago

I have same error: https://github.com/larastan/larastan/issues/1978

mamazu commented 2 months ago

This has been broken for some time now (I just never bothered fixing it). The fix I suggested only deals with empty outputs. Should we also just quietly fail with an error message and then continue in case phpstan sends invalid JSON?

scippio commented 2 months ago

The interesting thing is, when I run it manually exactly like phpactor on same file I get valid JSON: /usr/bin/php /home/scippio/.../vendor/bin/phpstan analyse --no-progress --error-format=json /tmp/phpstanlspXyM1S

{
    "totals": {
        "errors": 0,
        "file_errors": 13
    },
    "files": {
        "/tmp/phpstanlspXyM1S": {
            "errors": 13,
            "messages": [
                {
                    "message": "Attribute class Vyuldashev\\LaravelOpenApi\\Attributes\\PathItem does not exist.",
                    "line": 30,
                    "ignorable": true,
                    "identifier": "attribute.notFound"
                },
                {
                    "message": "Attribute class Vyuldashev\\LaravelOpenApi\\Attributes\\Operation does not exist.",
                    "line": 49,
                    "ignorable": true,
                    "identifier": "attribute.notFound"
                },
                {
                    "message": "Attribute class Vyuldashev\\LaravelOpenApi\\Attributes\\Operation does not exist.",
                    "line": 65,
                    "ignorable": true,
                    "identifier": "attribute.notFound"
                },
                {
                    "message": "Attribute class Vyuldashev\\LaravelOpenApi\\Attributes\\Operation does not exist.",
                    "line": 82,
                    "ignorable": true,
                    "identifier": "attribute.notFound"
                },
                {
                    "message": "Attribute class Vyuldashev\\LaravelOpenApi\\Attributes\\Operation does not exist.",
                    "line": 94,
                    "ignorable": true,
                    "identifier": "attribute.notFound"
                },
                {
                    "message": "Attribute class Vyuldashev\\LaravelOpenApi\\Attributes\\Operation does not exist.",
                    "line": 111,
                    "ignorable": true,
                    "identifier": "attribute.notFound"
                },
                {
                    "message": "Attribute class Vyuldashev\\LaravelOpenApi\\Attributes\\Operation does not exist.",
                    "line": 123,
                    "ignorable": true,
                    "identifier": "attribute.notFound"
                },
                {
                    "message": "Attribute class Vyuldashev\\LaravelOpenApi\\Attributes\\Operation does not exist.",
                    "line": 137,
                    "ignorable": true,
                    "identifier": "attribute.notFound"
                },
                {
                    "message": "Attribute class Vyuldashev\\LaravelOpenApi\\Attributes\\Operation does not exist.",
                    "line": 153,
                    "ignorable": true,
                    "identifier": "attribute.notFound"
                },
                {
                    "message": "Attribute class Vyuldashev\\LaravelOpenApi\\Attributes\\Operation does not exist.",
                    "line": 188,
                    "ignorable": true,
                    "identifier": "attribute.notFound"
                },
                {
                    "message": "Attribute class Vyuldashev\\LaravelOpenApi\\Attributes\\Operation does not exist.",
                    "line": 205,
                    "ignorable": true,
                    "identifier": "attribute.notFound"
                },
                {
                    "message": "Attribute class Vyuldashev\\LaravelOpenApi\\Attributes\\Operation does not exist.",
                    "line": 222,
                    "ignorable": true,
                    "identifier": "attribute.notFound"
                },
                {
                    "message": "Attribute class Vyuldashev\\LaravelOpenApi\\Attributes\\Operation does not exist.",
                    "line": 259,
                    "ignorable": true,
                    "identifier": "attribute.notFound"
                }
            ]
        }
    },
    "errors": []
}
scippio commented 2 months ago

ok, so I analysed the problem and there is two "issues" I hope it's maybe help someone (even if it's maybe not same problem like in VSCode):

1. Environment

I running project in the Docker container. But the PHPStan is executed in my IDE environment. So frist thing: I must have same PHP/libraries installed on my system like in Docker container. (Or I should run phpstan in Docker and that's almost impossible in phpactor setup...)

2. Different PHPStan executable (Mason)

I don't know how to run PHPStan binary outside vendor/ directory (Mason binary is normally in: ~/.local/share/nvim/mason/bin/phpstan). PHPStan still reports an error that "Path does not exists" whether I use relative or absolute path to directory for analyse even if I add path to configuration phpstan.neon in my root project directory.

So... it's working for me now :tada: , because:

1) I installed missing PHP extensions (to have it the same as I have it in Docker) 2) I don't use Mason PHPStan and use default vendor/ PHPStan.

PS: :heart: But I would rather use Mason PHPStan binary... because it's better update/checking for me via IDE etc.. But I don't know how (see point 2).

dantleech commented 2 months ago

hm.

i mean, if you can run the Mason PHPStan on your host, then you can run the project's PHPStan version on your host? i.e. I assume you mount your ptroject in the container, so actually have ./vendor/bin/phpstan?

but also, if it works with Mason, and that's better, then is there a reason to use the Phpactor integration?

but glad you found a solution!

scippio commented 2 months ago

hm.

i mean, if you can run the Mason PHPStan on your host, then you can run the project's PHPStan version on your host? i.e. I assume you mount your ptroject in the container, so actually have ./vendor/bin/phpstan?

but also, if it works with Mason, and that's better, then is there a reason to use the Phpactor integration?

but glad you found a solution!

Yeah... I can link my Mason PHPStan binary to vendor/bin/phpstan by linux symbolic link .. that might work :thinking: in that case maybe I should remove phpstan from composer...

Mason is only "package manager" .. so it's only installing PHPStan/binary/etc. into Mason directory and checking updates.. ( https://github.com/williamboman/mason.nvim )