~jeanmertz


#48 nvim-lint diagnostics not always shown by lsp_lines 1 year, 1 month ago

Comment by ~jeanmertz on ~whynothugo/lsp_lines.nvim

Here's a patch that renders a bit better due to keeping existing variable names:

diff --git a/lua/lsp_lines/init.lua b/lua/lsp_lines/init.lua
index a0d8b6e..069338e 100644
--- a/lua/lsp_lines/init.lua
+++ b/lua/lsp_lines/init.lua
@@ -2,17 +2,9 @@ local M = {}
 
 local render = require("lsp_lines.render")
 
-local function render_current_line(diagnostics, ns, bufnr, opts)
-  local current_line_diag = {}
+local function render_current_line(ns, bufnr, opts)
   local lnum = vim.api.nvim_win_get_cursor(0)[1] - 1
-
-  for _, diagnostic in pairs(diagnostics) do
-    local show = diagnostic.end_lnum and (lnum >= diagnostic.lnum and lnum <= diagnostic.end_lnum)
-      or (lnum == diagnostic.lnum)
-    if show then
-      table.insert(current_line_diag, diagnostic)
-    end
-  end
+  local current_line_diag = vim.diagnostic.get(bufnr, { lnum = lnum })
 
   render.show(ns, bufnr, current_line_diag, opts)
 end
@@ -45,12 +37,12 @@ M.setup = function()
         vim.api.nvim_create_autocmd("CursorMoved", {
           buffer = bufnr,
           callback = function()
-            render_current_line(diagnostics, ns.user_data.virt_lines_ns, bufnr, opts)
+            render_current_line(ns.user_data.virt_lines_ns, bufnr, opts)
           end,
           group = "LspLines",
         })
         -- Also show diagnostics for the current line before the first CursorMoved event
-        render_current_line(diagnostics, ns.user_data.virt_lines_ns, bufnr, opts)
+        render_current_line(ns.user_data.virt_lines_ns, bufnr, opts)
       else
         render.show(ns.user_data.virt_lines_ns, bufnr, diagnostics, opts)
       end

#48 nvim-lint diagnostics not always shown by lsp_lines 1 year, 1 month ago

Ticket created by ~jeanmertz on ~whynothugo/lsp_lines.nvim

Initially I thought my issue was similar to #45, but it turns out my issue was a different one.

Specifically, if I set only_current_line, then (I assume) the asynchronous nature of nvim-lint means that not all diagnostics are caught and can be shown by lsp_lines.nvim.

I've applied the following patch locally, after which I have had no issues since (I don't know how recent these Neovim APIs are, I am running a recent 0.10 build):

diff --git a/lua/lsp_lines/init.lua b/lua/lsp_lines/init.lua
index a0d8b6e..1a74959 100644
--- a/lua/lsp_lines/init.lua
+++ b/lua/lsp_lines/init.lua
@@ -2,19 +2,11 @@ local M = {}
 
 local render = require("lsp_lines.render")
 
-local function render_current_line(diagnostics, ns, bufnr, opts)
-  local current_line_diag = {}
+local function render_current_line(ns, bufnr, opts)
   local lnum = vim.api.nvim_win_get_cursor(0)[1] - 1
+  local diag = vim.diagnostic.get(bufnr, { lnum = lnum })
 
-  for _, diagnostic in pairs(diagnostics) do
-    local show = diagnostic.end_lnum and (lnum >= diagnostic.lnum and lnum <= diagnostic.end_lnum)
-      or (lnum == diagnostic.lnum)
-    if show then
-      table.insert(current_line_diag, diagnostic)
-    end
-  end
-
-  render.show(ns, bufnr, current_line_diag, opts)
+  render.show(ns, bufnr, diag, opts)
 end
 
 ---@class Opts
@@ -45,12 +37,12 @@ M.setup = function()
         vim.api.nvim_create_autocmd("CursorMoved", {
           buffer = bufnr,
           callback = function()
-            render_current_line(diagnostics, ns.user_data.virt_lines_ns, bufnr, opts)
+            render_current_line(ns.user_data.virt_lines_ns, bufnr, opts)
           end,
           group = "LspLines",
         })
         -- Also show diagnostics for the current line before the first CursorMoved event
-        render_current_line(diagnostics, ns.user_data.virt_lines_ns, bufnr, opts)
+        render_current_line(ns.user_data.virt_lines_ns, bufnr, opts)
       else
         render.show(ns.user_data.virt_lines_ns, bufnr, diagnostics, opts)
       end