sublimelsp / LSP-pylsp

Convenience package for the Python Language Server

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

When formatting, the list will become vertical

thep0y opened this issue · comments

It doesn’t matter what formatter I use. I didn’t have this problem when I used pyls before.

settings:

"pylsp": {
            "selector": "source.python",
            "settings": {
                "plugins": {
                    "yapf.enabled": true,
                    "autopep8.enabled": false
                }
            }
        }

yapf config:

[style]
based_on_style = pep8
column_limit = 248

dynamic image:
apngb-animated

yapf is not working?

The structure of the configuration you've posted is not valid.

Look at the default configuration file in Preferences: LSP-pylsp Settings and use the same structure for your overrides.

BTW. Don't create configuration in LSP.sublime-settings if you are using this package. This package has its own configuration that I've referenced in the previous comment.

Thanks for your reply, now the configuration I use:

// Settings in here override those in "LSP-pylsp/LSP-pylsp.sublime-settings"
{
    "settings": {
        "pylsp.plugins.autopep8.enabled": false,
        "pylsp.plugins.yapf.enabled": true,
    }
}

But did not solve the issue.

You should try directly with yapf formatter to see if the issue is in this server or with your configuration itself. If it works the same with yapf directly then that would indicate that the yapf config might be wrong.

You should try directly with yapf formatter to see if the issue is in this server or with your configuration itself. If it works the same with yapf directly then that would indicate that the yapf config might be wrong.

There is no such issue when formatting the same code directly with yapf:
2021-06-01 21 05 07

So how does your project structure look like exactly and what's the configuration file name?

Here is how I've tried it and it appears that the configuration is not picked up even when running yapf manually:

Screenshot 2021-06-01 at 15 18 37

So how does your project structure look like exactly and what's the configuration file name?

The test code is in a script file whose name is test.py, so the configuration used by the project is the global configuration:

// Settings in here override those in "LSP-pylsp/LSP-pylsp.sublime-settings"
{
    "settings": {
        "pylsp.plugins.autopep8.enabled": false,
        "pylsp.plugins.yapf.enabled": true,
    }
}

The yapf configuration file path is $HOME/.config/yapf/style, and its content is:

[style]
based_on_style = pep8
column_limit = 248

When I use yapf to format the code manually, it will pick up the configuration. The following is an animation demonstration:
output

I think lsp-pylsp has some problems when calling yapf.

Well, for me yapf formats it into a column, like in my screenshot. So until we figure that out, I won't be able to look into the possible issue with this server.

Actually, my bad. I had trailing comma in the list so that forced it into a column regardless of the length.

Actually, my bad. I had trailing comma in the list so that forced it into a column regardless of the length.

So, do you think it might be the issue of lsp-pylsp?

The naming of the black formatter configuration key was wrong so it was enabled and always used instead of yapf. Fix in #30