1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-02-02 22:20:06 +08:00

Add error handle key bindings to lsp layer (#2774)

This commit is contained in:
Wang Shidong 2019-04-28 20:44:47 +08:00 committed by GitHub
parent 516fbe9449
commit a80b4f5287
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 112 additions and 1 deletions

View File

@ -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('<sfile>'), '<SNR>\zs\d\+\ze__SID$')
endfunction
let s:_s = '<SNR>' . 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

View File

@ -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` | 列出错误列表窗口并跳至该窗口 |

View File

@ -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 |