From 773aa07b469114b7fa71ea5378c35c8247421ea6 Mon Sep 17 00:00:00 2001 From: Shidong Wang Date: Thu, 7 Oct 2021 23:22:04 +0800 Subject: [PATCH] feat(lang#javascript): 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 6. add `g D` for type def jumping --- autoload/SpaceVim/layers/lang/javascript.vim | 35 +++++++++++++++++--- doc/SpaceVim.txt | 14 ++++++++ 2 files changed, 45 insertions(+), 4 deletions(-) diff --git a/autoload/SpaceVim/layers/lang/javascript.vim b/autoload/SpaceVim/layers/lang/javascript.vim index d95d987b7..13946b1d6 100644 --- a/autoload/SpaceVim/layers/lang/javascript.vim +++ b/autoload/SpaceVim/layers/lang/javascript.vim @@ -45,6 +45,20 @@ " SPC l s l send current line " SPC l s s send selection text " < +" If the lsp layer is enabled for javascript, the following key +" bindings can be used: +" > +" key binding Description +" g D jump to type definition +" 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 +" < " let s:format_on_save = 0 @@ -103,7 +117,7 @@ function! SpaceVim#layers#lang#javascript#config() abort \ 'opt': ['-'], \ }) call SpaceVim#mapping#space#regesit_lang_mappings('javascript', - \ function('s:on_ft')) + \ function('s:language_mappings')) if SpaceVim#layers#lsp#check_filetype('javascript') call SpaceVim#mapping#gd#add('javascript', @@ -149,7 +163,7 @@ function! SpaceVim#layers#lang#javascript#config() abort endif endfunction -function! s:on_ft() abort +function! s:language_mappings() abort nnoremap :ImportJSWord nnoremap ji :ImportJSWord nnoremap jf :ImportJSFix @@ -175,12 +189,25 @@ function! s:on_ft() abort if SpaceVim#layers#lsp#check_filetype('javascript') + \ || SpaceVim#layers#lsp#check_server('tssserver') nnoremap K :call SpaceVim#lsp#show_doc() + nnoremap gD :call SpaceVim#lsp#go_to_typedef() 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) else call SpaceVim#mapping#space#langSPC('nnoremap', ['l', 'd'], 'TernDoc', \ 'show document', 1) diff --git a/doc/SpaceVim.txt b/doc/SpaceVim.txt index 9c7b0d700..9bbda816b 100644 --- a/doc/SpaceVim.txt +++ b/doc/SpaceVim.txt @@ -2931,6 +2931,20 @@ This layer also provides REPL support for javascript, the key bindings are: SPC l s l send current line SPC l s s send selection text < +If the lsp layer is enabled for javascript, the following key bindings can be +used: +> + key binding Description + g D jump to type definition + 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 +< ==============================================================================