All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@git.madduck.net.
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
1 " Returns a diagnostic object, or empty dictionary if no diagnostics are
4 " 'server': '', " optional
6 function! lsp#internal#diagnostics#under_cursor#get_diagnostic(...) abort
7 let l:options = get(a:000, 0, {})
8 let l:server = get(l:options, 'server', '')
9 let l:bufnr = bufnr('%')
11 if !lsp#internal#diagnostics#state#_is_enabled_for_buffer(l:bufnr)
15 let l:uri = lsp#utils#get_buffer_uri(l:bufnr)
17 let l:diagnostics_by_server = lsp#internal#diagnostics#state#_get_all_diagnostics_grouped_by_server_for_uri(l:uri)
18 let l:diagnostics = []
20 for l:item in values(l:diagnostics_by_server)
21 let l:diagnostics += lsp#utils#iteratable(l:item['params']['diagnostics'])
24 if has_key(l:diagnostics_by_server, l:server)
25 let l:diagnostics = lsp#utils#iteratable(l:diagnostics_by_server[l:server]['params']['diagnostics'])
29 let l:line = line('.')
32 let l:closest_diagnostic = {}
33 let l:closest_distance = -1
35 for l:diagnostic in l:diagnostics
36 let [l:start_line, l:start_col] = lsp#utils#position#lsp_to_vim('%', l:diagnostic['range']['start'])
38 if l:line == l:start_line
39 let l:distance = abs(l:start_col - l:col)
40 if l:closest_distance < 0 || l:distance < l:closest_distance
41 let l:closest_diagnostic = l:diagnostic
42 let l:closest_distance = l:distance
47 return l:closest_diagnostic