From 55365f64f8e2a6a5bf75db787514f57134ebeec1 Mon Sep 17 00:00:00 2001 From: Shidong Wang Date: Tue, 5 Oct 2021 22:47:55 +0800 Subject: [PATCH] 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 --- autoload/SpaceVim/layers/checkers.vim | 90 +++++++++++++++------------ autoload/SpaceVim/layers/lang/vim.vim | 4 ++ autoload/SpaceVim/lsp.vim | 12 ++++ 3 files changed, 67 insertions(+), 39 deletions(-) diff --git a/autoload/SpaceVim/layers/checkers.vim b/autoload/SpaceVim/layers/checkers.vim index 73ada55d8..73d19bfca 100644 --- a/autoload/SpaceVim/layers/checkers.vim +++ b/autoload/SpaceVim/layers/checkers.vim @@ -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 = '' diff --git a/autoload/SpaceVim/layers/lang/vim.vim b/autoload/SpaceVim/layers/lang/vim.vim index 0eae892f5..d24c4dfae 100644 --- a/autoload/SpaceVim/layers/lang/vim.vim +++ b/autoload/SpaceVim/layers/lang/vim.vim @@ -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 diff --git a/autoload/SpaceVim/lsp.vim b/autoload/SpaceVim/lsp.vim index 835609b9b..0ae5612d5 100644 --- a/autoload/SpaceVim/lsp.vim +++ b/autoload/SpaceVim/lsp.vim @@ -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 = {}