mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-01-23 10:40:03 +08:00
feat(pylsp): add support for pylsp
This commit is contained in:
parent
5642bc572c
commit
d66173b58a
@ -99,6 +99,7 @@ function! SpaceVim#layers#lang#python#plugins() abort
|
|||||||
" python
|
" python
|
||||||
if !SpaceVim#layers#lsp#check_filetype('python')
|
if !SpaceVim#layers#lsp#check_filetype('python')
|
||||||
\ && !SpaceVim#layers#lsp#check_server('pyright')
|
\ && !SpaceVim#layers#lsp#check_server('pyright')
|
||||||
|
\ && !SpaceVim#layers#lsp#check_server('pylsp')
|
||||||
if has('nvim')
|
if has('nvim')
|
||||||
call add(plugins, ['zchee/deoplete-jedi', { 'on_ft' : 'python'}])
|
call add(plugins, ['zchee/deoplete-jedi', { 'on_ft' : 'python'}])
|
||||||
" in neovim, we can use deoplete-jedi together with jedi-vim,
|
" 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')
|
elseif executable('python3')
|
||||||
call SpaceVim#plugins#repl#reg('python', ['python3', '-i'])
|
call SpaceVim#plugins#repl#reg('python', ['python3', '-i'])
|
||||||
endif
|
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 = []
|
let g:neomake_python_enabled_makers = []
|
||||||
else
|
else
|
||||||
let g:neomake_python_enabled_makers = s:enabled_linters
|
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')
|
if SpaceVim#layers#lsp#check_filetype('python')
|
||||||
\ || SpaceVim#layers#lsp#check_server('pyright')
|
\ || SpaceVim#layers#lsp#check_server('pyright')
|
||||||
|
\ || SpaceVim#layers#lsp#check_server('pylsp')
|
||||||
nnoremap <silent><buffer> K :call SpaceVim#lsp#show_doc()<CR>
|
nnoremap <silent><buffer> K :call SpaceVim#lsp#show_doc()<CR>
|
||||||
nnoremap <silent><buffer> gD :<C-u>call SpaceVim#lsp#go_to_typedef()<Cr>
|
nnoremap <silent><buffer> gD :<C-u>call SpaceVim#lsp#go_to_typedef()<Cr>
|
||||||
|
|
||||||
@ -278,6 +282,7 @@ endf
|
|||||||
function! s:go_to_def() abort
|
function! s:go_to_def() abort
|
||||||
if SpaceVim#layers#lsp#check_filetype('python')
|
if SpaceVim#layers#lsp#check_filetype('python')
|
||||||
\ || SpaceVim#layers#lsp#check_server('pyright')
|
\ || SpaceVim#layers#lsp#check_server('pyright')
|
||||||
|
\ || SpaceVim#layers#lsp#check_server('pylsp')
|
||||||
call SpaceVim#lsp#go_to_def()
|
call SpaceVim#lsp#go_to_def()
|
||||||
else
|
else
|
||||||
call jedi#goto()
|
call jedi#goto()
|
||||||
|
@ -106,6 +106,36 @@ pip install --user isort
|
|||||||
pip install --user coverage
|
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 文件头信息模板。
|
- `python_file_head`: 设置默认的 Python 文件头信息模板。
|
||||||
@ -134,6 +164,7 @@ pip install --user coverage
|
|||||||
|
|
||||||
- `format_on_save`: 启用或者禁用文件保存时的自动格式化,默认为禁用状态,
|
- `format_on_save`: 启用或者禁用文件保存时的自动格式化,默认为禁用状态,
|
||||||
若想启用这一功能,可以使用如下配置:
|
若想启用这一功能,可以使用如下配置:
|
||||||
|
|
||||||
```toml
|
```toml
|
||||||
[[layers]]
|
[[layers]]
|
||||||
name = 'lang#python'
|
name = 'lang#python'
|
||||||
@ -142,6 +173,7 @@ pip install --user coverage
|
|||||||
|
|
||||||
- `python_interpreter`: 设置 python 的可执行命令路劲,默认值为 `python3`,该选项的值将被应用于
|
- `python_interpreter`: 设置 python 的可执行命令路劲,默认值为 `python3`,该选项的值将被应用于
|
||||||
`g:neomake_python_python_exe` 和代码快速运行器。
|
`g:neomake_python_python_exe` 和代码快速运行器。
|
||||||
|
|
||||||
```toml
|
```toml
|
||||||
[[layers]]
|
[[layers]]
|
||||||
name = 'lang#python'
|
name = 'lang#python'
|
||||||
@ -172,8 +204,8 @@ pip install --user coverage
|
|||||||
|
|
||||||
### 测试覆盖
|
### 测试覆盖
|
||||||
|
|
||||||
| 模式 | 快捷键 | 功能描述 |
|
| 模式 | 快捷键 | 功能描述 |
|
||||||
| ------ | ----------- | ----------------- |
|
| ------ | ----------- | ---------------- |
|
||||||
| normal | `SPC l c r` | coverage report |
|
| normal | `SPC l c r` | coverage report |
|
||||||
| normal | `SPC l c s` | coverage show |
|
| normal | `SPC l c s` | coverage show |
|
||||||
| normal | `SPC l c e` | coverage session |
|
| normal | `SPC l c e` | coverage session |
|
||||||
|
@ -102,19 +102,29 @@ you need to add following snippet into your spacevim configuration file.
|
|||||||
|
|
||||||
- **language server**
|
- **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
|
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]]
|
[[layers]]
|
||||||
name = 'lsp'
|
name = 'lsp'
|
||||||
enabled_clients = ['pyright']
|
enabled_clients = ['pyright']
|
||||||
```
|
```
|
||||||
|
If you want to use `python-lsp-server`, use following config:
|
||||||
|
```
|
||||||
|
[[layers]]
|
||||||
|
name = 'lsp'
|
||||||
|
enabled_clients = ['pylsp']
|
||||||
|
```
|
||||||
|
|
||||||
## Layer options
|
## Layer options
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user