Skip to content

Commit

Permalink
feat(checkers): support lsp diagnostic jumping
Browse files Browse the repository at this point in the history
If the lsp is enabled for current buffer. the following key
bindings should support lsp diagnostic.
1. SPC e l: diagnostic set location list
2. SPC e n: jump to next diagnostic
3. SPC e p: jump to previous diagnostic
  • Loading branch information
wsdjeg committed Oct 5, 2021
1 parent c6156bf commit 55365f6
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 39 deletions.
90 changes: 51 additions & 39 deletions autoload/SpaceVim/layers/checkers.vim
Expand Up @@ -169,70 +169,82 @@ function! s:neomake_cursor_move_delay() abort
endfunction

function! s:toggle_show_error(...) abort
let llist = getloclist(0, {'size' : 1, 'winid' : 1})
let qlist = getqflist({'size' : 1, 'winid' : 1})
if llist.size == 0 && qlist.size == 0
echohl WarningMsg
echon 'There is no errors!'
echohl None
return
endif
if llist.winid > 0
lclose
elseif qlist.winid > 0
cclose
elseif llist.size > 0
botright lopen
elseif qlist.size > 0
botright copen
endif
if a:1 == 1
wincmd w
if SpaceVim#lsp#buf_server_ready()
call SpaceVim#lsp#diagnostic_set_loclist()
else
let llist = getloclist(0, {'size' : 1, 'winid' : 1})
let qlist = getqflist({'size' : 1, 'winid' : 1})
if llist.size == 0 && qlist.size == 0
echohl WarningMsg
echon 'There is no errors!'
echohl None
return
endif
if llist.winid > 0
lclose
elseif qlist.winid > 0
cclose
elseif llist.size > 0
botright lopen
elseif qlist.size > 0
botright copen
endif
if a:1 == 1
wincmd w
endif
endif
endfunction

function! s:jump_to_next_error() abort
try
lnext
catch
if SpaceVim#lsp#buf_server_ready()
call SpaceVim#lsp#diagnostic_goto_next()
else
try
ll
lnext
catch
try
cnext
ll
catch
try
cc
cnext
catch
echohl WarningMsg
echon 'There is no errors!'
echohl None
try
cc
catch
echohl WarningMsg
echon 'There is no errors!'
echohl None
endtry
endtry
endtry
endtry
endtry
endif
endfunction

function! s:jump_to_previous_error() abort
try
lprevious
catch
if SpaceVim#lsp#buf_server_ready()
call SpaceVim#lsp#diagnostic_goto_prev()
else
try
ll
lprevious
catch
try
cprevious
ll
catch
try
cc
cprevious
catch
echohl WarningMsg
echon 'There is no errors!'
echohl None
try
cc
catch
echohl WarningMsg
echon 'There is no errors!'
echohl None
endtry
endtry
endtry
endtry
endtry
endif
endfunction

let s:last_echoed_error = ''
Expand Down
4 changes: 4 additions & 0 deletions autoload/SpaceVim/layers/lang/vim.vim
Expand Up @@ -101,6 +101,10 @@ function! SpaceVim#layers#lang#vim#config() abort
autocmd BufWritePost *.vim call s:generate_doc()
augroup END
endif
" if the lsp layer is enabled, we should disable default linter
if SpaceVim#layers#lsp#check_server('vimls') || SpaceVim#layers#lsp#check_filetype('vim')
let g:neomake_vim_enabled_makers = []
endif
endfunction

function! s:on_exit(...) abort
Expand Down
12 changes: 12 additions & 0 deletions autoload/SpaceVim/lsp.vim
Expand Up @@ -59,6 +59,18 @@ if (has('nvim-0.5.0') && s:NVIM_VERSION.is_release_version()) || has('nvim-0.6.0
function! SpaceVim#lsp#remove_workspace_folder() abort
lua vim.lsp.buf.remove_workspace_folder()
endfunction
function! SpaceVim#lsp#buf_server_ready() abort
return v:lua.vim.lsp.buf.server_ready()
endfunction
function! SpaceVim#lsp#diagnostic_set_loclist() abort
lua vim.lsp.diagnostic.set_loclist()
endfunction
function! SpaceVim#lsp#diagnostic_goto_next() abort
lua vim.lsp.diagnostic.goto_next()
endfunction
function! SpaceVim#lsp#diagnostic_goto_prev() abort
lua vim.lsp.diagnostic.goto_prev()
endfunction
elseif SpaceVim#layers#isLoaded('autocomplete') && get(g:, 'spacevim_autocomplete_method') ==# 'coc'
" use coc.nvim
let s:coc_language_servers = {}
Expand Down

0 comments on commit 55365f6

Please sign in to comment.