1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-03-14 10:45:42 +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 endfunction
function! s:toggle_show_error(...) abort function! s:toggle_show_error(...) abort
let llist = getloclist(0, {'size' : 1, 'winid' : 1}) if SpaceVim#lsp#buf_server_ready()
let qlist = getqflist({'size' : 1, 'winid' : 1}) call SpaceVim#lsp#diagnostic_set_loclist()
if llist.size == 0 && qlist.size == 0 else
echohl WarningMsg let llist = getloclist(0, {'size' : 1, 'winid' : 1})
echon 'There is no errors!' let qlist = getqflist({'size' : 1, 'winid' : 1})
echohl None if llist.size == 0 && qlist.size == 0
return echohl WarningMsg
endif echon 'There is no errors!'
if llist.winid > 0 echohl None
lclose return
elseif qlist.winid > 0 endif
cclose if llist.winid > 0
elseif llist.size > 0 lclose
botright lopen elseif qlist.winid > 0
elseif qlist.size > 0 cclose
botright copen elseif llist.size > 0
endif botright lopen
if a:1 == 1 elseif qlist.size > 0
wincmd w botright copen
endif
if a:1 == 1
wincmd w
endif
endif endif
endfunction endfunction
function! s:jump_to_next_error() abort function! s:jump_to_next_error() abort
try if SpaceVim#lsp#buf_server_ready()
lnext call SpaceVim#lsp#diagnostic_goto_next()
catch else
try try
ll lnext
catch catch
try try
cnext ll
catch catch
try try
cc cnext
catch catch
echohl WarningMsg try
echon 'There is no errors!' cc
echohl None catch
echohl WarningMsg
echon 'There is no errors!'
echohl None
endtry
endtry endtry
endtry endtry
endtry endtry
endtry endif
endfunction endfunction
function! s:jump_to_previous_error() abort function! s:jump_to_previous_error() abort
try if SpaceVim#lsp#buf_server_ready()
lprevious call SpaceVim#lsp#diagnostic_goto_prev()
catch else
try try
ll lprevious
catch catch
try try
cprevious ll
catch catch
try try
cc cprevious
catch catch
echohl WarningMsg try
echon 'There is no errors!' cc
echohl None catch
echohl WarningMsg
echon 'There is no errors!'
echohl None
endtry
endtry endtry
endtry endtry
endtry endtry
endtry endif
endfunction endfunction
let s:last_echoed_error = '' 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() autocmd BufWritePost *.vim call s:generate_doc()
augroup END augroup END
endif 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 endfunction
function! s:on_exit(...) abort 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 function! SpaceVim#lsp#remove_workspace_folder() abort
lua vim.lsp.buf.remove_workspace_folder() lua vim.lsp.buf.remove_workspace_folder()
endfunction 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' elseif SpaceVim#layers#isLoaded('autocomplete') && get(g:, 'spacevim_autocomplete_method') ==# 'coc'
" use coc.nvim " use coc.nvim
let s:coc_language_servers = {} let s:coc_language_servers = {}