SanderRonde / phpstan-vscode

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

Output errors are garbled 2 and phpstan not executable #49

Closed uh-zuh closed 9 months ago

uh-zuh commented 10 months ago

Problem 1

I have same problem as there: https://github.com/SanderRonde/phpstan-vscode/issues/42

Output in PHPStan log:

[check:1] PHPStan process exited with error  filteredErr="d:\Projects\MyProject\git\build-composer\vendor\bin\phpstan" �� ���� ����७��� ��� ���譥�
��������, �ᯮ��塞�� �ணࠬ��� ��� ������ 䠩���.  rawErr="d:\Projects\MyProject\git\build-composer\vendor\bin\phpstan" �� ���� ����७��� ��� ���譥�
��������, �ᯮ��塞�� �ணࠬ��� ��� ������ 䠩���.

When I run command from terminal it tells me in Russian (because my Windows language is Russian) that ....\phpstan in not executeable.

This output in logs:

�� ���� ����७��� ��� ���譥�
��������, �ᯮ��塞�� �ணࠬ��� ��� ������ 䠩���.

is very similar to output in terminal:

не является внутренней или внешней
командой, исполняемой программой или пакетным файлом.

and it means that file is not executable.

I think encoding becomes broken somewhere inside your extension.

Problem 2

This is related problem. I can create new issue for this if needed.

When I add php to ....\phpstan, it outputs some errors in my code and it seems to work normal:

php d:\Projects\MyProject\git\build-composer\vendor\bin\phpstan analyse -c d:\Projects\MyProject\git\config\phpstan.neon

Environment

OS: Windows 10 vendor directory is generated inside docker with linux.

VSCode settings:

    "settings": {
        "phpstan.configFile": "config/phpstan.neon",
        "phpstan.binPath": "build-composer/vendor/bin/phpstan"
    }

How to configure PHPStan to work normally in my case?

SanderRonde commented 10 months ago

I'm not really sure how to fix the encoding issue. It appears that your process is spawned with non-utf8 encoding and I'm not actually sure how to detect that. I've made a version that (I think) forces a specific encoding so maybe that works. Can you give that a try? I've attached it as a zip file. Just rename it to .vsix (github doesn't allow attaching .vsix files) and install it in VSCode. Thanks!

Regarding the second issue, it appears that you've generated the vendor directory using linux but you're running it from windows. That won't work so things break. You'll either have to install it in windows and run it from windows or actually run the command through docker. Just change the phpstan.binCommand setting to instead run docker's version of PHPStan and use the phpstan.paths command to map it back to your original file system. (See the readme). This may also be causing the encoding issue but I'm not entirely sure.

Alternatively run VSCode inside the docker container, then you won't need to do all this work

uh-zuh commented 10 months ago

I've attached it as a zip file.

Where is it?

uh-zuh commented 10 months ago
"phpstan.configFile": "config\\phpstan.neon",
"phpstan.binCommand": ["php", "build-composer\\vendor\\bin\\phpstan"],
"phpstan.timeout": 20000

This has fixed my second issue without any additional manipulations with docker. It may be useful to add this case to README.

Timeout of 10000 ms is not enought for one of my source files which is 1150 lines of code - is it normal?

SanderRonde commented 10 months ago

Whoops my bad, I've really attached it this time. If this doesn't work maybe try checking whether the pre-release version of the extension works.

Will look into adding your fix to the README, thanks!

10000ms could indeed not be enough, it kind of depends on your project setup and on what device you run it. I've bumped the timeout to 60s in the latest (pre-release) version of the extension.

phpstan-vscode-2.2.26.zip

uh-zuh commented 10 months ago

Attaced extension doesn't fix encoding issue. Pre-release version runs phpstan without errors but failed with 5 minutes timeout: "PHPStan check timed out after 300000ms".

SanderRonde commented 10 months ago

Ah sucks that the encoding issue wasn't fixed... I'm kind of unsure how to fix this. Detecting encoding from input seems to be a really hard problem, especially when the input size is small.

How long does PHPStan normally run on the commandline when scanning the whole project? You could always increase the timeout (I think it even prompts you to do that doesn't it?)

uh-zuh commented 10 months ago

About encoding - https://copyprogramming.com/howto/node-jss-spawn-exec-options-and-encoding - is it helpful?

Normally it takes 5 seconds that much less than 5 minutes :)

One more thing - pre-release version ignores phpstan.timeout option. I have set it 30000 (30 seconds).

SanderRonde commented 10 months ago

The initial version I sent you tried solution 1 in your link but it looks like that didn't work. I've attached another version where I tried approach 2. Let's see if that works :)

I think normally PHPStan is so fast because it's normally cached. The first time it won't be cached so it's slow.

It indeed ignores phpstan.timeout, since it now does project-wide checks it's using the phpstan.projectTimeout setting. The timeout setting only applies to single files so it'll be too low anyways.

phpstan-vscode-2.2.26.zip

uh-zuh commented 9 months ago

This version fixes encoding issue, now it is in English:

[check:2] PHPStan process exited with error  filteredErr='d:\Projects\MyProject\git\build-composer\vendor\bin\phpstan' is not recognized as an internal or external command,
operable program or batch file.  rawErr='d:\Projects\MyProject\git\build-composer\vendor\bin\phpstan' is not recognized as an internal or external command,
operable program or batch file.

👍

uh-zuh commented 9 months ago

Pre-release version never finishes checking my small project even any small single file. Release verions finishes checking entire project in 5 seconds.

SanderRonde commented 9 months ago

Good to hear this fixes the encoding issue. I would find it really strange if the pre-release version never finishes checking. How long does a full-project check from the commandline take after you've deleted your cache for PHPStan?

uh-zuh commented 9 months ago

5 seconds:

>php build-composer\\vendor\\bin\\phpstan clear-result-cache
Result cache cleared from directory:
C:\Users\Egor\AppData\Local\Temp/phpstan

>php build-composer\vendor\bin\phpstan analyse -v -c config\phpstan.neon      
 40/40 [============================] 100% 5 secs

 [OK] No errors

Used memory: 118 MB
SanderRonde commented 9 months ago

Hmm strange. Could you look at the logs outputted from PHPStan and run that by itself in the terminal? I wonder what happens then. That should include the special PHPStan-vscode .neon and autoload file, which might both change things.

uh-zuh commented 9 months ago

PHPStan Client output:

[client] Starting extension with configuration: {
    "binPath": "vendor/bin/phpstan",
    "binCommand": [
        "php",
        "build-composer\\vendor\\bin\\phpstan"
    ],
    "configFile": "config\\phpstan.neon",
    "rootDir": "",
    "options": [],
    "enableStatusBar": true,
    "memoryLimit": "1G",
    "enabled": true,
    "projectTimeout": 300000,
    "suppressTimeoutMessage": false,
    "paths": {},
    "showProgress": false,
    "enableLanguageServer": true,
    "ignoreErrors": [],
    "suppressWorkspaceMessage": false,
    "pro": false,
    "proTmpDir": ""
}
[client] Initializing done
[client] Showing one-time messages (if needed)
[server] Language server ready
[server] Language server started
[server] PHPStan version: PHP 8.2.14 (cli) (built: Dec 20 2023 10:20:01) (ZTS Visual C++ 2019 x64)
Copyright (c) The PHP Group
Zend Engine v4.2.14, Copyright (c) Zend Technologies

[check:1] Check started for project
[status-bar] Showing status bar

PHPStan Laguage Server output:

[server] Language server ready
[server] PHPStan version: PHP 8.2.14 (cli) (built: Dec 20 2023 10:20:01) (ZTS Visual C++ 2019 x64)
Copyright (c) The PHP Group
Zend Engine v4.2.14, Copyright (c) Zend Technologies

[check:1] Check started for project

There is no full command in output that I can run manually in the terminal. And thers is no information about PHPStan-vscode .neon and autoload files.

From the Process Monitor I have found that there is only one command php --version has beed executed. No phpstan has been run at all.

I use PHP 8.2.14.

SanderRonde commented 9 months ago

Strange, looks like the check isn't even being started in the first place. Anything interesting in the developer tools? (Help -> Toggle developer tools) Also is this using the release version, the pre-release version or the version I sent you? You mentioned that the version I sent you fixed the encoding issues but that the pre-release version never starts. Those are the same version though (with just the encoding changes) so that would be strange.

SanderRonde commented 9 months ago

I've pushed the fix for the encoding issue to the pre-release version by the way

uh-zuh commented 9 months ago

Now pre-release version works fine: 1) There is no encoding issue. 2) All checks are completed within 5 seconds.

SanderRonde commented 9 months ago

Awesome, I'll close this issue then :)