Skip to content

Commit 7c43b01

Browse files
refactor diagnostics get buffer first error line to use the new internal state (#1003)
1 parent e846a99 commit 7c43b01

File tree

3 files changed

+27
-15
lines changed

3 files changed

+27
-15
lines changed

autoload/lsp.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1125,7 +1125,7 @@ endfunction
11251125

11261126
" Return first error line or v:null if there are no errors
11271127
function! lsp#get_buffer_first_error_line() abort
1128-
return lsp#ui#vim#diagnostics#get_buffer_first_error_line()
1128+
return lsp#internal#diagnostics#first_line#get_first_error_line({'bufnr': bufnr('%')})
11291129
endfunction
11301130

11311131
" Return UI list with window/workDoneProgress
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
" Return first error line or v:null if there are no errors
2+
" available.
3+
" options = {
4+
" 'bufnr': '', " optional
5+
" }
6+
function! lsp#internal#diagnostics#first_line#get_first_error_line(options) abort
7+
let l:bufnr = get(a:options, 'bufnr', bufnr('%'))
8+
9+
if !lsp#internal#diagnostics#state#_is_enabled_for_buffer(l:bufnr)
10+
return v:null
11+
endif
12+
13+
let l:uri = lsp#utils#get_buffer_uri(l:bufnr)
14+
let l:diagnostics_by_server = lsp#internal#diagnostics#state#_get_all_diagnostics_grouped_by_server_for_uri(l:uri)
15+
16+
let l:first_error_line = v:null
17+
for l:diagnostics_response in values(l:diagnostics_by_server)
18+
for l:diagnostics in l:diagnostics_response['params']['diagnostics']
19+
let l:severity = get(l:diagnostics, 'severity', 1)
20+
if l:severity ==# 1 && (l:first_error_line ==# v:null || l:first_error_line ># l:diagnostics['range']['start']['line'])
21+
let l:first_error_line = l:diagnostics['range']['start']['line']
22+
endif
23+
endfor
24+
endfor
25+
return l:first_error_line ==# v:null ? v:null : l:first_error_line + 1
26+
endfunction

autoload/lsp/ui/vim/diagnostics.vim

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -208,18 +208,4 @@ function! s:compare_diagnostics(d1, d2) abort
208208
return l:line1 > l:line2 ? 1 : -1
209209
endif
210210
endfunction
211-
212-
function! lsp#ui#vim#diagnostics#get_buffer_first_error_line() abort
213-
let l:uri = lsp#utils#get_buffer_uri()
214-
let [l:has_diagnostics, l:diagnostics] = s:get_diagnostics(l:uri)
215-
let l:first_error_line = v:null
216-
for [l:server_name, l:data] in items(l:diagnostics)
217-
for l:diag in l:data['response']['params']['diagnostics']
218-
if s:severity_of(l:diag) ==# 1 && (l:first_error_line ==# v:null || l:first_error_line ># l:diag['range']['start']['line'])
219-
let l:first_error_line = l:diag['range']['start']['line']
220-
endif
221-
endfor
222-
endfor
223-
return l:first_error_line ==# v:null ? v:null : l:first_error_line + 1
224-
endfunction
225211
" vim sw=4 ts=4 et

0 commit comments

Comments
 (0)