From a2c7d7863cf08eebfda40d08625c67225db4ea97 Mon Sep 17 00:00:00 2001 From: bhagwan Date: Thu, 7 Jul 2022 14:27:08 -0700 Subject: [PATCH] feat(diagnostics): extract icons|highlights from neovim signs --- README.md | 21 ++++++++++---- doc/fzf-lua.txt | 23 +++++++++++---- lua/fzf-lua/config.lua | 20 ++++--------- lua/fzf-lua/providers/diagnostic.lua | 43 +++++++++++++++++++--------- lua/fzf-lua/win.lua | 3 ++ 5 files changed, 70 insertions(+), 40 deletions(-) diff --git a/README.md b/README.md index e311be3..9ab7650 100644 --- a/README.md +++ b/README.md @@ -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" diff --git a/doc/fzf-lua.txt b/doc/fzf-lua.txt index 59188d8..0916e50 100644 --- a/doc/fzf-lua.txt +++ b/doc/fzf-lua.txt @@ -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" diff --git a/lua/fzf-lua/config.lua b/lua/fzf-lua/config.lua index 5c26961..c1c7de5 100644 --- a/lua/fzf-lua/config.lua +++ b/lua/fzf-lua/config.lua @@ -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 diff --git a/lua/fzf-lua/providers/diagnostic.lua b/lua/fzf-lua/providers/diagnostic.lua index e0eacbb..9dcb53f 100644 --- a/lua/fzf-lua/providers/diagnostic.lua +++ b/lua/fzf-lua/providers/diagnostic.lua @@ -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 diff --git a/lua/fzf-lua/win.lua b/lua/fzf-lua/win.lua index 73efd17..18a9342 100644 --- a/lua/fzf-lua/win.lua +++ b/lua/fzf-lua/win.lua @@ -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)