Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Respect identation settings when doing Format Document #93

Closed
dotnetCarpenter opened this issue Mar 16, 2017 · 15 comments
Closed

Comments

@dotnetCarpenter
Copy link

When I do Format Document the tab size is always 4 even though I've set "editor.tabSize": 2.

Also it appears that I can not format only the selected text but have to format the entire document.
See the screen shot:

vscode-php-intellisense

@Midwain
Copy link

Midwain commented Mar 29, 2017

How i can format file with tabs?

@felixfbecker
Copy link
Owner

Formatting is done by PHP CodeSniffer, please refer to its documentation for configuring it.

@dotnetCarpenter
Copy link
Author

@felixfbecker I failed to see how configuring PHP CodeSniffer to use vscode configuration can/should be done outside this vscode plugin.

I'm reading the PHP CodeSniffer tab documentation but can't see how I can influence phpcs inside vscode.

Please advise.

@felixfbecker
Copy link
Owner

@dotnetCarpenter
Copy link
Author

As I see it, vscode-php-intellisense needs a patch to forward vscode settings to php-language-server.

Unfortunately, I don't have time to implement this. But 🥇 to who-ever who do it! :)

@felixfbecker
Copy link
Owner

um, no. As said, you can use an XML file already, which can be read by more than just VS Code. If any patch is required, it would be needed in the language server.

@dotnetCarpenter
Copy link
Author

dotnetCarpenter commented Apr 7, 2017

I don't get it. Why would I want to maintain a separate xml file, with the same settings as in vscode for php-language-server?

If I want to change my vscode settings in one project, I would expect the php intellisense to honor my settings.

In vscode:

// Place your settings in this file to overwrite the default settings
{
    // The number of spaces a tab is equal to.
    "editor.tabSize": 2,

    // Insert spaces when pressing Tab.
    "editor.insertSpaces": true
}

Don't know the file location of user/workspace settings

Somewhere in my project (don't know the location for php-language-server xml config in my project):

<?xml version="1.0"?>
<ruleset name="PHP Language Server">
    <file>src</file>
    <file>tests</file>
    <rule ref="PSR2">
        <exclude name="PSR2.Namespaces.UseDeclaration.MultipleDeclarations"/>
        <exclude name="PSR2.ControlStructures.ElseIfDeclaration.NotAllowed"/>
        <exclude name="PSR2.ControlStructures.ControlStructureSpacing.SpacingAfterOpenBrace"/>
    </rule>
</ruleset>

How do I set --config-set tab_width 2 for phpcs

@dotnetCarpenter
Copy link
Author

There is a need for vscode-php-intellisense to forward vscode settings to php-language-server.

@felixfbecker
Copy link
Owner

Why? Because the vscode settings are only read by vscode. On a serious project you will likely have CI where you want to run linting. CodeSniffer can read your XML file then too, when running as a command in CI.

"Forwarding" the vscode settings to the language server is not the complicated part, that is already done through didChangeConfiguration. The language server would need to interpret them, which I am reluctant to do, because they are in a vscode-specific schema and the language server can run in all kinds of clients.

@dotnetCarpenter
Copy link
Author

I understand your hesitation to cater for vscode in php-language-server, but couldn't vscode-php-intellisense transform the JSON settings to the XML format php-language-server understand?

I'm afraid I can't find how didChangeConfiguration is utilized in this repository: https://github.com/felixfbecker/vscode-php-intellisense/search?utf8=%E2%9C%93&q=didChangeConfiguration&type=

@felixfbecker
Copy link
Owner

Are you proposing the vscode extension should write an XML file into your workspace?

@dotnetCarpenter
Copy link
Author

I would have to understand how vscode-php-intellisense can communicate to php-language-server and if the didChangeConfiguration event is fired at a time where php-language-server can either be re-started or made to read configuration files. Before I can make such propositions.

All I'm saying is that, settings in vscode should be honored by php-language-server, so that I as a vscode user, only need to make my project (user/workspace) configurations in one place - which seems to naturally be in vscode. Regardless of where vscode and php-language-server stores its configuration files.

I'm sorry but I lack deep understanding of both vscode-php-intellisense and php-language-server to propose an implementation. I'm only making a feature request and I'm still bewildered about how I would even set this up manually.

@felixfbecker
Copy link
Owner

What is the problem with creating a CodeSniffer XML config file in your workspace? Your vscode config will not be read by anything but vscode, so it clearly is not the suitable location for "only needing to make my project (user/workspace) configurations in one place"

@dotnetCarpenter
Copy link
Author

Maybe I'm misunderstanding the use-case for vscode-php-intellisense.

I thought it was only to facilitate PHP development in vscode.

Why should I have to understand CodeSniffer XML configuration in order to use vscode-php-intellisense? Anyway, it was only a request. Feel free to ignore it. I'll just stay away from the code formatting feature.

@MartinMa
Copy link

How exactly has a phpcs.xml to look like to enforce an indentation of 2 spaces (for example)?

I tried adding <arg name="tab-width" value="2"/> to the to phpcs.xml.dist and copying the file to the root of my workspace.

Like this:

<?xml version="1.0"?>
<ruleset name="PHP Language Server Custom">
  <arg name="tab-width" value="2"/>
  <file>src</file>
  <file>tests</file>
  <exclude-pattern>tests/Validation/cases</exclude-pattern>
  <rule ref="PSR2">
    <exclude name="PSR2.Namespaces.UseDeclaration.MultipleDeclarations"/>
    <exclude name="PSR2.ControlStructures.ElseIfDeclaration.NotAllowed"/>
    <exclude name="PSR2.ControlStructures.ControlStructureSpacing.SpacingAfterOpenBrace"/>
    <exclude name="Squiz.WhiteSpace.ControlStructureSpacing.SpacingBeforeClose"/>
    <exclude name="Squiz.WhiteSpace.ControlStructureSpacing.SpacingAfterOpen"/>
  </rule>
</ruleset>

It seems to be loaded. But it still uses 4 spaces for indentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants