1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-02-03 04:30:04 +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,6 +169,9 @@ function! s:neomake_cursor_move_delay() abort
endfunction
function! s:toggle_show_error(...) abort
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
@ -189,9 +192,13 @@ function! s:toggle_show_error(...) abort
if a:1 == 1
wincmd w
endif
endif
endfunction
function! s:jump_to_next_error() abort
if SpaceVim#lsp#buf_server_ready()
call SpaceVim#lsp#diagnostic_goto_next()
else
try
lnext
catch
@ -211,9 +218,13 @@ function! s:jump_to_next_error() abort
endtry
endtry
endtry
endif
endfunction
function! s:jump_to_previous_error() abort
if SpaceVim#lsp#buf_server_ready()
call SpaceVim#lsp#diagnostic_goto_prev()
else
try
lprevious
catch
@ -233,6 +244,7 @@ function! s:jump_to_previous_error() abort
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 = {}