vscode-php-cs-fixer icon indicating copy to clipboard operation
vscode-php-cs-fixer copied to clipboard

PHP CS Fixer: executablePath not found in WSL

Open kippekont opened this issue 4 years ago • 10 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.

kippekont avatar Nov 13 '21 17:11 kippekont

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

junstyle avatar Nov 13 '21 23:11 junstyle

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?

kippekont avatar Nov 15 '21 14:11 kippekont

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

junstyle avatar Nov 16 '21 01:11 junstyle

@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 avatar Mar 09 '22 12:03 Sunhat

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

ronfuller avatar Mar 17 '22 11:03 ronfuller

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?

jorismak avatar Apr 27 '22 13:04 jorismak

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"
}

robpomeroy avatar Aug 02 '22 11:08 robpomeroy

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",
}

akmandev avatar Nov 02 '22 21:11 akmandev

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

lechuhuuha avatar Jan 29 '24 07:01 lechuhuuha