vysker / vscode-php-formatter

Visual Studio Code extension. A wrapper for the Sensiolabs PHP CS Fixer. Analyzes some PHP source code and tries to fix coding standards issues (PSR-1 and PSR-2 compatible).
MIT License
93 stars 11 forks source link

This is a real bitch to install #22

Open perholmes opened 7 years ago

perholmes commented 7 years ago

I thought I was pretty competent, but I've spent an hour now. The command "phpformatter.fix" can't be run from the VS Code command line. The settings register, so VS Code must somehow be aware of PHP Formatter. The .phar archive is super duper in the right place, mapped in the settings, PHP is globally accessible. The keyboard bindings are pasted into the right file, but the shortcuts don't work. The documentation doesn't seem to discuss any of this.

It seems I have to go back to some external PHP formatter and copy/paste entire files in and out. I'm utterly lost with this plugin, nothing works, and I've done about 20 sanity checks now, I'm following every instruction to the letter. Is it this hard for anyone else?

perholmes commented 7 years ago

OK, it seems to actually be installed, there's just so little feedback anywhere that I didn't realize it. I now enabled logging, and I can see it's running. Now I just need to find out why it's not touching the files. Is my existing formatting really that good? Anyway, seems to be working.

meyer commented 7 years ago

@perholmes you’re not alone.

Tommixoft commented 7 years ago

this plugin is piece of shit doesnt work even if you install everything and use older version.

meyer commented 7 years ago

@Tommixoft fork it and improve it.

Tommixoft commented 7 years ago

it have to be fixed, cause its not working, improvements should be done when item works. I see no reason keeping non working stuff in git :) It would be great if it would work, and thanks for your tie, but the fatc is fact-it doesnt work.

martic commented 7 years ago

There where 3 things that got it working for me.

The default phpformatter.arguments is incorrect set to empty in settings.json. "phpformatter.arguments": [], I can see there is a pull request in for it.

Also for me when I installed php-cs-fixer via composer. There is no php-cs-fixer.par file, just php-cs-fix. So I use: "phpformatter.pharPath": "%APPDATA%\Composer\vendor\friendsofphp\php-cs-fixer\php-cs-fixer",

And the phpformatter.logging shows in the ">Developer: Toggle Developer Tools" not debug console.

AlbinoDrought commented 7 years ago

Here are the couple issues I experienced, in case anyone else has similar troubles:

  1. PHPFormatter: Could not open input file:: I was using my homepath, ~, in the pharPath. I replaced this with the full path, and this error went away.

  2. The "--level" option does not exist.: Changed arguments to ["--rules=@PSR2"]

Everything works great now, thanks!

peterbabic commented 7 years ago

In addition to aforementioned changes to --level, I also needed to get rid of php in php php-cs-fixer fix command, since it is now a standalone file and not a .phar one. My solution was "phpformatter.phpPath": "nohup". The resulting command in colsole now looks like this and works: "nohup" "php-cs-fixer" fix "/tmp/phpfmt-17064pZjqlYL7HmPF.tmp".

Hope this helps someone.

AndyYuenOk commented 7 years ago

this title, i like... u're not alone

Sarav-S commented 7 years ago

Finally got it working.

Steps

  1. Goto https://github.com/FriendsOfPHP/PHP-CS-Fixer#installation and download the phar file
  2. Place it on your computer somewhere. I placed it on (/Users/Sarav/php-cs-fixer-v2.phar)
  3. Open your vs code and goto settings.json
  4. Add the following lines
    "phpformatter.arguments": [],
    "phpformatter.pharPath" : "/Users/Sarav/php-cs-fixer-v2.phar"

    Thats it! Now your code will get formatted.

Cheers!

fofosud commented 7 years ago

@Sarav-S Thank you so much, I was so stressed for hours! looking for the solution in many sites, but finally your solution worked for me! :D

Sarav-S commented 7 years ago

@fofosud Glad I could help :)

jikkujose commented 7 years ago

This is the reason this language is seriously fucked up! Something so straight forward like a formatter is stalling me for the whole day! I was trying to tweak something done by another developer, the code looks like shit paste! This is so painful!

dean-me commented 7 years ago

For me the fix was "phpformatter.arguments": [] inside settings.json There must be some bug in the settings

hubertursua commented 6 years ago

Installed via homebrew. Here are the options I added in settings.json for those with a similar env.

{
    "phpformatter.composer": false,
    "phpformatter.pharPath": "/usr/local/bin/php-cs-fixer",
    "phpformatter.phpPath": "/usr/local/bin/php",
    "phpformatter.arguments": [],
}

The phpformatter.arguments option is an undocumented fix (as mentioned above, thanks @dean-me).

bernhardriegler commented 6 years ago

@Sarav-S you are a real hero - thank you!

cwhsu1984 commented 6 years ago

@Sarav-S good job! "phpformatter.arguments": [] MUST BE DOCUMENTED AS A MUST.

It's ridiculous for someone who have been coding for years to spend half hour setting up configs only to find that the reason a plugin cannot work is because one setting that is not even needed is mandatory

sgehrman commented 5 years ago

"phpformatter.arguments": [] MUST BE DOCUMENTED AS A MUST. Still not documented, I spent hours trying to get this working.

IlanVivanco commented 5 years ago

"phpformatter.arguments": [] did the trick 😢