pylsp
wasn’t working today for some reason. It wasn’t jumping to definitions,
offering any auto-completions, nor formatting code. I had to figure out why.
Usually, LSPs are executed directly by the IDE with stdin/stdout piped directly into an LSP client, which means that logging to stdout/stderr is not as simple as usual.
Running the LSP manually on a TCP port makes following logs nice and simple. The following command should be executed in the root of a python project:
pylsp --tcp --port 9977 --verbose
I then had to configure neovim to use the language server via TCP instead of
spawning its own instance. This was also quite simple, just override the cmd
with a dedicated function.
A usual neovim LSP configuration looks something like:
local lspconfig = require('lspconfig')
lspconfig.pylsp.setup({
-- additional LSP configuration here...
})
To connect via TCP use:
local lspconfig = require('lspconfig')
lspconfig.pylsp.setup({
cmd = vim.lsp.rpc.connect("127.0.0.1", 9977),
-- additional LSP configuration here...
})
Now execute neovim on the same directory where the LSP server was started. Logs
will immediately start showing out in the LSP server. In this particular case,
it turns out that I had a version of jedi
which was too new for pylsp
and
it refused to work with it:
2023-09-05 17:55:30,637 CEST - INFO - pylsp.python_lsp - Serving PythonLSPServer on (127.0.0.1, 9977)
2023-09-05 17:55:34,279 CEST - INFO - pylsp.config.config - Failed to load pylsp entry point 'pylsp_mypy': (jedi 0.19.0 (/usr/lib/python3.11/site-packages), Requirement.parse('jedi<0.19.0,>=0.17.2'), {'python-lsp-server'})
2023-09-05 17:55:34,282 CEST - INFO - pylsp.config.config - Failed to load pylsp entry point 'pylsp_black': (jedi 0.19.0 (/usr/lib/python3.11/site-packages), Requirement.parse('jedi<0.19.0,>=0.17.2'), {'python-lsp-server'})
2023-09-05 17:55:34,282 CEST - INFO - pylsp.config.config - Failed to load pylsp entry point 'autopep8': (jedi 0.19.0 (/usr/lib/python3.11/site-packages), Requirement.parse('jedi<0.19.0,>=0.17.2'))
2023-09-05 17:55:34,283 CEST - INFO - pylsp.config.config - Failed to load pylsp entry point 'flake8': (jedi 0.19.0 (/usr/lib/python3.11/site-packages), Requirement.parse('jedi<0.19.0,>=0.17.2'))
2023-09-05 17:55:34,283 CEST - INFO - pylsp.config.config - Failed to load pylsp entry point 'folding': (jedi 0.19.0 (/usr/lib/python3.11/site-packages), Requirement.parse('jedi<0.19.0,>=0.17.2'))
2023-09-05 17:55:34,283 CEST - INFO - pylsp.config.config - Failed to load pylsp entry point 'jedi_completion': (jedi 0.19.0 (/usr/lib/python3.11/site-packages), Requirement.parse('jedi<0.19.0,>=0.17.2'))
2023-09-05 17:55:34,283 CEST - INFO - pylsp.config.config - Failed to load pylsp entry point 'jedi_definition': (jedi 0.19.0 (/usr/lib/python3.11/site-packages), Requirement.parse('jedi<0.19.0,>=0.17.2'))
2023-09-05 17:55:34,283 CEST - INFO - pylsp.config.config - Failed to load pylsp entry point 'jedi_highlight': (jedi 0.19.0 (/usr/lib/python3.11/site-packages), Requirement.parse('jedi<0.19.0,>=0.17.2'))
2023-09-05 17:55:34,283 CEST - INFO - pylsp.config.config - Failed to load pylsp entry point 'jedi_hover': (jedi 0.19.0 (/usr/lib/python3.11/site-packages), Requirement.parse('jedi<0.19.0,>=0.17.2'))
2023-09-05 17:55:34,283 CEST - INFO - pylsp.config.config - Failed to load pylsp entry point 'jedi_references': (jedi 0.19.0 (/usr/lib/python3.11/site-packages), Requirement.parse('jedi<0.19.0,>=0.17.2'))
2023-09-05 17:55:34,284 CEST - INFO - pylsp.config.config - Failed to load pylsp entry point 'jedi_rename': (jedi 0.19.0 (/usr/lib/python3.11/site-packages), Requirement.parse('jedi<0.19.0,>=0.17.2'))
2023-09-05 17:55:34,284 CEST - INFO - pylsp.config.config - Failed to load pylsp entry point 'jedi_signature_help': (jedi 0.19.0 (/usr/lib/python3.11/site-packages), Requirement.parse('jedi<0.19.0,>=0.17.2'))
2023-09-05 17:55:34,284 CEST - INFO - pylsp.config.config - Failed to load pylsp entry point 'jedi_symbols': (jedi 0.19.0 (/usr/lib/python3.11/site-packages), Requirement.parse('jedi<0.19.0,>=0.17.2'))
2023-09-05 17:55:34,284 CEST - INFO - pylsp.config.config - Failed to load pylsp entry point 'mccabe': (jedi 0.19.0 (/usr/lib/python3.11/site-packages), Requirement.parse('jedi<0.19.0,>=0.17.2'))
2023-09-05 17:55:34,284 CEST - INFO - pylsp.config.config - Failed to load pylsp entry point 'preload': (jedi 0.19.0 (/usr/lib/python3.11/site-packages), Requirement.parse('jedi<0.19.0,>=0.17.2'))
2023-09-05 17:55:34,284 CEST - INFO - pylsp.config.config - Failed to load pylsp entry point 'pycodestyle': (jedi 0.19.0 (/usr/lib/python3.11/site-packages), Requirement.parse('jedi<0.19.0,>=0.17.2'))
2023-09-05 17:55:34,284 CEST - INFO - pylsp.config.config - Failed to load pylsp entry point 'pydocstyle': (jedi 0.19.0 (/usr/lib/python3.11/site-packages), Requirement.parse('jedi<0.19.0,>=0.17.2'))
2023-09-05 17:55:34,284 CEST - INFO - pylsp.config.config - Failed to load pylsp entry point 'pyflakes': (jedi 0.19.0 (/usr/lib/python3.11/site-packages), Requirement.parse('jedi<0.19.0,>=0.17.2'))
2023-09-05 17:55:34,285 CEST - INFO - pylsp.config.config - Failed to load pylsp entry point 'pylint': (jedi 0.19.0 (/usr/lib/python3.11/site-packages), Requirement.parse('jedi<0.19.0,>=0.17.2'))
2023-09-05 17:55:34,285 CEST - INFO - pylsp.config.config - Failed to load pylsp entry point 'rope_autoimport': (jedi 0.19.0 (/usr/lib/python3.11/site-packages), Requirement.parse('jedi<0.19.0,>=0.17.2'))
2023-09-05 17:55:34,285 CEST - INFO - pylsp.config.config - Failed to load pylsp entry point 'rope_completion': (jedi 0.19.0 (/usr/lib/python3.11/site-packages), Requirement.parse('jedi<0.19.0,>=0.17.2'))
2023-09-05 17:55:34,285 CEST - INFO - pylsp.config.config - Failed to load pylsp entry point 'rope_rename': (jedi 0.19.0 (/usr/lib/python3.11/site-packages), Requirement.parse('jedi<0.19.0,>=0.17.2'))
2023-09-05 17:55:34,285 CEST - INFO - pylsp.config.config - Failed to load pylsp entry point 'yapf': (jedi 0.19.0 (/usr/lib/python3.11/site-packages), Requirement.parse('jedi<0.19.0,>=0.17.2'))
2023-09-05 17:55:34,290 CEST - INFO - pylsp.config.config - Disabled plugins: []
Looks like pylsp
refuses to work with jedi
>= 0.19, but 0.19.0 is already
out and it’s what I have installed.
This has been addressed upstream a while ago, although unreleased. I’ve backported the patch into the APKBUILD for community/py3-lsp-server in the meantime.