Skip to content
This repository was archived by the owner on Feb 20, 2025. It is now read-only.

Commit 55365f6

Browse files
committed
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
1 parent c6156bf commit 55365f6

File tree

3 files changed

+67
-39
lines changed

3 files changed

+67
-39
lines changed

autoload/SpaceVim/layers/checkers.vim

Lines changed: 51 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -169,70 +169,82 @@ function! s:neomake_cursor_move_delay() abort
169169
endfunction
170170

171171
function! s:toggle_show_error(...) abort
172-
let llist = getloclist(0, {'size' : 1, 'winid' : 1})
173-
let qlist = getqflist({'size' : 1, 'winid' : 1})
174-
if llist.size == 0 && qlist.size == 0
175-
echohl WarningMsg
176-
echon 'There is no errors!'
177-
echohl None
178-
return
179-
endif
180-
if llist.winid > 0
181-
lclose
182-
elseif qlist.winid > 0
183-
cclose
184-
elseif llist.size > 0
185-
botright lopen
186-
elseif qlist.size > 0
187-
botright copen
188-
endif
189-
if a:1 == 1
190-
wincmd w
172+
if SpaceVim#lsp#buf_server_ready()
173+
call SpaceVim#lsp#diagnostic_set_loclist()
174+
else
175+
let llist = getloclist(0, {'size' : 1, 'winid' : 1})
176+
let qlist = getqflist({'size' : 1, 'winid' : 1})
177+
if llist.size == 0 && qlist.size == 0
178+
echohl WarningMsg
179+
echon 'There is no errors!'
180+
echohl None
181+
return
182+
endif
183+
if llist.winid > 0
184+
lclose
185+
elseif qlist.winid > 0
186+
cclose
187+
elseif llist.size > 0
188+
botright lopen
189+
elseif qlist.size > 0
190+
botright copen
191+
endif
192+
if a:1 == 1
193+
wincmd w
194+
endif
191195
endif
192196
endfunction
193197

194198
function! s:jump_to_next_error() abort
195-
try
196-
lnext
197-
catch
199+
if SpaceVim#lsp#buf_server_ready()
200+
call SpaceVim#lsp#diagnostic_goto_next()
201+
else
198202
try
199-
ll
203+
lnext
200204
catch
201205
try
202-
cnext
206+
ll
203207
catch
204208
try
205-
cc
209+
cnext
206210
catch
207-
echohl WarningMsg
208-
echon 'There is no errors!'
209-
echohl None
211+
try
212+
cc
213+
catch
214+
echohl WarningMsg
215+
echon 'There is no errors!'
216+
echohl None
217+
endtry
210218
endtry
211219
endtry
212220
endtry
213-
endtry
221+
endif
214222
endfunction
215223

216224
function! s:jump_to_previous_error() abort
217-
try
218-
lprevious
219-
catch
225+
if SpaceVim#lsp#buf_server_ready()
226+
call SpaceVim#lsp#diagnostic_goto_prev()
227+
else
220228
try
221-
ll
229+
lprevious
222230
catch
223231
try
224-
cprevious
232+
ll
225233
catch
226234
try
227-
cc
235+
cprevious
228236
catch
229-
echohl WarningMsg
230-
echon 'There is no errors!'
231-
echohl None
237+
try
238+
cc
239+
catch
240+
echohl WarningMsg
241+
echon 'There is no errors!'
242+
echohl None
243+
endtry
232244
endtry
233245
endtry
234246
endtry
235-
endtry
247+
endif
236248
endfunction
237249

238250
let s:last_echoed_error = ''

autoload/SpaceVim/layers/lang/vim.vim

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ function! SpaceVim#layers#lang#vim#config() abort
101101
autocmd BufWritePost *.vim call s:generate_doc()
102102
augroup END
103103
endif
104+
" if the lsp layer is enabled, we should disable default linter
105+
if SpaceVim#layers#lsp#check_server('vimls') || SpaceVim#layers#lsp#check_filetype('vim')
106+
let g:neomake_vim_enabled_makers = []
107+
endif
104108
endfunction
105109

106110
function! s:on_exit(...) abort

autoload/SpaceVim/lsp.vim

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,18 @@ if (has('nvim-0.5.0') && s:NVIM_VERSION.is_release_version()) || has('nvim-0.6.0
5959
function! SpaceVim#lsp#remove_workspace_folder() abort
6060
lua vim.lsp.buf.remove_workspace_folder()
6161
endfunction
62+
function! SpaceVim#lsp#buf_server_ready() abort
63+
return v:lua.vim.lsp.buf.server_ready()
64+
endfunction
65+
function! SpaceVim#lsp#diagnostic_set_loclist() abort
66+
lua vim.lsp.diagnostic.set_loclist()
67+
endfunction
68+
function! SpaceVim#lsp#diagnostic_goto_next() abort
69+
lua vim.lsp.diagnostic.goto_next()
70+
endfunction
71+
function! SpaceVim#lsp#diagnostic_goto_prev() abort
72+
lua vim.lsp.diagnostic.goto_prev()
73+
endfunction
6274
elseif SpaceVim#layers#isLoaded('autocomplete') && get(g:, 'spacevim_autocomplete_method') ==# 'coc'
6375
" use coc.nvim
6476
let s:coc_language_servers = {}

0 commit comments

Comments
 (0)