Time for a change…
Vim has some plugins available for interacting with language servers via the language server protocol.
vim-lsp seemed to be a good next candidate to try.
(Why?
It supports many commands for the language server interaction, is written in vimscript, just takes care of the language server part.)
For setting servers up there is another plugin, vim-lsp-settings.
Installing lsp
Installing the following plugins in vim via vim-plug:is the basic set up.Plug 'prabirshrestha/async.vim' Plug 'prabirshrestha/vim-lsp' Plug 'mattn/vim-lsp-settings'Plug 'prabirshrestha/asyncomplete.vim' Plug 'prabirshrestha/asyncomplete-lsp.vim'
But still for every language or filetype a server needs to be installed separately. Here the vim-lsp-settings helps with its command
It will install the appropriate server for the filetype. Sometimes there are multiple servers available. You can check via <Ctrl>d or on the website of the plugin and install the server with its name, e.g.:LspInstallServer
For some servers you need to have some criteria met, like having npm, go or python3 venv installed.:LspInstallServer pyls-ms
Adjusting Settings
Some languages and there servers are not yet inside the project, so you have to set them up on your own. You can do it inside your .vimrc file, or in a user-global or project-local settings.json file:For python and pyls or python-language-server it could be:~/.local/share/vim-lsp-settings/settings.json $project/.vim-lsp-settings/settings.json
Or multiple, like python, dart, clangd, inside the .vimrc:{ "pyls": { "workspace_config": { "pyls": { "plugins": { "pydocstyle": {"enabled": true}, "pycodestyle": {"enabled": true}, "pyflakes": {"enabled": true}, "jedi": {"enabled": true}, "pylint": {"enabled": true} } } } } }
Usefull options I enabled are:let g:lsp_settings = { \ 'analysis-server-dart-snapshot': { \ 'cmd': [ \ '/usr/lib/dart/bin/dart', \ '/usr/lib/dart/bin/snapshots/analysis_server.dart.snapshot', \ '--lsp' \ ] \ }, \ 'clangd': { \ 'cmd': [ \ 'clangd' \ ] \ }, \ 'pyls': { \ 'workspace_config': { \ 'pyls': { \ 'plugins': { \ 'pydocstyle': {'enabled': v:true}, \ 'pycodestyle': {'enabled': v:true}, \ 'pyflakes': {'enabled': v:true}, \ 'jedi': {'enabled': v:true}, \ 'pylint': {'enabled': v:true} \ } \ } \ } \ } \ }
As an extra I bound <LocalLeader>K (in my case \K) to hover and show a neat little window with information above the current symbole:let g:lsp_diagnostics_echo_cursor = 1 " enable echo under cursor when in normal mode let g:lsp_diagnostics_float_cursor = 1 " enable echo under cursor when in normal mode
You can bind more with given mappings or use the commands directly, like showing diagnostics vianmap <LocalLeader>K <Plug>(lsp-hover)
:LspDocumentDiagnostics
, formating the document via :LspDocumentFormat
lsp with python via pyls
Installing the pyls python-language-server via
:LspInstallServer pyls
installs it in its own environment under
~/.local/share/vim-lsp-settings/servers/pyls/venv
It is basically installing it via pip. But you might not have the tools, like pydocstyle and pycodestyle, installed. You can just install them inside that virtual environment, e.g.:
If you have the feeling, that one of your tools is not working, check the logs provided by lsp via enabling them in your vimrc:$ ~/.local/share/vim-lsp-settings/servers/pyls/venv/bin/pip3 install pyls-black pycodestyle pydocstyle pyflakes pylint autopep8
Inside there might be something like this:let g:lsp_log_verbose = 1
let g:lsp_log_file = expand('~/vim-lsp.log')
Failed to load pyls entry point 'pycodestyle': No module named 'autopep8'",""]]
Keine Kommentare:
Kommentar veröffentlichen