我花了很多时间弄清楚如何在 neovim 中使用 Python (3) 的语言服务器协议 (LSP)。主要是我在寻找 Python 3 的自动完成功能,它是像 PySide2 这样的模块。
遗憾的是,我无法让我的配置文件 (.config/vim/init.vim) 工作。我知道github上有很多。但是它们包含了如此多的附加功能,我还没有能够根据我的需要调整其中的一个。还有一些也已经过时了。
所以这是我迄今为止尝试过的:
www.langserver.org 有很长的语言客户端和服务器列表。
我为 Python 安装了 Palantirs 语言服务器协议(https://github.com/palantir/python-language-server):
pip3 install 'python-language-server[all]'
Run Code Online (Sandbox Code Playgroud)
在下一步中,我通过 vim-plug 为 neovim 安装了一个语言客户端。实际上我尝试了几个,但让我们坚持以 ale 为例(https://github.com/dense-analysis/ale):
call plug#begin('~/.local/share/nvim/plugged')
" Plugins:
Plug 'dense-analysis/ale'
" Initialize plugin system
call plug#end()
Run Code Online (Sandbox Code Playgroud)
并通过安装它 :PlugInstall
然后必须在加载 Ale 之前对自动完成功能进行设置:
" initialize before ale is loaded
let g:ale_completion_enabled = 1
Run Code Online (Sandbox Code Playgroud)
要与 Omnicompletion 一起使用,还需要另外一项设置:
set omnifunc=ale#completion#OmniFunc
Run Code Online (Sandbox Code Playgroud)
经过更多的谷歌搜索,我读到我必须注册语言服务器(https://vi.stackexchange.com/questions/20958/use-the-pyls-python-lsp-with-ale-on-neovim):
if executable('pyls')
au User lsp_setup call lsp#register_server({
\ …Run Code Online (Sandbox Code Playgroud)