feat(diagnostics): extract icons|highlights from neovim signs

main
bhagwan 2 years ago
parent 236b305a18
commit a2c7d7863c

@ -298,6 +298,8 @@ require('fzf-lua').setup{
EOF EOF
``` ```
### Default Options
**Below is a list of most (still, not all default settings), please also **Below is a list of most (still, not all default settings), please also
consult the issues if there's something you need and you can't find as there consult the issues if there's something you need and you can't find as there
have been many obscure requests which have been fulfilled and are yet to be have been many obscure requests which have been fulfilled and are yet to be
@ -831,12 +833,19 @@ require'fzf-lua'.setup {
file_icons = true, file_icons = true,
git_icons = false, git_icons = false,
diag_icons = true, diag_icons = true,
severity_icons = { -- by default icons and highlights are extracted from 'DiagnosticSignXXX'
["Error"] = { icon = "", color = "red" }, -- and highlighted by a highlight group of the same name (which is usually
["Warning"] = { icon = "", color = "yellow" }, -- set by your colorscheme, for more info see:
["Information"] = { icon = "", color = "blue" }, -- :help DiagnosticSignHint'
["Hint"] = { icon = "", color = "magenta" }, -- :help hl-DiagnosticSignHint'
}, -- only uncomment below if you wish to override the signs/highlights
-- define only text, texthl or both (':help sign_define()' for more info)
-- signs = {
-- ["Error"] = { text = "", texthl = "DiagnosticError" },
-- ["Warn"] = { text = "", texthl = "DiagnosticWarn" },
-- ["Info"] = { text = "", texthl = "DiagnosticInfo" },
-- ["Hint"] = { text = "", texthl = "DiagnosticHint" },
-- },
-- limit to specific severity, use either a string or num: -- limit to specific severity, use either a string or num:
-- 1 or "hint" -- 1 or "hint"
-- 2 or "information" -- 2 or "information"

@ -338,6 +338,10 @@ Can also be called from a `.vim` file:
} }
EOF EOF
< <
DEFAULT OPTIONS *fzf-lua-default-options*
**Below is a list of most (still, not all default settings), please also **Below is a list of most (still, not all default settings), please also
consult the issues if there's something you need and you can't find as there consult the issues if there's something you need and you can't find as there
have been many obscure requests which have been fulfilled and are yet to be have been many obscure requests which have been fulfilled and are yet to be
@ -868,12 +872,19 @@ open an issue and I'll be more than happy to help.**
file_icons = true, file_icons = true,
git_icons = false, git_icons = false,
diag_icons = true, diag_icons = true,
severity_icons = { -- by default icons and highlights are extracted from 'DiagnosticSignXXX'
["Error"] = { icon = "", color = "red" }, -- and highlighted by a highlight group of the same name (which is usually
["Warning"] = { icon = "", color = "yellow" }, -- set by your colorscheme, for more info see:
["Information"] = { icon = "", color = "blue" }, -- :help DiagnosticSignHint'
["Hint"] = { icon = "", color = "magenta" }, -- :help hl-DiagnosticSignHint'
}, -- only uncomment below if you wish to override the signs/highlights
-- define only text, texthl or both (':help sign_define()' for more info)
-- signs = {
-- ["Error"] = { text = "", texthl = "DiagnosticError" },
-- ["Warn"] = { text = "", texthl = "DiagnosticWarn" },
-- ["Info"] = { text = "", texthl = "DiagnosticInfo" },
-- ["Hint"] = { text = "", texthl = "DiagnosticHint" },
-- },
-- limit to specific severity, use either a string or num: -- limit to specific severity, use either a string or num:
-- 1 or "hint" -- 1 or "hint"
-- 2 or "information" -- 2 or "information"

@ -519,12 +519,12 @@ M.globals.diagnostics = {
git_icons = false, git_icons = false,
diag_icons = true, diag_icons = true,
_actions = function() return M.globals.actions.files end, _actions = function() return M.globals.actions.files end,
severity_icons = { -- signs = {
["Error"] = { icon = "", color = "red" }, -- ["Error"] = { text = "e", texthl = "DiagnosticError" },
["Warning"] = { icon = "", color = "yellow" }, -- ["Warn"] = { text = "w", texthl = "DiagnosticWarn" },
["Information"] = { icon = "", color = "blue" }, -- ["Info"] = { text = "i", texthl = "DiagnosticInfo" },
["Hint"] = { icon = "", color = "magenta" }, -- ["Hint"] = { text = "h", texthl = "DiagnosticHint" },
}, -- },
} }
M.globals.builtin = { M.globals.builtin = {
prompt = 'Builtin> ', prompt = 'Builtin> ',
@ -736,10 +736,6 @@ function M.normalize_opts(opts, defaults)
opts[k] or {}, utils.tbl_deep_clone(M.globals[k]) or {}) opts[k] or {}, utils.tbl_deep_clone(M.globals[k]) or {})
end end
-- overwrite highlights if supplied by the caller/provider setup
opts.winopts.__hl = vim.tbl_deep_extend("force",
opts.winopts.__hl, opts.winopts.hl or {})
-- these options are copied from globals unless specifically set -- these options are copied from globals unless specifically set
-- also check if we need to override 'opts.prompt' from cli args -- also check if we need to override 'opts.prompt' from cli args
-- if we don't override 'opts.prompt' 'FzfWin.save_query' will -- if we don't override 'opts.prompt' 'FzfWin.save_query' will
@ -827,11 +823,7 @@ function M.normalize_opts(opts, defaults)
['winopts.preview.scrollbar'] = 'previewers.builtin.scrollbar', ['winopts.preview.scrollbar'] = 'previewers.builtin.scrollbar',
['winopts.preview.scrollchar'] = 'previewers.builtin.scrollchar', ['winopts.preview.scrollchar'] = 'previewers.builtin.scrollchar',
-- Diagnostics & LSP symbols separation options -- Diagnostics & LSP symbols separation options
['symbol_fmt'] = 'lsp.symbol_fmt',
['symbol_style'] = 'lsp.symbol_style',
['symbol_hl_prefix'] = 'lsp.symbol_hl_prefix',
['diag_icons'] = 'lsp.lsp_icons', ['diag_icons'] = 'lsp.lsp_icons',
['severity_icons'] = 'lsp.icons',
} }
-- recursive key loopkup, can also set new value -- recursive key loopkup, can also set new value

@ -47,16 +47,31 @@ M.diagnostics = function(opts)
end end
end end
-- normalize the LSP icons table -- configure signs and highlights
opts._severity_icons = {} local signs = vim.diagnostic and {
for k, v in pairs({ ["Error"] = { severity = 1, default = "E", sign = "DiagnosticSignError" },
["Error"] = 1, ["Warn"] = { severity = 2, default = "W", sign = "DiagnosticSignWarn" },
["Warning"] = 2, ["Info"] = { severity = 3, default = "I", sign = "DiagnosticSignInfo" },
["Information"] = 3, ["Hint"] = { severity = 4, default = "H", sign = "DiagnosticSignHint" },
["Hint"] = 4 } or {
}) do -- At one point or another wdefault = "E", e'll drop support for the old LSP diag
if opts.severity_icons and opts.severity_icons[k] then ["Error"] = { severity = 1, default = "E", sign = "LspDiagnosticsSignError" },
opts._severity_icons[v] = opts.severity_icons[k] ["Warn"] = { severity = 2, default = "W", sign = "LspDiagnosticsSignWarning" },
["Info"] = { severity = 3, default = "I", sign = "LspDiagnosticsSignInformation" },
["Hint"] = { severity = 4, default = "H", sign = "LspDiagnosticsSignHint" },
}
opts.__signs = {}
for k, v in pairs(signs) do
opts.__signs[v.severity] = {}
local sign_def = vim.fn.sign_getdefined(v.sign)
opts.__signs[v.severity].text = sign_def and sign_def[1].text or v.default
opts.__signs[v.severity].texthl = sign_def and sign_def[1].texthl or nil
if opts.signs and opts.signs[k] and opts.signs[k].text then
opts.__signs[v.severity].text = opts.signs[k].text
end
if opts.signs and opts.signs[k] and opts.signs[k].texthl then
opts.__signs[v.severity].texthl = opts.signs[k].texthl
end end
end end
@ -149,11 +164,11 @@ M.diagnostics = function(opts)
coroutine.resume(co) coroutine.resume(co)
else else
local type = diag_entry.type local type = diag_entry.type
if opts.diag_icons and opts._severity_icons[type] then if opts.diag_icons and opts.__signs[type] then
local severity = opts._severity_icons[type] local value = opts.__signs[type]
local icon = severity.icon local icon = value.text
if opts.color_icons then if opts.color_icons then
icon = utils.ansi_codes[severity.color or "dark_grey"](icon) icon = utils.ansi_from_hl(value.texthl, icon)
end end
entry = icon .. utils.nbsp .. utils.nbsp .. entry entry = icon .. utils.nbsp .. utils.nbsp .. entry
end end

@ -235,6 +235,9 @@ local normalize_winopts = function(o)
winopts = vim.tbl_deep_extend("force", winopts, opts.winopts_raw()) winopts = vim.tbl_deep_extend("force", winopts, opts.winopts_raw())
end end
-- overwrite highlights if supplied by the caller/provider setup
winopts.__hl = vim.tbl_deep_extend("force", winopts.__hl, winopts.hl or {})
local max_width = vim.o.columns-2 local max_width = vim.o.columns-2
local max_height = vim.o.lines-vim.o.cmdheight-2 local max_height = vim.o.lines-vim.o.cmdheight-2
winopts.width = math.min(max_width, winopts.width) winopts.width = math.min(max_width, winopts.width)

Loading…
Cancel
Save