-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
pylsp black/isort formatting does not work #903
Comments
Upstream issue: rupert/pyls-black#35 |
Oh, crap, I didn't see that (and it is very unfortunate). Thanks for the info! |
@carrascomj Try python-lsp-black, which is a fork of pyls-black that is compatible with python-lsp-server. Just uninstall pyls-black and install the new one and it should work. There is also a new release of pyls-isort that is compatible with python-lsp-server, so you should just need to upgrade it. |
@haplo That's awesome, thank you very much! I tried and it works perfectly. It seems like it is the best LSP python server for neovim right now. |
I personally find pyright significantly more performant FWIW |
pyright was very good, but I could not get go-to-definition or formatting to work (I don't remember which one), but I might give it a try again. |
Pyright doesn't have formatting. You have to use something like diagnostic-languageserver or efm-langserver for that. Which I think is a more flexible solution anyway. require("lspconfig").diagnosticls.setup {
filetypes = {"python"},
init_options = {
formatters = {
black = {
command = "black",
args = {"--quiet", "-"},
rootPatterns = {"pyproject.toml"},
},
formatFiletypes = {
python = {"black"}
}
}
}
} |
kindly link to the diagnostic-languageserver config by @lithammer for future readers reference. |
Note that I'm not very good at keeping that repo up-to-date. It might not even work with recent Neovim 0.6-0.7 changes. |
nvim --version
: v0.5.0-dev+1282-gfbe18d9caHow to reproduce the problem from neovim startup
Add this and load it in your config:
Then open a python file and, in command mode (
:
), runActual behaviour
No formatting occurs, sometimes this error is produced:
Apart from that, flake8 is not repecting my
setup.cfg
and returns the warnings from the default parameters.Expected behaviour
With
pyls-black
installed, I would expect to run black onvim.lsp.buf.formatting()
, but that's not the case. I guess that this is not implemented for pylsp and it may be hard since it is using its own plugins to handle formatting.The same holds for
pyls-isort
.Minimal init.vim or init.lua and code sample
Health check
Checkhealth result
health#lspconfig#check
Checking language server protocol configuration
LSP log
Log file
[ START ] 2021-05-13T12:57:08+0200 ] LSP logging initiated [ INFO ] 2021-05-13T12:57:14+0200 ] /usr/share/nvim/runtime/lua/vim/lsp/rpc.lua:311 ] "Starting RPC client" { args = {}, cmd = "pylsp", extra = {}} [ DEBUG ] 2021-05-13T12:57:14+0200 ] /usr/share/nvim/runtime/lua/vim/lsp.lua:819 ] "LSP[pylsp]" "initialize_params" { capabilities = { callHierarchy = { dynamicRegistration = false, = <1>{ __tostring = } }, textDocument = { codeAction = { codeActionLiteralSupport = { codeActionKind = { valueSet = { "", "Empty", "QuickFix", "Refactor", "RefactorExtract", "RefactorInline", "RefactorRewrite", "Source", "SourceOrganizeImports", "quickfix", "refactor", "refactor.extract", "refactor.inline", "refactor.rewrite", "source", "source.organizeImports" }, = }, =The text was updated successfully, but these errors were encountered: