junstyle / vscode-php-cs-fixer

PHP CS Fixer extension for VS Code

Home Page:https://marketplace.visualstudio.com/items?itemName=junstyle.php-cs-fixer

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

PHP CS Fixer: executablePath not found in WSL

kippekont opened this issue · comments

I have installed the PHP CS Fixer plugin in WSL, but it can not find the php-cs-fixer.phar file.
The following rules were added to both my WSL and my Windows sided settings.json:
"php-cs-fixer.lastDownload": 1636825156238,
"php-cs-fixer.executablePath": "${extensionPath}/php-cs-fixer.phar"

The extension is installed here (including the .phar file):
\wsl$\Ubuntu-20.04\home\user.vscode-server\extensions\junstyle.php-cs-fixer-0.2.8

I'm not sure what path ${extensionPath} returns, so I have tried several absolute paths on both the WSL and the windows side, but no luck.
Any help would be appreciated.

menu: help -> developer tool, you can get the args and error infos

Thank you for your reply.

In the console the extension host is returning the following object:
["/home/user/.vscode-server/extensions/junstyle.php-cs-fixer-0.2.8/php-cs-fixer.phar", "fix", "--using-cache=no", "/tmp/web.php", "--rules=@PSR2", "--path-mode=override"]

And the following errors:
PHP CS Fixer: executablePath not found, please check your settings. It will set to built-in php-cs-fixer.phar. Try again!

Error: spawn php ENOENT at Process.ChildProcess._handle.onexit (internal/child_process.js:269:19) at onErrorNT (internal/child_process.js:465:16) at processTicksAndRejections (internal/process/task_queues.js:80:21

The path in the object seems correct, although I'm not sure if it should be prefixed with "wsl$/Ubuntu-20.04/"
Any thoughts?

you should make sure path existing in your os where installed vscode. wsl or window?

@junstyle You should make a program that works, and also a program that doesn't overwrite user-land settings OVER AND OVER AND OVER.

@Sunhat the extension doesn't work in Remote SSH mode with WSL 2. I used the suggestion here: #94 and installed the emeraldwalk run on save extension to simply run php-cs-fixer from the terminal.

For what it's worth, this extension works fine in my WSL2 setup. I'm using an php-cs-fixer.executablePath that points to the workspace itself in vendor/bin, so maybe that helps? Or I installed the extension in the WSL2 system and not the windows portion if working in remote-mode?

My fix was to do the following, within the WSL distro:

  1. Install PHP (I'm using AlmaLinux, so dnf install -y php).
  2. Install php-cs-fixer under /usr/bin. i.e.:
sudo wget https://cs.symfony.com/download/php-cs-fixer-v3.phar -O /usr/bin/php-cs-fixer
sudo chmod a+x /usr/bin/php-cs-fixer
  1. Add the php-cs-fixer.executablePath setting to /home/[username]/.vscode-server/data/Machine/settings.json:
{
    "php-cs-fixer.executablePath": "/usr/bin/php-cs-fixer"
}

Solution:

  1. Install official WSL extension from Microsoft
  2. F1 -> Open Remote Settings (JSON) (WSL: Ubuntu ...)
  3. Add a configuration line for executablePath (Path from WSL)
{
    "php-cs-fixer.executablePath": "/home/any_user/.php/bin/php-cs-fixer",
}

just add
"php-cs-fixer.executablePath": "${workspaceFolder}/tools/php-cs-fixer/vendor/bin/php-cs-fixer.bat",
in your setting json
its will work both on wsl and window separate files