1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-02-03 02:30:03 +08:00

feat(checkers): support lsp diagnostic jumping

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
This commit is contained in:
Shidong Wang 2021-10-05 22:47:55 +08:00
parent c6156bf766
commit 55365f64f8
No known key found for this signature in database
GPG Key ID: 41BB7053E835C848
3 changed files with 67 additions and 39 deletions

View File

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

View File

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

View File

@ -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 = {}