Skip to content

Commit 291360f

Browse files
authored
fix(config): normalize partial table configs, fix multiple diagnostics icons, add support overriding open_float (#172)
* fix(config): remove inconsistent config instantiations * fix(config): support overriding open_float with config option * fix(config): support overriding open_float * Update README.md * Update vimdoc
1 parent a536798 commit 291360f

5 files changed

Lines changed: 70 additions & 40 deletions

File tree

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,17 @@ vim.keymap.set("n", "<leader>dt", "<cmd>TinyInlineDiag toggle<cr>", { desc = "To
358358

359359
### Auto-Disable on Float
360360

361-
To automatically hide inline diagnostics when opening Neovim's diagnostic float windows, override the function to disable diagnostics before opening the float and re-enable them after closing.
361+
To automatically hide inline diagnostics when opening Neovim's diagnostic float windows, enable the `override_open_float` option:
362+
363+
```lua
364+
require("tiny-inline-diagnostic").setup({
365+
options = {
366+
override_open_float = true,
367+
},
368+
})
369+
```
370+
371+
Alternatively, you can manually override the function:
362372

363373
```lua
364374
vim.diagnostic.open_float = require("tiny-inline-diagnostic.override").open_float

doc/tiny-inline-diagnostic.nvim.txt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,8 +390,17 @@ You can map these to keybindings for quick access:
390390
AUTO-DISABLE ON FLOAT ~
391391

392392
To automatically hide inline diagnostics when opening Neovim’s diagnostic
393-
float windows, override the function to disable diagnostics before opening the
394-
float and re-enable them after closing.
393+
float windows, enable the `override_open_float` option:
394+
395+
>lua
396+
require("tiny-inline-diagnostic").setup({
397+
options = {
398+
override_open_float = true,
399+
},
400+
})
401+
<
402+
403+
Alternatively, you can manually override the function:
395404

396405
>lua
397406
vim.diagnostic.open_float = require("tiny-inline-diagnostic.override").open_float

lua/tiny-inline-diagnostic/chunk.lua

Lines changed: 15 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,7 @@ function M.get_header_from_chunk(
7070
vim.list_extend(virt_texts, { { icon, diag_hi } })
7171

7272
local cursor_line = vim.api.nvim_win_get_cursor(0)[1] - 1
73-
local add_messages_opts = type(opts.options.add_messages) == "table" and opts.options.add_messages
74-
or {
75-
messages = opts.options.add_messages,
76-
display_count = false,
77-
use_max_severity = false,
78-
show_multiple_glyphs = true,
79-
}
73+
local add_messages_opts = opts.options.add_messages
8074

8175
local add_messages = add_messages_opts.messages
8276
local display_count = add_messages_opts.display_count
@@ -130,13 +124,7 @@ function M.add_severity_icons(virt_texts, opts, severities, diag_hi)
130124
return
131125
end
132126

133-
local add_messages_opts = type(opts.options.add_messages) == "table" and opts.options.add_messages
134-
or {
135-
messages = opts.options.add_messages,
136-
display_count = false,
137-
use_max_severity = false,
138-
show_multiple_glyphs = true,
139-
}
127+
local add_messages_opts = opts.options.add_messages
140128

141129
local show_multiple_glyphs = add_messages_opts.show_multiple_glyphs
142130
local use_max_severity = add_messages_opts.use_max_severity
@@ -217,7 +205,9 @@ function M.get_diagnostic_icon(opts, severities, index_diag, total_chunks)
217205

218206
if opts.options.use_icons_from_diagnostic then
219207
if total_chunks == 1 then
220-
icon = highlights.get_diagnostic_icon(severities[#severities])
208+
local sorted = vim.deepcopy(severities)
209+
table.sort(sorted)
210+
icon = highlights.get_diagnostic_icon(sorted[1])
221211
else
222212
icon = highlights.get_diagnostic_icon(severities[index_diag])
223213
end
@@ -393,22 +383,18 @@ function M.get_chunks(opts, diags_on_line, diag_index, diag_line, cursor_line, b
393383
local diag = diags_on_line[diag_index]
394384

395385
local show_source = false
396-
if type(opts.options.show_source) == "table" then
397-
if opts.options.show_source.enabled then
398-
if opts.options.show_source.if_many then
399-
local sources = {}
400-
for _, d in ipairs(diags_on_line) do
401-
if d.source then
402-
sources[d.source] = true
403-
end
386+
if opts.options.show_source.enabled then
387+
if opts.options.show_source.if_many then
388+
local sources = {}
389+
for _, d in ipairs(diags_on_line) do
390+
if d.source then
391+
sources[d.source] = true
404392
end
405-
show_source = vim.tbl_count(sources) > 1
406-
else
407-
show_source = true
408393
end
394+
show_source = vim.tbl_count(sources) > 1
395+
else
396+
show_source = true
409397
end
410-
elseif opts.options.show_source then
411-
show_source = true
412398
end
413399

414400
local show_code = opts.options.show_code
@@ -444,9 +430,7 @@ function M.get_chunks(opts, diags_on_line, diag_index, diag_line, cursor_line, b
444430

445431
local other_extmarks_offset = extmarks.handle_other_extmarks(buf, diag_line, line_length)
446432

447-
local multilines_enabled = type(opts.options.multilines) == "table"
448-
and opts.options.multilines.enabled
449-
or opts.options.multilines
433+
local multilines_enabled = opts.options.multilines.enabled
450434

451435
if
452436
(opts.options.overflow.mode ~= "none" and not multilines_enabled) or cursor_line == diag_line

lua/tiny-inline-diagnostic/filter.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,12 @@ end
9090
---@param diagnostics table
9191
---@return table
9292
local function add_related_diagnostics(opts, diagnostics)
93-
if not opts.options.show_related or not opts.options.show_related.enabled then
93+
if not opts.options.show_related.enabled then
9494
return diagnostics
9595
end
9696

9797
local result = {}
98-
local max_count = opts.options.show_related.max_count or 3
98+
local max_count = opts.options.show_related.max_count
9999

100100
for _, diag in ipairs(diagnostics) do
101101
table.insert(result, diag)

lua/tiny-inline-diagnostic/init.lua

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,18 +110,40 @@ local function normalize_config(config)
110110
if type(config.options.multilines) == "boolean" then
111111
config.options.multilines = vim.tbl_deep_extend("force", default_config.options.multilines, {
112112
enabled = config.options.multilines,
113-
always_show = default_config.options.multilines.always_show,
114113
})
114+
elseif type(config.options.multilines) == "table" then
115+
config.options.multilines =
116+
vim.tbl_deep_extend("force", default_config.options.multilines, config.options.multilines)
115117
end
116118

117119
if type(config.options.add_messages) == "boolean" then
118120
config.options.add_messages =
119121
vim.tbl_deep_extend("force", default_config.options.add_messages, {
120122
messages = config.options.add_messages,
121-
display_count = default_config.options.add_messages.display_count,
122-
use_max_severity = default_config.options.add_messages.use_max_severity,
123-
show_multiple_glyphs = default_config.options.add_messages.show_multiple_glyphs,
124123
})
124+
elseif type(config.options.add_messages) == "table" then
125+
config.options.add_messages =
126+
vim.tbl_deep_extend("force", default_config.options.add_messages, config.options.add_messages)
127+
end
128+
129+
if type(config.options.show_source) == "boolean" then
130+
config.options.show_source =
131+
vim.tbl_deep_extend("force", default_config.options.show_source, {
132+
enabled = config.options.show_source,
133+
})
134+
elseif type(config.options.show_source) == "table" then
135+
config.options.show_source =
136+
vim.tbl_deep_extend("force", default_config.options.show_source, config.options.show_source)
137+
end
138+
139+
if type(config.options.show_related) == "boolean" then
140+
config.options.show_related =
141+
vim.tbl_deep_extend("force", default_config.options.show_related, {
142+
enabled = config.options.show_related,
143+
})
144+
elseif type(config.options.show_related) == "table" then
145+
config.options.show_related =
146+
vim.tbl_deep_extend("force", default_config.options.show_related, config.options.show_related)
125147
end
126148

127149
return config
@@ -146,6 +168,11 @@ function M.setup(opts)
146168
if config.options.experimental.use_window_local_extmarks then
147169
extmarks.update_namespace_window()
148170
end
171+
172+
if config.options.override_open_float then
173+
local override = require("tiny-inline-diagnostic.override")
174+
vim.diagnostic.open_float = override.open_float
175+
end
149176
end
150177

151178
--- Change the blend and highlight settings dynamically.

0 commit comments

Comments
 (0)