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

Code formatting configuration #328

Open
ambv opened this issue Apr 4, 2018 · 12 comments
Open

Code formatting configuration #328

ambv opened this issue Apr 4, 2018 · 12 comments

Comments

@ambv
Copy link

ambv commented Apr 4, 2018

Hi! Thanks for pyls, it's great.

Historically, YAPF was the preferred formatter in pyls. This recently changed with #315 without a rationale provided (in fact the README still states the opposite). There's a few problems with this.

  1. I don't think defaulting to autopep8 is a great choice. YAPF's README provides a good explanation as to why.

  2. It seems to me like the only option to configure an alternative formatter is to uninstall YAPF and/or autopep8 from the virtualenv?

It would be great if there was a way for people to configure which one they want, ideally on a per-project basis.

@gatesn
Copy link
Contributor

gatesn commented Apr 16, 2018

Yup, seems like YAPF might be a better default. Happy to revert the PR?

@ambv
Copy link
Author

ambv commented Apr 16, 2018

Reverting the PR would be a good start but I'd love some configurability here. I do also have a horse in this race.

@gatesn
Copy link
Contributor

gatesn commented Apr 17, 2018

So configuration can be passed by the client to the sever to disable/enable specific plugins. I’d prefer the client to handle this if possible.

However it may make sense to try to enable/disable based on the presence of a yapf config file.

It would be great if you could provide a plugin for that formatter by the way! Would be happy to take a PR or to help review a separate plugin (see pyls mypy)

@ambv
Copy link
Author

ambv commented Apr 17, 2018

I'll submit a PR soon :-)

@vlcinsky
Copy link

@ambv How is your (black) horse pulling the request? Any chance to see that majestic creature in this stable?

@auscompgeek
Copy link

@vlcinsky Looks like someone else has already written a plugin: https://github.com/rupert/pyls-black

@vlcinsky
Copy link

vlcinsky commented Jun 18, 2018

@auscompgeek thanks for great reference. It is very fresh. My first test does not seem work, but I will retry after few more pyls-black commits.

@laixintao
Copy link

@ambv Any progress on configuration for code formatting than using a plugin?

@marioidival
Copy link

Up

@ccordoba12
Copy link
Contributor

ccordoba12 commented Oct 6, 2020

You need to enable or disable those plugins in order to leave a single formatter enabled at a time. That's how you can handle several formatters without installing/uninstalling them.

@marioidival
Copy link

@ccordoba12 How I can do that? I wan't use black

@ccordoba12
Copy link
Contributor

You need to install the pyls-black plugin mentioned above, then configure your client to tell the server that autopep8 and yapf are disabled and that plugin is enabled.

I can't give you more details because each client handles configuration in different ways, but it's usually done in through a json file, like this one:

https://github.com/palantir/python-language-server/blob/develop/vscode-client/package.json

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

Successfully merging a pull request may close this issue.

7 participants