SanderRonde / phpstan-vscode

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

Extension Erroring Out because of notification of config file #96

Closed baschnipke closed 2 months ago

baschnipke commented 2 months ago

Here's the error I'm receiving: `[8/21/2024, 3:46:47 AM] [server] Language server ready [8/21/2024, 3:46:47 AM] [server] PHPStan version: Docker version 27.0.3, build 7d4bcd8

[8/21/2024, 3:46:47 AM] [file-watcher] Checking: Initial check [8/21/2024, 3:46:47 AM] [check:1] Check started for project [8/21/2024, 3:46:47 AM] [check:1] Spawning PHPStan with the following configuration: {"binStr":"docker","args":["exec","--workdir","/var/www/html","-t","redacted-laravel.test-1","bash","-c","vendor/bin/phpstan","--error-format=json","analyse","-c","/var/www/html//phpstan.neon","--error-format=json","--no-interaction","--memory-limit=1G"]} [8/21/2024, 3:46:49 AM] [check:1] PHPStan process exited succesfully undefined:1 Note: Using configuration file /var/www/html/phpstan.neon. ^

SyntaxError: Unexpected token 'N', "Note: Usin"... is not valid JSON at JSON.parse () at ChildProcess. (/home/bobby/.vscode-server/extensions/sanderronde.phpstan-vscode-3.1.14/out/server.js:76:1890)

Node.js v20.14.0 [Error - 3:46:49 AM] The PHPStan Language Server server crashed 5 times in the last 3 minutes. The server will not be restarted. See the output for more information.`

And here are my config settings: "phpstan.binCommand": [ "docker", "exec", "--workdir", "/var/www/html", "-t", "redacted-laravel.test-1", "bash", "-c", "vendor/bin/phpstan", "--error-format=json", ], "phpstan.configFile": "phpstan.neon", "phpstan.paths": { "/home/bobby/redacted/redacted": "/var/www/html/" }, "phpstan.binPath": "${workspaceFolder}",

I'm using WSL and Sail. when I run the command from my terminal it runs fine, but the first line output in the terminal is: Note: Using configuration file /var/www/html/phpstan.neon. which seems to be causing the problem because the extension is expecting only json output.

SanderRonde commented 2 months ago

I think that is due to the config file in the command that is finally ran having two slashes (/var/www/html//phpstan.neon). It then doens't use the provided config file, finds one by itself and prints that. Could be because one of your paths settings ends with a slash and the other doesn't?

Side-note: I think PHPStan shouldn't be logging this in the first place when it's in non-interactive JSON mode but that's more-so something for the PHPStan developer to address.

baschnipke commented 2 months ago

I think that is due to the config file in the command that is finally ran having two slashes (/var/www/html//phpstan.neon). It then doens't use the provided config file, finds one by itself and prints that. Could be because one of your paths settings ends with a slash and the other doesn't?

Side-note: I think PHPStan shouldn't be logging this in the first place when it's in non-interactive JSON mode but that's more-so something for the PHPStan developer to address.

I actually noticed that after I pasted this, I thought I updated it before I submitted the ticket. I resolved that issue by updating the config phpstan.paths and removing the slash after html. My updated configs are:

    "phpstan.binCommand": [
      "docker",
      "exec",
      "--workdir",
      "/var/www/html",
      "-t",
      "redacted-laravel.test-1",
      "bash",
      "-c",
      "vendor/bin/phpstan",
    ],
    "phpstan.paths": {
      "/home/bobby/redacted/redacted": "/var/www/html"
    },
    "phpstan.binPath": "${workspaceFolder}",
    "settingsSync.ignoredExtensions": [
      "sanderronde.phpstan-vscode"
    ],
    "phpstan.enableStatusBar": false,

The new output is:

[8/21/2024, 8:45:58 PM] [server] Language server ready
[8/21/2024, 8:45:58 PM] [server] PHPStan version: Docker version 27.0.3, build 7d4bcd8

[8/21/2024, 8:45:58 PM] [file-watcher] Checking: Initial check
[8/21/2024, 8:45:58 PM] [check:1] Check started for project
[8/21/2024, 8:45:58 PM] [check:1] Spawning PHPStan with the following configuration:  {"binStr":"docker","args":["exec","--workdir","/var/www/html","-t","redacted-laravel.test-1","bash","-c","vendor/bin/phpstan","analyse","-c","/var/www/html/phpstan.neon","--error-format=json","--no-interaction","--memory-limit=1G"]}
[8/21/2024, 8:45:59 PM] [check:1] PHPStan process exited succesfully
undefined:1
Note: Using configuration file /var/www/html/phpstan.neon.
^

SyntaxError: Unexpected token 'N', "Note: Usin"... is not valid JSON
    at JSON.parse (<anonymous>)
    at ChildProcess.<anonymous> (/home/bobby/.vscode-server/extensions/sanderronde.phpstan-vscode-3.1.14/out/server.js:76:1890)

Node.js v20.14.0
[Error - 8:45:59 PM] The PHPStan Language Server server crashed 5 times in the last 3 minutes. The server will not be restarted. See the output for more information.

I'm still tinkering about with it to see if I can figure out if it's a config or something. Will update if I get it figured out.

baschnipke commented 2 months ago

I went into the container and ran vendor/bin/phpunit --no-interaction and still got the message "Note: Using configuration file /var/www/html/phpstan.neon.", so the --no-interaction doesn't seem to affect that.

baschnipke commented 2 months ago

I've got it working with this config:

    "phpstan.binCommand": [
      "docker",
      "exec",
      "--workdir",
      "/var/www/html",
      "-t",
      "nexus-laravel.test-1",
      "/bin/sh",
      "-c",
      "vendor/bin/phpstan -cphpstan.neon analyse --memory-limit=1G --error-format=json"
    ],
    "phpstan.paths": {
      "/home/bobby/intxlog/nexus": "/var/www/html"
    },
    "phpstan.binPath": "${workspaceFolder}",
    "settingsSync.ignoredExtensions": [
      "sanderronde.phpstan-vscode"
    ],
    "phpstan.enableStatusBar": true,
    "phpstan.configFile": "phpstan.neon",

I don't think it's how it's intended to work, but it works. It seems it wasn's picking up the options for some reason.

SanderRonde commented 2 months ago

Side-note: I think PHPStan shouldn't be logging this in the first place when it's in non-interactive JSON mode but that's more-so something for the PHPStan developer to address.

Ah I was maybe unclear with this. I knew that it indeed doesn't do that but I believe that it should do that.

Glad you got it working, I'll make the extension ignore the "Using configuration file" line in the future. That should allow you to go back to a more normal setup as well.