aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/diagnostic.lua
diff options
context:
space:
mode:
authorGregory Anders <greg@gpanders.com>2021-11-15 08:56:10 -0700
committerGregory Anders <greg@gpanders.com>2021-11-15 09:12:27 -0700
commit63413bd0478ebbb2aa5fc90b2533a04d8b785bbc (patch)
tree928fbbd8e1979078da4986ce278be77b2e01e4a4 /runtime/lua/vim/diagnostic.lua
parentcc488376221e3792a2c69d1507bdfe405eaebc73 (diff)
downloadrneovim-63413bd0478ebbb2aa5fc90b2533a04d8b785bbc.tar.gz
rneovim-63413bd0478ebbb2aa5fc90b2533a04d8b785bbc.tar.bz2
rneovim-63413bd0478ebbb2aa5fc90b2533a04d8b785bbc.zip
refactor(diagnostic)!: rename 'show_header' to 'header'
Rename the `show_header` option in `open_float` to simply `header` and allow users to specify both the header string as well as the highlight group.
Diffstat (limited to 'runtime/lua/vim/diagnostic.lua')
-rw-r--r--runtime/lua/vim/diagnostic.lua28
1 files changed, 21 insertions, 7 deletions
diff --git a/runtime/lua/vim/diagnostic.lua b/runtime/lua/vim/diagnostic.lua
index c5cb08fb2d..80efa20f27 100644
--- a/runtime/lua/vim/diagnostic.lua
+++ b/runtime/lua/vim/diagnostic.lua
@@ -534,7 +534,9 @@ end
--- its severity. Otherwise, all signs use the same priority.
--- - float: Options for floating windows:
--- * severity: See |diagnostic-severity|.
---- * show_header: (boolean, default true) Show "Diagnostics:" header
+--- * header: (string or table) String to use as the header for the floating
+--- window. If a table, it is interpreted as a [text, hl_group] tuple.
+--- Defaults to "Diagnostics:".
--- * source: (string) Include the diagnostic source in
--- the message. One of "always" or "if_many".
--- * format: (function) A function that takes a diagnostic as input and returns a
@@ -1146,8 +1148,9 @@ end
--- from |vim.diagnostic.config()|.
--- - severity: See |diagnostic-severity|. Overrides the setting from
--- |vim.diagnostic.config()|.
---- - show_header: (boolean, default true) Show "Diagnostics:" header. Overrides the
---- setting from |vim.diagnostic.config()|.
+--- - header: (string or table) String to use as the header for the floating window. If a
+--- table, it is interpreted as a [text, hl_group] tuple. Overrides the setting
+--- from |vim.diagnostic.config()|.
--- - source: (string) Include the diagnostic source in the message. One of "always" or
--- "if_many". Overrides the setting from |vim.diagnostic.config()|.
--- - format: (function) A function that takes a diagnostic as input and returns a
@@ -1225,10 +1228,21 @@ function M.open_float(bufnr, opts)
local lines = {}
local highlights = {}
- local show_header = vim.F.if_nil(opts.show_header, true)
- if show_header then
- table.insert(lines, "Diagnostics:")
- table.insert(highlights, {0, "Bold"})
+ local header = if_nil(opts.header, "Diagnostics:")
+ if header then
+ vim.validate { header = { header, function(v)
+ return type(v) == "string" or type(v) == "table"
+ end, "'string' or 'table'" } }
+ if type(header) == "table" then
+ -- Don't insert any lines for an empty string
+ if string.len(if_nil(header[1], "")) > 0 then
+ table.insert(lines, header[1])
+ table.insert(highlights, {0, header[2] or "Bold"})
+ end
+ elseif #header > 0 then
+ table.insert(lines, header)
+ table.insert(highlights, {0, "Bold"})
+ end
end
if opts.format then