From a80b4f5287f35262470a3a08385baccbc7baf6a4 Mon Sep 17 00:00:00 2001 From: Wang Shidong Date: Sun, 28 Apr 2019 20:44:47 +0800 Subject: [PATCH] Add error handle key bindings to lsp layer (#2774) --- autoload/SpaceVim/layers/lsp.vim | 89 ++++++++++++++++++++++ docs/cn/layers/language-server-protocol.md | 11 +++ docs/layers/language-server-protocol.md | 13 +++- 3 files changed, 112 insertions(+), 1 deletion(-) diff --git a/autoload/SpaceVim/layers/lsp.vim b/autoload/SpaceVim/layers/lsp.vim index f09497631..07fba96bb 100644 --- a/autoload/SpaceVim/layers/lsp.vim +++ b/autoload/SpaceVim/layers/lsp.vim @@ -71,6 +71,28 @@ function! SpaceVim#layers#lsp#config() abort let g:LanguageClient_diagnosticsDisplay[4].signTexthl = 'ALEInfoSign' endif + + if !SpaceVim#layers#isLoaded('checkers') + call SpaceVim#mapping#space#def('nnoremap', ['e', 'c'], 'call call(' + \ . string(s:_function('s:clear_errors')) . ', [])', + \ 'clear all errors', 1) + call SpaceVim#mapping#space#def('nnoremap', ['e', 'n'], 'call call(' + \ . string(s:_function('s:jump_to_next_error')) . ', [])', + \ 'next-error', 1) + call SpaceVim#mapping#space#def('nnoremap', ['e', 'p'], 'call call(' + \ . string(s:_function('s:jump_to_previous_error')) . ', [])', + \ 'previous-error', 1) + call SpaceVim#mapping#space#def('nnoremap', ['e', 'N'], 'call call(' + \ . string(s:_function('s:jump_to_previous_error')) . ', [])', + \ 'previous-error', 1) + call SpaceVim#mapping#space#def('nnoremap', ['e', 'l'], 'call call(' + \ . string(s:_function('s:toggle_show_error')) . ', [0])', + \ 'toggle showing the error list', 1) + call SpaceVim#mapping#space#def('nnoremap', ['e', 'L'], 'call call(' + \ . string(s:_function('s:toggle_show_error')) . ', [1])', + \ 'toggle showing the error list', 1) + endif + let g:LanguageClient_autoStart = 1 let g:lsp_async_completion = 1 " }}} @@ -126,3 +148,70 @@ endfunction function! SpaceVim#layers#lsp#check_filetype(ft) abort return index(s:enabled_fts, a:ft) != -1 endfunction + +function! s:jump_to_next_error() abort + try + lnext + catch + try + cnext + catch + echohl WarningMsg + echon 'There is no errors!' + echohl None + endtry + endtry +endfunction + +function! s:jump_to_previous_error() abort + try + lprevious + catch + try + cprevious + catch + echohl WarningMsg + echon 'There is no errors!' + echohl None + endtry + endtry +endfunction + +function! s:toggle_show_error(...) abort + try + botright lopen + catch + try + if len(getqflist()) == 0 + echohl WarningMsg + echon 'There is no errors!' + echohl None + else + botright copen + endif + catch + endtry + endtry + if a:1 == 1 + wincmd w + endif +endfunction + +if v:version > 703 || v:version == 703 && has('patch1170') + function! s:_function(fstr) abort + return function(a:fstr) + endfunction +else + function! s:_SID() abort + return matchstr(expand(''), '\zs\d\+\ze__SID$') + endfunction + let s:_s = '' . s:_SID() . '_' + function! s:_function(fstr) abort + return function(substitute(a:fstr, 's:', s:_s, 'g')) + endfunction +endif + +" TODO clear errors +function! s:clear_errors() abort + sign unplace * +endfunction diff --git a/docs/cn/layers/language-server-protocol.md b/docs/cn/layers/language-server-protocol.md index b5619da9c..cdbc939b5 100644 --- a/docs/cn/layers/language-server-protocol.md +++ b/docs/cn/layers/language-server-protocol.md @@ -168,3 +168,14 @@ gem install solargraph | --------------- | ------------- | | `K` / `SPC l d` | 显示文档 | | `SPC l e` | 重命名 symbol | + +如果 `checkers` 模块未载入,则以下快捷键将被引入: + +| 快捷键 | 功能描述 | +| --------- | ------------------------------- | +| `SPC e c` | 清除错误列表 | +| `SPC e n` | 跳至下一个语法错误位置 | +| `SPC e N` | 跳至上一个语法错误位置 | +| `SPC e p` | 跳至上一个语法错误位置 | +| `SPC e l` | 列出错误列表窗口 | +| `SPC e L` | 列出错误列表窗口并跳至该窗口 | diff --git a/docs/layers/language-server-protocol.md b/docs/layers/language-server-protocol.md index 544524e0a..72aae5b32 100644 --- a/docs/layers/language-server-protocol.md +++ b/docs/layers/language-server-protocol.md @@ -156,7 +156,7 @@ default language server commands: | `php` | `['php', 'path/to/bin/php-language-server.php']` | | `purescript` | `['purescript-language-server', '--stdio']` | | `python` | `['pyls']` | -| `ruby` | `['solargraph', 'stdio']` +| `ruby` | `['solargraph', 'stdio']` | | `rust` | `['rustup', 'run', 'nightly', 'rls']` | | `sh` | `['bash-language-server', 'start']` | | `typescript` | `['typescript-language-server', '--stdio']` | @@ -181,3 +181,14 @@ To override the server command, you may need to use `override_cmd` option: | --------------- | ------------- | | `K` / `SPC l d` | show document | | `SPC l e` | rename symbol | + +if the checkers layer is not loaded, these key bindings will be added: + +| Key | description | +| --------- | ------------------------------------------------------------ | +| `SPC e c` | clear errors | +| `SPC e n` | jump to the position of next error | +| `SPC e N` | jump to the position of previous error | +| `SPC e p` | jump to the position of previous error | +| `SPC e l` | display a list of all the errors | +| `SPC e L` | display a list of all the errors and focus the errors buffer |