Closed uh-zuh closed 9 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
I've attached it as a zip file.
Where is it?
"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?
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.
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".
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?)
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).
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.
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.
👍
Pre-release version never finishes checking my small project even any small single file. Release verions finishes checking entire project in 5 seconds.
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?
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
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.
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.
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.
I've pushed the fix for the encoding issue to the pre-release version by the way
Now pre-release version works fine: 1) There is no encoding issue. 2) All checks are completed within 5 seconds.
Awesome, I'll close this issue then :)
Problem 1
I have same problem as there: https://github.com/SanderRonde/phpstan-vscode/issues/42
Output in PHPStan log:
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:Environment
OS: Windows 10
vendor
directory is generated inside docker with linux.VSCode settings:
How to configure PHPStan to work normally in my case?