fix: error from unset LspDiagnosticSign & introduce opts.no_sign to lsp_*_diagnostics (#607)

This commit is contained in:
fdschmidt93
2021-03-04 21:53:41 +01:00
committed by GitHub
parent e7f724b437
commit 8369acea3e

View File

@@ -858,16 +858,25 @@ function make_entry.gen_from_lsp_diagnostics(opts)
opts = opts or {} opts = opts or {}
opts.tail_path = utils.get_default(opts.tail_path, true) opts.tail_path = utils.get_default(opts.tail_path, true)
local signs = {} local signs
for _, v in pairs(lsp_type_diagnostic) do if not opts.no_sign then
signs[v] = vim.trim(vim.fn.sign_getdefined("LspDiagnosticsSign" .. v)[1].text) signs = {}
for _, v in pairs(lsp_type_diagnostic) do
-- pcall to catch entirely unbound or cleared out sign hl group
local status, sign = pcall(
function() return vim.trim(vim.fn.sign_getdefined("LspDiagnosticsSign" .. v)[1].text) end)
if not status then
sign = v:sub(1,1)
end
signs[v] = sign
end
end end
local layout = { local layout = {
{ width = 9 }, { width = utils.if_nil(signs, 8, 10) },
{ remaining = true } { remaining = true }
} }
local line_width = utils.get_default(opts.line_width, 47) local line_width = utils.get_default(opts.line_width, 45)
if not opts.hide_filename then table.insert(layout, 2, {width = line_width}) end if not opts.hide_filename then table.insert(layout, 2, {width = line_width}) end
local displayer = entry_display.create { local displayer = entry_display.create {
separator = "", separator = "",
@@ -886,10 +895,10 @@ function make_entry.gen_from_lsp_diagnostics(opts)
end end
-- add styling of entries -- add styling of entries
local pos = string.format("%3d:%2d", entry.lnum, entry.col) local pos = string.format("%4d:%2d", entry.lnum, entry.col)
local line_info = { local line_info = {
string.format("%s %s", signs[entry.type], pos), (signs and signs[entry.type] .. " " or "") .. pos,
string.format("LspDiagnosticsDefault%s", entry.type) "LspDiagnosticsDefault" .. entry.type
} }
return displayer { return displayer {