Fix for deprecated vim.lsp.diagnostic.get_all (#840)

This commit is contained in:
Jason Hansen
2021-12-12 04:34:05 -07:00
committed by GitHub
parent fd87c240df
commit 06a2b799c6

View File

@@ -1,7 +1,6 @@
local a = vim.api
local utils = require'nvim-tree.utils'
local view = require'nvim-tree.view'
local get_diagnostics = vim.lsp.diagnostic.get_all
local M = {}
@@ -35,7 +34,23 @@ end
local function from_nvim_lsp()
local buffer_severity = {}
for buf, diagnostics in pairs(get_diagnostics()) do
-- vim.lsp.diagnostic.get_all was deprecated in nvim 0.7 and replaced with vim.diagnostic.get
-- This conditional can be removed when the minimum required version of nvim is changed to 0.7.
if vim.diagnostic then
-- nvim version >= 0.7
for _, diagnostic in ipairs(vim.diagnostic.get()) do
local buf = diagnostic.bufnr
if a.nvim_buf_is_valid(buf) then
local bufname = a.nvim_buf_get_name(buf)
local lowest_severity = buffer_severity[bufname]
if not lowest_severity or diagnostic.severity < lowest_severity then
buffer_severity[bufname] = diagnostic.severity
end
end
end
else
-- nvim version < 0.7
for buf, diagnostics in pairs(vim.lsp.diagnostic.get_all()) do
if a.nvim_buf_is_valid(buf) then
local bufname = a.nvim_buf_get_name(buf)
if not buffer_severity[bufname] then
@@ -44,6 +59,7 @@ local function from_nvim_lsp()
end
end
end
end
return buffer_severity
end