return
endif
- # Conver to Ale's diagnostics format (:h ale-loclist-format)
+ # Convert to Ale's diagnostics format (:h ale-loclist-format)
ale#other_source#ShowResults(bnr, 'lsp', diagsMap[bnr].sortedDiagnostics->mapnew((_, v) => {
return {text: v.message,
lnum: v.range.start.line + 1,
endfor
enddef
+# Return the sorted diagnostics for buffer "bnr". Default is the current
+# buffer. A copy of the diagnostics is returned so that the caller can modify
+# the diagnostics.
+export def GetDiagsForBuf(bnr: number = bufnr()): list<dict<any>>
+ if !diagsMap->has_key(bnr) ||
+ diagsMap[bnr].sortedDiagnostics->empty()
+ return []
+ endif
+
+ return diagsMap[bnr].sortedDiagnostics->deepcopy()
+enddef
+
# vim: tabstop=8 shiftwidth=2 softtabstop=2
message area instead, you can set the 'showDiagInPopup' option to false. By
default this is set to true.
+The lsp#diag#GetDiagsForBuf() function can be used to get all the LSP
+diagnostics in a buffer. This function optionally accepts a buffer number.
+If the buffer number argument is not specified, then the current buffer is
+used. This function returns a |List| of diagnostics sorted by their line and
+column number. Each diagnostic is a |Dict| returned by the language server.
+
==============================================================================
8. Tag Function *lsp-tagfunc*
var bnr = bufnr()
g:WaitForServerFileLoad(1)
:redraw!
+ var d = lsp#diag#GetDiagsForBuf()[0]
+ assert_equal({start: {line: 0, character: 5}, end: {line: 0, character: 6}},
+ d.range)
:LspDiagShow
assert_equal(1, line('$'))
setline(2, 'int j:')
redraw!
g:WaitForDiags(2)
+ var l = lsp#diag#GetDiagsForBuf()
+ assert_equal({start: {line: 0, character: 5}, end: {line: 0, character: 6}},
+ l[0].range)
+ assert_equal({start: {line: 1, character: 5}, end: {line: 1, character: 6}},
+ l[1].range)
wincmd w
assert_equal(2, line('$'))
wincmd w
deletebufline('', 1, '$')
redraw!
g:WaitForDiags(0)
+ assert_equal([], lsp#diag#GetDiagsForBuf())
wincmd w
assert_equal([''], getline(1, '$'))
:lclose