]> Sergey Matveev's repositories - vim-lsp.git/commitdiff
Ignore invalid lnum and column for prop_add
authorAndreas Louv <andreas@louv.dk>
Thu, 30 Mar 2023 16:07:49 +0000 (18:07 +0200)
committerAndreas Louv <andreas@louv.dk>
Thu, 30 Mar 2023 17:41:17 +0000 (19:41 +0200)
Diagnostics arrive asynchronous and the document might have changed
before they reach the client.

This could cause the line number or column to be invalid when the
diagnostics arrive.

Ignoring these errors isn't a big deal as new diagnostics will be send
by the server shortly. And when there isn't any document changes, the
client will be updated ASAP.

autoload/lsp/diag.vim

index 4661ca75a945cae179527d5bf536b16e181f91fc..71b63e4b013917180ca757cbac14fb7a66798434 100644 (file)
@@ -111,22 +111,27 @@ def DiagsRefreshSigns(lspserver: dict<any>, bnr: number)
                                lnum: lnum,
                                name: DiagSevToSignName(diag.severity)})
 
-    if opt.lspOptions.highlightDiagInline
-      prop_add(diag.range.start.line + 1,
-               util.GetLineByteFromPos(bnr, diag.range.start) + 1,
-               {end_lnum: diag.range.end.line + 1,
-                 end_col: util.GetLineByteFromPos(bnr, diag.range.end) + 1,
-                 bufnr: bnr,
-                 type: DiagSevToInlineHLName(diag.severity)})
-    endif
+    try
+      if opt.lspOptions.highlightDiagInline
+        prop_add(diag.range.start.line + 1,
+                  util.GetLineByteFromPos(bnr, diag.range.start) + 1,
+                  {end_lnum: diag.range.end.line + 1,
+                    end_col: util.GetLineByteFromPos(bnr, diag.range.end) + 1,
+                    bufnr: bnr,
+                    type: DiagSevToInlineHLName(diag.severity)})
+      endif
 
-    if opt.lspOptions.showDiagWithVirtualText
-      prop_add(lnum, 0, {bufnr: bnr,
-                        type: 'LspDiagVirtualText',
-                        text: $'┌─ {diag.message}',
-                        text_align: 'above',
-                        text_padding_left: diag.range.start.character})
-    endif
+      if opt.lspOptions.showDiagWithVirtualText
+        prop_add(lnum, 0, {bufnr: bnr,
+                           type: 'LspDiagVirtualText',
+                           text: $'┌─ {diag.message}',
+                           text_align: 'above',
+                           text_padding_left: diag.range.start.character})
+      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.
+    endtry
   endfor
 
   signs->sign_placelist()