From 309728bcf2adf95b40caece041671f1a181fa6d1 Mon Sep 17 00:00:00 2001 From: Shidong Wang Date: Wed, 6 Oct 2021 15:30:36 +0800 Subject: [PATCH] feat(lang#python): add more lsp key bindings Problem: Only a few lsp shortcuts are defined for python. Solution: add more lsp key bindings 1. SPC l x: show references 2. SPC l s: show line diagnostics 3. SPC l w l: list workspace folder 4. SPC l w a: add workspace folder 5. SPC l w r: remove workspace folder --- autoload/SpaceVim/layers/lang/python.vim | 47 +++++++++++++++++++----- doc/SpaceVim.txt | 13 +++++++ 2 files changed, 51 insertions(+), 9 deletions(-) diff --git a/autoload/SpaceVim/layers/lang/python.vim b/autoload/SpaceVim/layers/lang/python.vim index 67cc469d6..70556ebd9 100644 --- a/autoload/SpaceVim/layers/lang/python.vim +++ b/autoload/SpaceVim/layers/lang/python.vim @@ -62,6 +62,19 @@ " SPC l s s send selection text " < " +" If the lsp layer is enabled for python, the following key bindings can +" be used: +" > +" key binding Description +" SPC l e rename symbol +" SPC l x show references +" SPC l s show line diagnostics +" SPC l d show document +" K show document +" SPC l w l list workspace folder +" SPC l w a add workspace folder +" SPC l w r remove workspace folder +" < if exists('s:enabled_linters') @@ -122,13 +135,13 @@ function! SpaceVim#layers#lang#python#config() abort augroup end endif " }}} - let g:deoplete#sources#jedi#enable_typeinfo = s:enable_typeinfo + let g:deoplete#sources#jedi#enable_typeinfo = s:enable_typeinfo call SpaceVim#plugins#runner#reg_runner('python', \ { - \ 'exe' : function('s:getexe'), - \ 'opt' : ['-'], - \ 'usestdin' : 1, - \ }) + \ 'exe' : function('s:getexe'), + \ 'opt' : ['-'], + \ 'usestdin' : 1, + \ }) call SpaceVim#mapping#gd#add('python', function('s:go_to_def')) call SpaceVim#mapping#space#regesit_lang_mappings('python', function('s:language_specified_mappings')) call SpaceVim#layers#edit#add_ft_head_tamplate('python', s:python_file_head) @@ -141,8 +154,12 @@ function! SpaceVim#layers#lang#python#config() abort elseif executable('python3') call SpaceVim#plugins#repl#reg('python', ['python3', '-i']) endif - let g:neomake_python_enabled_makers = s:enabled_linters - let g:neomake_python_python_exe = s:python_interpreter + if SpaceVim#layers#lsp#check_server('pyright') || SpaceVim#layers#lsp#check_filetype('python') + let g:neomake_python_enabled_makers = [] + else + let g:neomake_python_enabled_makers = s:enabled_linters + let g:neomake_python_python_exe = s:python_interpreter + endif endfunction function! s:language_specified_mappings() abort @@ -198,12 +215,24 @@ function! s:language_specified_mappings() abort " }}} if SpaceVim#layers#lsp#check_filetype('python') + \ || SpaceVim#layers#lsp#check_server('pyright') nnoremap K :call SpaceVim#lsp#show_doc() call SpaceVim#mapping#space#langSPC('nnoremap', ['l', 'd'], - \ 'call SpaceVim#lsp#show_doc()', 'show_document', 1) + \ 'call SpaceVim#lsp#show_doc()', 'show-document', 1) + call SpaceVim#mapping#space#langSPC('nnoremap', ['l', 'x'], + \ 'call SpaceVim#lsp#references()', 'show-references', 1) call SpaceVim#mapping#space#langSPC('nnoremap', ['l', 'e'], - \ 'call SpaceVim#lsp#rename()', 'rename symbol', 1) + \ 'call SpaceVim#lsp#rename()', 'rename-symbol', 1) + call SpaceVim#mapping#space#langSPC('nnoremap', ['l', 's'], + \ 'call SpaceVim#lsp#show_line_diagnostics()', 'show-line-diagnostics', 1) + let g:_spacevim_mappings_space.l.w = {'name' : '+Workspace'} + call SpaceVim#mapping#space#langSPC('nnoremap', ['l', 'w', 'l'], + \ 'call SpaceVim#lsp#list_workspace_folder()', 'list-workspace-folder', 1) + call SpaceVim#mapping#space#langSPC('nnoremap', ['l', 'w', 'a'], + \ 'call SpaceVim#lsp#add_workspace_folder()', 'add-workspace-folder', 1) + call SpaceVim#mapping#space#langSPC('nnoremap', ['l', 'w', 'r'], + \ 'call SpaceVim#lsp#remove_workspace_folder()', 'remove-workspace-folder', 1) endif " Format on save diff --git a/doc/SpaceVim.txt b/doc/SpaceVim.txt index b454c060f..79849d70f 100644 --- a/doc/SpaceVim.txt +++ b/doc/SpaceVim.txt @@ -3552,6 +3552,19 @@ This layer also provides REPL support for python, the key bindings are: SPC l s s send selection text < +If the lsp layer is enabled for python, the following key bindings can be +used: +> + key binding Description + SPC l e rename symbol + SPC l x show references + SPC l s show line diagnostics + SPC l d show document + K show document + SPC l w l list workspace folder + SPC l w a add workspace folder + SPC l w r remove workspace folder +< ============================================================================== LANG#RACKET *SpaceVim-layers-lang-racket*