jupyter-lsp / jupyterlab-lsp

Coding assistance for JupyterLab (code navigation + hover suggestions + linters + autocompletion + rename) using Language Server Protocol
https://jupyterlab-lsp.readthedocs.io
BSD 3-Clause "New" or "Revised" License
1.82k stars 148 forks source link

Use yapf fixer #373

Open quantum-booty opened 4 years ago

quantum-booty commented 4 years ago

Is it possible to implement syntax fixers like yapf? It's annoying to see the all the linter warnings and having to fix them one by one.

bollwyvl commented 4 years ago

@quantum-booty thanks for raising this, have been meaning to for a while!

Is it possible to implement syntax fixers like yapf?

It certainly is possible! PRs welcome, but as I said, this is also feature in which I am very interested, and so maybe once we can clear some outstanding stuff, I might be able to take that on.

In the meantime, here's a sketch of how such a PR might be built, with the caveat that I haven't actually landed a whole feature myself, just refactored and reviewed, so maybe @krassowski and @trajamsmith can weigh in on how this agrees with what they did:

dclong commented 3 years ago

Is there completely no YAPF support in jupyterlab-lsp? I understand that there's no easy way to fix formatting in jupyterlab-lsp now. But is there a way to configure jupyterlab-lsp to complain about bad formatted code (using yapf )? I have the following settings but it doesn't make jupyteralb-lsp complain about bad formatted code.

image

bollwyvl commented 3 years ago

It appears it only implements the format provider, not diagnostics:

https://github.com/palantir/python-language-server/blob/91a13687dbd5247374253b245124befb8d9c60c9/pyls/plugins/yapf_format.py

michaelaye commented 2 years ago

I'm confused, why is this issue here and not in python-lsp-server? I thought jupyterlab-lsp is language agnostic?

bollwyvl commented 2 years ago

as described above, the client needs to implement the feature. Making it work for the general case, including notebooks, is non-trivial. PRs welcome!

michaelaye commented 2 years ago

I would, but the whole code formatting story inside jlab has become a completely obfuscated story with too many settings locations, clients-upon-servers, knobs to turn, some formatter's options supported, some not, it's just mayhem, to me anyway, so without understanding anything, I can't even begin to think where to start. For example, python-lsp-server has an internal black and there's a plugin for it also providing black, so plugin needed or not? But there's no yapf support, but jupyterlab-code-formatter supports yapf, however, it doesn't seem to support providing options to yapf. I guess jupyterlab-code-formatter will become obsolete soon, as it's not using the lsp architecture?

bollwyvl commented 2 years ago

yes, the language server spec is complicated. for reference, LSP has approximately 5x the messages of the jupyter kernel spec. this is why it hasn't been implemented on this repo yet.

yes, jupyterlab is also rather complicated, as its trying to serve a lot of different use cases. we've been slowly improving the configuration process upstream, such as with the newer configuration UI: yes, it has warts, but we're trying. and mostly on a volunteer basis.

once the complexity of jupyterlab, codemirror and the formatting LSP have been implemented, once, in this repo it would work "for free" for all the language servers that have implemented formatting. the configuration of those servers would not be free, but at least would be configurable. the configuration is also often very complicated.

as we often try out features first for python, we would likely look at that server you mention first. the one you mention can use yapf internally, but also has a plugin. but has nothing to do with this repo, other than that we would use it in our integration tests.

i am not familiar with other lab extensions + serverextensions that do formatting, but no, presumably they do not implement the LSP formatting spec, and might only support python.

michaelaye commented 2 years ago

I'm only now realizing (please correct me if I'm wrong), that ANY code formatting via LSP is not implemented yet, is that what you meant with it ?:

LSP has approximately 5x the messages of the jupyter kernel spec. this is why it hasn't been implemented on this repo yet.

So, the fact that python-lsp-server (btw, it's a server, but also a client for jupyterlab-lsp?) does support code formatting via yapf, does not apply (yet) to jupyterlab yet, right? (Works, I guess, only in Spyder, for which that lsp-server is being maintained).

So, the only way to currently get code-formatting happening in jlab then is https://github.com/ryantam626/jupyterlab_code_formatter , it seems.

bollwyvl commented 2 years ago

ANY code formatting via LSP is not implemented yet,

that is correct. it would appear as a file/folder under the features.

python-lsp-server (btw, it's a server, but also a client for jupyterlab-lsp?)

yes, it is a Language Server. No, it is not a client. Spyder, VSCode, neovim, and jupyterlab (with jupyterlab-lsp installed) are clients.

does support code formatting via yapf, does not apply (yet) to jupyterlab

yep, because we do not advertise that we support the formatting message, the servers are not sending it.

only way to currently get code-formatting happening in jlab

that could be!