python-language-server icon indicating copy to clipboard operation
python-language-server copied to clipboard

Code formatting configuration

Open ambv opened this issue 7 years ago • 12 comments

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.

ambv avatar Apr 04 '18 22:04 ambv

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

gatesn avatar Apr 16 '18 22:04 gatesn

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

ambv avatar Apr 16 '18 23:04 ambv

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)

gatesn avatar Apr 17 '18 01:04 gatesn

I'll submit a PR soon :-)

ambv avatar Apr 17 '18 01:04 ambv

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

vlcinsky avatar Jun 14 '18 20:06 vlcinsky

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

auscompgeek avatar Jun 18 '18 08:06 auscompgeek

@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.

vlcinsky avatar Jun 18 '18 21:06 vlcinsky

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

laixintao avatar Jan 31 '19 06:01 laixintao

Up

marioidival avatar Oct 06 '20 13:10 marioidival

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.

ccordoba12 avatar Oct 06 '20 14:10 ccordoba12

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

marioidival avatar Oct 06 '20 14:10 marioidival

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

ccordoba12 avatar Oct 06 '20 15:10 ccordoba12