autoload/lsp/diag.vim | 54 +++++++++++++++++++++++++++++++++-------------------- test/runner.vim | 2 +- diff --git a/autoload/lsp/diag.vim b/autoload/lsp/diag.vim index 33c7fe8b2c2ddf6fb992c3256f0320cb0ef605fa..dd902be8705bb9536de098b5ad572d27c885a1ed 100644 --- a/autoload/lsp/diag.vim +++ b/autoload/lsp/diag.vim @@ -127,17 +127,21 @@ setbufvar(bnr, '&balloonexpr', 'g:LspDiagExpr()') endif enddef +# Function to sort the diagnostics in ascending order based on the line and +# character offset +def DiagsSortFunc(a: dict, b: dict): number + var a_start: dict = a.range.start + var b_start: dict = b.range.start + var linediff: number = a_start.line - b_start.line + if linediff == 0 + return a_start.character - b_start.character + endif + return linediff +enddef + # Sort diagnostics ascending based on line and character offset def SortDiags(diags: list>): list> - return diags->sort((a, b) => { - var a_start = a.range.start - var b_start = b.range.start - var linediff = a_start.line - b_start.line - if linediff == 0 - return a_start.character - b_start.character - endif - return linediff - }) + return diags->sort(DiagsSortFunc) enddef # Remove the diagnostics stored for buffer "bnr" @@ -255,6 +259,7 @@ endif var signs: list> = [] var diags: list> = diagsMap[bnr].sortedDiagnostics + var inlineHLprops: list>> = [[], [], [], [], []] for diag in diags # TODO: prioritize most important severity if there are multiple # diagnostics from the same line @@ -270,15 +275,14 @@ endif try if lspOpts.highlightDiagInline - prop_add(lnum, util.GetLineByteFromPos(bnr, d_start) + 1, - {end_lnum: d_end.line + 1, - end_col: util.GetLineByteFromPos(bnr, d_end) + 1, - bufnr: bnr, - type: DiagSevToInlineHLName(diag.severity)}) + var propLocation: list = [ + lnum, util.GetLineByteFromPos(bnr, d_start) + 1, + d_end.line + 1, util.GetLineByteFromPos(bnr, d_end) + 1 + ] + inlineHLprops[diag.severity]->add(propLocation) endif if lspOpts.showDiagWithVirtualText - var padding: number var symbol: string = diag_symbol @@ -301,10 +305,22 @@ text_wrap: diag_wrap, text_padding_left: padding}) endif catch /E966\|E964/ # Invalid lnum | Invalid col - # Diagnostics arrive asynchronous and the document changed while they - # wore send. Ignore this as new once will arrive shortly. + # Diagnostics arrive asynchronously and the document changed while they + # were in transit. Ignore this as new once will arrive shortly. endtry endfor + + if lspOpts.highlightDiagInline + for i in range(1, 4) + if !inlineHLprops[i]->empty() + try + prop_add_list({bufnr: bnr, type: DiagSevToInlineHLName(i)}, + inlineHLprops[i]) + catch /E966\|E964/ # Invalid lnum | Invalid col + endtry + endif + endfor + endif if lspOpts.showDiagWithSign signs->sign_placelist() @@ -426,9 +442,7 @@ # store the diagnostic for each line separately var joinedServerDiags: list> = [] for diags in serverDiags->values() - for diag in diags - joinedServerDiags->add(diag) - endfor + joinedServerDiags->extend(diags) endfor var sortedDiags = SortDiags(joinedServerDiags) diff --git a/test/runner.vim b/test/runner.vim index f706b275670b4778909f1b306d2549e5f2a74601..14c849a388d460a482fd079557f0813ae4cf5c50 100644 --- a/test/runner.vim +++ b/test/runner.vim @@ -47,7 +47,7 @@ exe $'source {g:TestName}' g:StartLangServer() LspRunTests() catch - writefile([$'FAIL: Tests in {g:TestName} failed with exception {v:exception} at {v:throwpoint} '], 'results.txt', 'a') + writefile(['FAIL: Tests in ' .. g:TestName .. ' failed with exception ' .. v:exception .. ' at ' .. v:throwpoint], 'results.txt', 'a') endtry qall!