From d66173b58abe941966e0e4666e54963c7a2d7dc9 Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Tue, 7 Jun 2022 23:50:28 +0800 Subject: [PATCH] feat(pylsp): add support for pylsp --- autoload/SpaceVim/layers/lang/python.vim | 7 ++++- docs/cn/layers/lang/python.md | 36 ++++++++++++++++++++++-- docs/layers/lang/python.md | 14 +++++++-- 3 files changed, 52 insertions(+), 5 deletions(-) diff --git a/autoload/SpaceVim/layers/lang/python.vim b/autoload/SpaceVim/layers/lang/python.vim index 7da7582f6..445e35c68 100644 --- a/autoload/SpaceVim/layers/lang/python.vim +++ b/autoload/SpaceVim/layers/lang/python.vim @@ -99,6 +99,7 @@ function! SpaceVim#layers#lang#python#plugins() abort " python if !SpaceVim#layers#lsp#check_filetype('python') \ && !SpaceVim#layers#lsp#check_server('pyright') + \ && !SpaceVim#layers#lsp#check_server('pylsp') if has('nvim') call add(plugins, ['zchee/deoplete-jedi', { 'on_ft' : 'python'}]) " in neovim, we can use deoplete-jedi together with jedi-vim, @@ -161,7 +162,9 @@ function! SpaceVim#layers#lang#python#config() abort elseif executable('python3') call SpaceVim#plugins#repl#reg('python', ['python3', '-i']) endif - if SpaceVim#layers#lsp#check_server('pyright') || SpaceVim#layers#lsp#check_filetype('python') + if SpaceVim#layers#lsp#check_server('pyright') + \ || SpaceVim#layers#lsp#check_server('pylsp') + \ || SpaceVim#layers#lsp#check_filetype('python') let g:neomake_python_enabled_makers = [] else let g:neomake_python_enabled_makers = s:enabled_linters @@ -223,6 +226,7 @@ function! s:language_specified_mappings() abort if SpaceVim#layers#lsp#check_filetype('python') \ || SpaceVim#layers#lsp#check_server('pyright') + \ || SpaceVim#layers#lsp#check_server('pylsp') nnoremap K :call SpaceVim#lsp#show_doc() nnoremap gD :call SpaceVim#lsp#go_to_typedef() @@ -278,6 +282,7 @@ endf function! s:go_to_def() abort if SpaceVim#layers#lsp#check_filetype('python') \ || SpaceVim#layers#lsp#check_server('pyright') + \ || SpaceVim#layers#lsp#check_server('pylsp') call SpaceVim#lsp#go_to_def() else call jedi#goto() diff --git a/docs/cn/layers/lang/python.md b/docs/cn/layers/lang/python.md index 90414808e..f0f25a9f9 100644 --- a/docs/cn/layers/lang/python.md +++ b/docs/cn/layers/lang/python.md @@ -106,6 +106,36 @@ pip install --user isort pip install --user coverage ``` +**语言服务器:** + +如果需要为 Python 语言启用 `lsp` 模块,你需要安装 `pyright` 或者 `python-lsp-server`: + +``` +npm install -g pyright +``` + +或者 + +``` +pip install python-lsp-server +``` + +同时,需要启用 `lsp` 模块,以及 `pyright` 服务: + +``` +[[layers]] + name = 'lsp' + enabled_clients = ['pyright'] +``` + +如果想要使用 `python-lsp-server`,可以使用如下配置: + +``` +[[layers]] + name = 'lsp' + enabled_clients = ['pylsp'] +``` + ## 模块设置 - `python_file_head`: 设置默认的 Python 文件头信息模板。 @@ -134,6 +164,7 @@ pip install --user coverage - `format_on_save`: 启用或者禁用文件保存时的自动格式化,默认为禁用状态, 若想启用这一功能,可以使用如下配置: + ```toml [[layers]] name = 'lang#python' @@ -142,6 +173,7 @@ pip install --user coverage - `python_interpreter`: 设置 python 的可执行命令路劲,默认值为 `python3`,该选项的值将被应用于 `g:neomake_python_python_exe` 和代码快速运行器。 + ```toml [[layers]] name = 'lang#python' @@ -172,8 +204,8 @@ pip install --user coverage ### 测试覆盖 -| 模式 | 快捷键 | 功能描述 | -| ------ | ----------- | ----------------- | +| 模式 | 快捷键 | 功能描述 | +| ------ | ----------- | ---------------- | | normal | `SPC l c r` | coverage report | | normal | `SPC l c s` | coverage show | | normal | `SPC l c e` | coverage session | diff --git a/docs/layers/lang/python.md b/docs/layers/lang/python.md index 198813b57..459d5838b 100644 --- a/docs/layers/lang/python.md +++ b/docs/layers/lang/python.md @@ -102,19 +102,29 @@ you need to add following snippet into your spacevim configuration file. - **language server** - To enable python support of `lsp` layer. You may need to install `pyright`: + To enable python support of `lsp` layer. You may need to install `pyright` or `python-lsp-server`: ``` npm install -g pyright ``` + or + ``` + pip install python-lsp-server + ``` - Also you need enable `lsp` layer with pyright client: + Also you need enable `lsp` layer with `pyright` client: ``` [[layers]] name = 'lsp' enabled_clients = ['pyright'] ``` + If you want to use `python-lsp-server`, use following config: + ``` + [[layers]] + name = 'lsp' + enabled_clients = ['pylsp'] + ``` ## Layer options