Skip to content

Commit 842983e

Browse files
authored
Merge pull request #114 from umutondersu/feature/show-source-if-many
feat: added if_many option for show_source
2 parents e563f38 + 4f5dec7 commit 842983e

File tree

4 files changed

+32
-4
lines changed

4 files changed

+32
-4
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,10 @@ require("tiny-inline-diagnostic").setup({
7676

7777
options = {
7878
-- Display the source of the diagnostic (e.g., basedpyright, vsserver, lua_ls etc.)
79-
show_source = false,
79+
show_source = {
80+
enabled = false,
81+
if_many = false,
82+
},
8083

8184
-- Use icons defined in the diagnostic configuration
8285
use_icons_from_diagnostic = false,

doc/tiny-inline-diagnostic.nvim.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,10 @@ OPTIONS *tiny-inline-diagnostic.nvim-tiny-inline-diagnostic.nvim-options*
8686

8787
options = {
8888
-- Display the source of the diagnostic (e.g., basedpyright, vsserver, lua_ls etc.)
89-
show_source = false,
89+
show_source = {
90+
enabled = false,
91+
if_many = false,
92+
},
9093

9194
-- Use icons defined in the diagnostic configuration
9295
use_icons_from_diagnostic = false,

lua/tiny-inline-diagnostic/chunk.lua

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,26 @@ function M.get_chunks(opts, diags_on_line, diag_index, diag_line, cursor_line, b
244244

245245
local diag = diags_on_line[diag_index]
246246

247-
if opts.options.show_source and diag.source then
247+
local show_source = false
248+
if type(opts.options.show_source) == "table" then
249+
if opts.options.show_source.enabled then
250+
if opts.options.show_source.if_many then
251+
local sources = {}
252+
for _, d in ipairs(diags_on_line) do
253+
if d.source then
254+
sources[d.source] = true
255+
end
256+
end
257+
show_source = vim.tbl_count(sources) > 1
258+
else
259+
show_source = true
260+
end
261+
end
262+
elseif opts.options.show_source then
263+
show_source = true
264+
end
265+
266+
if show_source and diag.source then
248267
diag.message = diag.message .. " (" .. diag.source .. ")"
249268
end
250269

lua/tiny-inline-diagnostic/init.lua

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ local default_config = {
2424
mixing_color = "Normal",
2525
},
2626
options = {
27-
show_source = false,
27+
show_source = {
28+
enabled = false,
29+
if_many = false,
30+
},
2831
add_messages = true,
2932
set_arrow_to_diag_color = false,
3033
use_icons_from_diagnostic = false,

0 commit comments

Comments
 (0)