diagWithinRange->add(diag)
endfor
+ # sort the diagnostics by line number and column number
var sortedDiags = diagWithinRange->sort((a, b) => {
var linediff = a.range.start.line - b.range.start.line
if linediff == 0
# Get all diagnostics from the LSP server for a particular line in a file
export def GetDiagsByLine(lspserver: dict<any>, bnr: number, lnum: number): list<dict<any>>
if lspserver.diagsMap->has_key(bnr)
- if lspserver.diagsMap[bnr].diagnosticsByLnum->has_key(lnum)
- return lspserver.diagsMap[bnr].diagnosticsByLnum[lnum]
+ var diagsbyLnum = lspserver.diagsMap[bnr].diagnosticsByLnum
+ if diagsbyLnum->has_key(lnum)
+ return diagsbyLnum[lnum]->sort((a, b) => {
+ return a.range.start.character - b.range.start.character
+ })
endif
endif
return []
return
endif
- # sort the diagnostics by line number
var diags = lspserver.diagsMap[bnr].sortedDiagnostics
if which == 'first'
setcursorcharpos(diags[0].range.start.line + 1, diags[0].range.start.character + 1)
+ DisplayDiag(diags[0])
return
endif
&& col < curcol))
|| (which == 'here' && (lnum == curlnum && col >= curcol))
setcursorcharpos(lnum, col)
- if (which == 'here')
- DisplayDiag(diag)
- endif
+ DisplayDiag(diag)
return
endif
endfor
- util.WarnMsg('Error: No more diagnostics found')
+ if which == 'here'
+ util.WarnMsg('Error: No more diagnostics found on this line')
+ else
+ util.WarnMsg('Error: No more diagnostics found')
+ endif
enddef
# Disable the LSP diagnostics highlighting in all the buffers
}
END
setline(1, lines)
- :sleep 1
- g:WaitForDiags(1)
+ g:WaitForServerFileLoad(1)
var bnr: number = bufnr()
:redraw!
:LspDiagShow
assert_match('No diagnostic messages found for', output[0])
g:LspOptionsSet({showDiagInPopup: true})
+ popup_clear()
:%bw!
enddef
}
END
setline(1, lines)
- sleep 1
+ g:WaitForServerFileLoad(0)
cursor(4, 1)
redraw!
:LspCodeAction 1
}
END
setline(1, lines2)
- sleep 1
+ g:WaitForServerFileLoad(0)
cursor(4, 1)
redraw!
:LspCodeAction use
}
END
setline(1, lines)
- sleep 1
+ g:WaitForServerFileLoad(0)
cursor(1, 1)
search('count')
redraw!
}
END
setline(1, lines)
- sleep 1
+ g:WaitForServerFileLoad(0)
# start a block-wise visual mode, LspSelectionExpand should change this to
# a characterwise visual mode.
exe "normal! 1G\<C-V>G\"_y"
}
END
setline(1, lines)
- :sleep 1
+ g:WaitForServerFileLoad(0)
cursor(1, 13)
:LspHighlight
var expected: dict<any>
}
END
setline(1, lines)
- :sleep 1
+ g:WaitForServerFileLoad(0)
cursor(8, 4)
:LspHover
var p: list<number> = popup_list()
}
END
setline(1, lines)
- :sleep 1
+ g:WaitForServerFileLoad(2)
cursor(8, 10)
:LspShowSignature
var p: list<number> = popup_list()
}
END
setline(1, lines)
- :sleep 1
+ g:WaitForServerFileLoad(0)
cursor(1, 1)
feedkeys(":LspSymbolSearch lsptest_funcB\<CR>\<CR>", "xt")
}
END
setline(1, lines)
- :sleep 1
+ g:WaitForServerFileLoad(0)
cursor(1, 6)
:LspIncomingCalls
assert_equal([1, 2], [winnr(), winnr('$')])
}
END
setline(1, lines)
- :sleep 1
+ g:WaitForServerFileLoad(0)
:LspOutline
assert_equal(2, winnr('$'))
var bnum = winbufnr(1)
END
writefile(lines, 'Xtest.c')
:silent! edit Xtest.c
- :sleep 1
+ g:WaitForServerFileLoad(1)
:setlocal tagfunc=lsp#lsp#TagFunc
cursor(3, 4)
:exe "normal \<C-]>"
}
END
setline(1, lines)
- :sleep 1
- g:WaitForDiags(0)
+ g:WaitForServerFileLoad(0)
setline(3, ' return:')
+ redraw!
g:WaitForDiags(1)
setline(3, ' return;')
+ redraw!
g:WaitForDiags(0)
:%bw!
autocmd_delete([{event: 'User', pattern: 'LspDiagsUpdated'}])
- assert_equal(3, g:LspAutoCmd)
+ assert_equal(6, g:LspAutoCmd)
enddef
# Test custom notification handlers
#define FOO 1
END
setline(1, lines)
- :sleep 1
+ g:WaitForServerFileLoad(0)
redraw!
feedkeys("G0i\<C-X>\<C-O>", 'xt')
return slept
endfunc
-# Wait for diagnostic messages from the LSP server
+# Wait for diagnostic messages from the LSP server.
+# Waits for a maximum of (10 * 1500) / 1000 seconds
def g:WaitForDiags(errCount: number)
var retries = 0
- while retries < 150
+ while retries < 1500
var d = lsp#lsp#ErrorCount()
if d.Error == errCount
break
endif
retries += 1
- :sleep 100m
+ :sleep 10m
endwhile
+
+ assert_equal(errCount, lsp#lsp#ErrorCount().Error)
+ if lsp#lsp#ErrorCount().Error != errCount
+ :LspDiagShow
+ assert_report(getloclist(0)->string())
+ :lclose
+ endif
+enddef
+
+# Wait for the LSP server to load and process a file. This works by waiting
+# for a certain number of diagnostic messages from the server.
+def g:WaitForServerFileLoad(diagCount: number)
+ redraw!
+ var waitCount = diagCount
+ if waitCount == 0
+ # Introduce a temporary diagnostic
+ append('$', '-')
+ redraw!
+ waitCount = 1
+ endif
+ g:WaitForDiags(waitCount)
+ if waitCount != diagCount
+ # Remove the temporary line
+ deletebufline('%', '$')
+ redraw!
+ g:WaitForDiags(0)
+ endif
enddef
# Start the language server. Returns true on success and false on failure.
var bnr: number = bufnr()
# This tests that two diagnostics can be on the same line
- var lines: list<string> = [
- ' export obj = {',
- ' foo: 1,',
- ' bar: 2,',
- ' baz: 3',
- ' }'
- ]
+ var lines: list<string> =<< trim END
+ export obj = {
+ foo: 1,
+ bar: 2,
+ baz; 3
+ }
+ END
setline(1, lines)
- :sleep 3
- g:WaitForDiags(2)
+ g:WaitForServerFileLoad(5)
:redraw!
:LspDiagShow
var qfl: list<dict<any>> = getloclist(0)
assert_equal('quickfix', getwinvar(winnr('$'), '&buftype'))
assert_equal(bnr, qfl[0].bufnr)
- assert_equal(2, qfl->len())
- assert_equal([1, 3, 'E'], [qfl[0].lnum, qfl[0].col, qfl[0].type])
- assert_equal([1, 10, 'E'], [qfl[1].lnum, qfl[1].col, qfl[1].type])
+ assert_equal(5, qfl->len())
+ assert_equal([1, 1, 'E'], [qfl[0].lnum, qfl[0].col, qfl[0].type])
+ assert_equal([1, 8, 'E'], [qfl[1].lnum, qfl[1].col, qfl[1].type])
+ assert_equal([4, 3, 'E'], [qfl[2].lnum, qfl[2].col, qfl[2].type])
close
:sleep 100m
- cursor(5, 1)
+ cursor(3, 1)
assert_equal('', execute('LspDiagPrev'))
- assert_equal([1, 10], [line('.'), col('.')])
+ assert_equal([1, 8], [line('.'), col('.')])
assert_equal('', execute('LspDiagPrev'))
- assert_equal([1, 3], [line('.'), col('.')])
+ assert_equal([1, 1], [line('.'), col('.')])
var output = execute('LspDiagPrev')->split("\n")
assert_equal('Error: No more diagnostics found', output[0])
cursor(5, 1)
assert_equal('', execute('LspDiagFirst'))
- assert_equal([1, 3], [line('.'), col('.')])
+ assert_equal([1, 1], [line('.'), col('.')])
assert_equal('', execute('LspDiagNext'))
- assert_equal([1, 10], [line('.'), col('.')])
+ assert_equal([1, 8], [line('.'), col('.')])
+ popup_clear()
- :normal! 0
+ # Test for :LspDiagHere on a line with multiple diagnostics
+ cursor(4, 1)
:LspDiagHere
- assert_equal([1, 3], [line('.'), col('.')])
- :normal! l
+ assert_equal([4, 3], [line('.'), col('.')])
+ var ids = popup_list()
+ assert_equal(1, ids->len())
+ assert_match('No value exists', getbufline(ids[0]->winbufnr(), 1, '$')[0])
+ popup_clear()
+ cursor(4, 4)
:LspDiagHere
- assert_equal([1, 10], [line('.'), col('.')])
+ assert_equal([4, 6], [line('.'), col('.')])
+ ids = popup_list()
+ assert_equal(1, ids->len())
+ assert_match("',' expected.", getbufline(ids[0]->winbufnr(), 1, '$')[0])
popup_clear()
+ # Line without diagnostics
+ cursor(3, 1)
+ output = execute('LspDiagHere')->split("\n")
+ assert_equal('Error: No more diagnostics found on this line', output[0])
+
g:LspOptionsSet({showDiagInPopup: false})
for i in range(1, 3)
- cursor(1, i)
+ cursor(4, i)
output = execute('LspDiagCurrent')->split('\n')
- assert_equal('Declaration or statement expected.', output[0])
+ assert_match('No value exists in scope', output[0])
endfor
- for i in range(4, 16)
- cursor(1, i)
+ for i in range(4, 8)
+ cursor(4, i)
output = execute('LspDiagCurrent')->split('\n')
- assert_equal('Cannot find name ''obj''.', output[0])
+ assert_equal("',' expected.", output[0])
endfor
g:LspOptionsSet({showDiagInPopup: true})
]
setline(1, lines)
- :sleep 3
+ g:WaitForServerFileLoad(0)
cursor(8, 1)
assert_equal('', execute('LspGotoDefinition'))