pappasam / jedi-language-server

A Python language server exclusively for Jedi. If Jedi supports it well, this language server should too.
MIT License
597 stars 45 forks source link

Extensibility / integration with other tools #32

Closed fsouza closed 3 years ago

fsouza commented 4 years ago

Hi there! This projects looks very exciting. I've opened a PR in nvim-lsp to add it there: https://github.com/neovim/nvim-lsp/pull/284

I know the name is explicit about this being a jedi language server, but would it make sense to integrate other tools to support operations that can't be provided by jedi (two examples that come to mind is diagnostics with mypy and code formatting with black) or maybe use something like pluggy to support adhoc extensions?

One can always run more than one language server, but it'd be good to be able to run just one 😁

pappasam commented 4 years ago

Awesome, thanks for submitting this to nvim-lsp!

In general, I'm trying to minimize external dependencies for this language server so I can best support (and keep supporting) Jedi's latest features without getting distracted by churn from other projects. It wouldn't be too hard to add plugin support at this time, but I'd rather not deal with the maintenance headache going forward (got really annoyed at the development speed / code complexity on other Python language servers, which is why I wrote this one). I'm fairly certain that most other Python language servers are powered by Jedi, but support other tools (like black / flake8) as well. Because of this, I think this language server's jedi "purity" is its distinguishing feature.

That said, if Jedi supports it, I'm happy to support it here! If @davidhalter wants to support code formatting / type-checked linting, I'm happy to add the features to this language server.

Note: from a selfish perspective, I don't use language servers for code formatting. I have another Vim plugin that I prefer for that: https://github.com/pappasam/vim-filetype-formatter . If I need additional diagnostics not provided by a particular language server, I use this with whichever linter(s) I want: https://github.com/iamcco/diagnostic-languageserver

davidhalter commented 4 years ago

That said, if Jedi supports it, I'm happy to support it here! If @davidhalter wants to support code formatting / type-checked linting, I'm happy to add the features to this language server.

No. Haha :)

(I even tried that once, but got annoyed by all the details. Then again I also don't think that linting is that important, so I dropped it. The code is still here: https://github.com/davidhalter/parso/blob/master/parso/python/pep8.py. It's essentially a replacement for pycodestyle. However I stopped when I realized how annoying it is to reformat to a maximum line length. This is just a very hard problem and if you don't invest enough time, you will not get a good solution.)

caheredia commented 3 years ago

Came here to ask about this. It would be nice to run this command in Neovim with this language server lua vim.lsp.buf.formatting()

pappasam commented 3 years ago

@caheredia to me, formatting is one of those special-case topics that I don't think is solved well by language-specific LSP servers. For example, here's my current Python formatting pipeline using https://github.com/pappasam/vim-filetype-formatter:

let g:vim_filetype_formatter_commands = {
      \ 'python': 'black -q - | isort -q - | docformatter -',
      \ }

Notice how I pipe black to isort to docformatter in my own user-defined manner? A generalized, cross-platform version of this is hard to implement and probably not worth it for jedi-language-server. If you want formatting with LSP, consider this language server in addition to jedi-language-server: https://github.com/iamcco/diagnostic-languageserver. It supports BOTH diagnostics AND formatting in a general sense.

Alternatively, consider https://github.com/pappasam/vim-filetype-formatter. Since I'm its maintainer, I'd be happy to help you get set up with vim-filetype-formatter.

caheredia commented 3 years ago

@pappasam Thanks! Your example is exactly what I needed, I use black, isort, and mypy in my projects.

pappasam commented 3 years ago

Closing this issue because I think we've reached a collective understanding that jedi-language-server's scope is constrained to jedi.