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
```
### Default Options
**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
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,
git_icons = false,
diag_icons = true,
severity_icons = {
["Error"] = { icon = "", color = "red" },
["Warning"] = { icon = "", color = "yellow" },
["Information"] = { icon = "", color = "blue" },
["Hint"] = { icon = "", color = "magenta" },
},
-- by default icons and highlights are extracted from 'DiagnosticSignXXX'
-- and highlighted by a highlight group of the same name (which is usually
-- set by your colorscheme, for more info see:
-- :help DiagnosticSignHint'
-- :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:
-- 1 or "hint"
-- 2 or "information"

@ -338,6 +338,10 @@ Can also be called from a `.vim` file:
}
EOF
<
DEFAULT OPTIONS *fzf-lua-default-options*
**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
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,
git_icons = false,
diag_icons = true,
severity_icons = {
["Error"] = { icon = "", color = "red" },
["Warning"] = { icon = "", color = "yellow" },
["Information"] = { icon = "", color = "blue" },
["Hint"] = { icon = "", color = "magenta" },
},
-- by default icons and highlights are extracted from 'DiagnosticSignXXX'
-- and highlighted by a highlight group of the same name (which is usually
-- set by your colorscheme, for more info see:
-- :help DiagnosticSignHint'
-- :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:
-- 1 or "hint"
-- 2 or "information"

@ -519,12 +519,12 @@ M.globals.diagnostics = {
git_icons = false,
diag_icons = true,
_actions = function() return M.globals.actions.files end,
severity_icons = {
["Error"] = { icon = "", color = "red" },
["Warning"] = { icon = "", color = "yellow" },
["Information"] = { icon = "", color = "blue" },
["Hint"] = { icon = "", color = "magenta" },
},
-- signs = {
-- ["Error"] = { text = "e", texthl = "DiagnosticError" },
-- ["Warn"] = { text = "w", texthl = "DiagnosticWarn" },
-- ["Info"] = { text = "i", texthl = "DiagnosticInfo" },
-- ["Hint"] = { text = "h", texthl = "DiagnosticHint" },
-- },
}
M.globals.builtin = {
prompt = 'Builtin> ',
@ -736,10 +736,6 @@ function M.normalize_opts(opts, defaults)
opts[k] or {}, utils.tbl_deep_clone(M.globals[k]) or {})
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
-- also check if we need to override 'opts.prompt' from cli args
-- 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.scrollchar'] = 'previewers.builtin.scrollchar',
-- 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',
['severity_icons'] = 'lsp.icons',
}
-- recursive key loopkup, can also set new value

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

@ -235,6 +235,9 @@ local normalize_winopts = function(o)
winopts = vim.tbl_deep_extend("force", winopts, opts.winopts_raw())
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_height = vim.o.lines-vim.o.cmdheight-2
winopts.width = math.min(max_width, winopts.width)

Loading…
Cancel
Save