Open quantum-booty opened 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:
spoiler: nope
I would think formatting could be a single file, unless it has a lot of complicated options
Ctrl+Shift+I according to my muscle memory, but that triggers the browser inspector (in Chrome and FF), and we shouldn't be That Extension
on the project we use
black
, so might prefer apyls-black
example, butyapf
is fine, too, as it's already a dependency ofpyls
(as packaged by conda-forge)
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.
It appears it only implements the format provider, not diagnostics:
I'm confused, why is this issue here and not in python-lsp-server? I thought jupyterlab-lsp
is language agnostic?
as described above, the client needs to implement the feature. Making it work for the general case, including notebooks, is non-trivial. PRs welcome!
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?
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.
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.
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!
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.