bmewburn / vscode-intelephense

PHP intellisense for Visual Studio Code
https://intelephense.com
Other
1.6k stars 93 forks source link

Formatter config #509

Closed kanlukasz closed 4 years ago

kanlukasz commented 5 years ago

Hello Great addon!

I have question about formatter config

I saw that a year ago you wrote that this is not possible, because the goal of the project is minimal configuration.

Has something changed in this topic? Maybe at least some basic configuration ( brackets, spaces/tabs, etc. ) ?

bmewburn commented 5 years ago

The only config option is tabs/spaces and tab size as they are defined by the language server protocol. I'll leave this open but it's unlikely to happen any time soon if at all. The goal for now is to be ~PSR2~ PSR12 compliant.

muuvmuuv commented 5 years ago

Would love to see a minimal amount of configuration like Prettier has. For example, I prefer single quotes and others double quotes so an option to convert them would be awesome, the same for leading comma's and adding maybe adding semicolons where they are missing.

kanlukasz commented 5 years ago

@muuvmuuv - I'm not sure if I understand you correctly, but what you are asking for, can be problematic (for example replacing quotes in sql queries in php file). Keep in mind that PSR-2 is coding standard and it's not the same as beautifying.


Honestly, after thinking deeply, I understand the author's point of view PSR-2 is PSR-2 - nothing more, nothing less. If we start to add non standard ideas one by one, then it will stop having a logical sense


I think it's good to keep this ticket open for a while (thanks for keep it open). We'll see what other users will publish here and what they think about it.

ericmillsio commented 5 years ago

If the only configuration you add is disabling the Allman braces, I would be a happy man. K&R (1TBS) style is so prevalent across so many codebases I could see a lot of people preferring this disabled. I want strict adoption at my company, but this one is a deal breaker if I want everyone setup to format on autosave.

(I never understood why Allman was adopted with PSR-2/12 in the first place, it's not even consistent with if/for blocks.)

AeonFr commented 5 years ago

It would be nice if Intelephense could detect the user setting for HTML files and preserve that for PHP (PHTML) files.

For example, right now intellephense won't let me add newlines between the attributes of a <div>, and the line length is excessively long. My HTML formatting settings are in force-aligned witch would give me a nice and optimal style:

<div id="example"
     class="isnt-this-more-readable"
     data-answer="yes">
</div>
bmewburn commented 5 years ago

@AeonFr you can put a .jsbeautifyrc file in your project root and it should obey these settings. Here's an example https://gist.github.com/wzup/fc3254562236c1ec3f69

jKuenel commented 5 years ago

The Allman braces are a real issue for me too. I think it's not really about whether they are preferable, but rather about that not being able to change it can be an enormous drawback. In my case, I love the intelephense extension, but if it's breaking the conventions in collaborative projects (so that's why it's not about what someone thinks of Allman braces personally), I won't be able to use it much longer. So I would be very grateful if there was any way...

muuvmuuv commented 5 years ago

In my case the .jsbeautifyrc is not working. Put the example in the root but get no results from what I have configured in the config (set indent to 5 for a test). Got this someone to work and could please post his setup somewhere?

d8vjork commented 5 years ago

The only config option is tabs/spaces and tab size as they are defined by the language server protocol. I'll leave this open but it's unlikely to happen any time soon if at all. The goal for now is to be ~PSR2~ PSR12 compliant.

And for that we already have https://editorconfig.org/ (with its extension on VS Code)

Will be great to have PSR12 on php-cs-fixer so then that could be integrated

d8vjork commented 5 years ago

@muuvmuuv Did you try setting up the Document Root option on the extension settings? I mean, this one: "intelephense.environment.documentRoot": ""

muuvmuuv commented 5 years ago

@d8vjork so this should point to my current workspace? Why do I need to set this?

d8vjork commented 5 years ago

@muuvmuuv Just thinking maybe that's why the extension doesn't detect the workspace root for check the .jsbeautifyrc file

willstocks commented 5 years ago

The only config option is tabs/spaces and tab size as they are defined by the language server protocol.

How do I define whether I want tabs or spaces via intelephpsense formatting?

KapitanOczywisty commented 5 years ago

How do I define whether I want tabs or spaces via intelephpsense formatting?

Intelephense uses editor.tabSize and editor.insertSpaces settings.

{
    "[php]": {
        // tab or space size
        "editor.tabSize": 4,
        // use spaces or tabs
        "editor.insertSpaces": true,
        // false to force above for existing files
        "editor.detectIndentation": false
    },
}
willstocks commented 5 years ago

Aha! This was all I needed:

"[php]": {
    "editor.detectIndentation": false
  },

My editor.tabSize and editor.insertSpaces was already set to true globally

Thanks @KapitanOczywisty 😄

d8vjork commented 4 years ago

@fakhamatia I think Beautify is the one used by Intelephense (correct me if I'm wrong)

kanlukasz commented 4 years ago

Hi guys, with all due respect, but this is a ticket for one specific issue. Respect the addon author and stop making a mess which makes it difficult for him to keep issues If you have another question, you can use stackoverflow every day, you can, really just try it Eventually please create another issue

bmewburn commented 4 years ago

Opened #729 to offer a choice of html formatter.

Braces seems to be one of the main issues with the php formatter. I'd rather not have a config option for braces usage in every possible context. I opened #730 with a proposal for this.

kanlukasz commented 4 years ago

Due to the opening of two separate tickets by @bmewburn (formatter and brackets), I close this ticket (everything in this topic has been said)