Skip to content

Commit 9f3f714

Browse files
committed
fix(filter): treat diagnostics with no column info as whole line (#179)
1 parent b3b91e0 commit 9f3f714

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

lua/tiny-inline-diagnostic/filter.lua

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,13 @@ function M.at_position(opts, diagnostics, line, col)
3434
end
3535

3636
local current_pos_diags = vim.tbl_filter(function(diag)
37-
return diag.lnum == line and col >= diag.col and col <= diag.end_col
37+
if diag.lnum ~= line then
38+
return false
39+
end
40+
if diag.col == 0 and diag.end_col == 0 then
41+
return true
42+
end
43+
return col >= diag.col and col <= diag.end_col
3844
end, diagnostics)
3945

4046
if opts.options.show_diags_only_under_cursor then

tests/test_filter.lua

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,26 @@ T["at_position"]["returns empty when show_diags_only_under_cursor enabled and cu
6666
MiniTest.expect.equality(#result, 0)
6767
end
6868

69+
T["at_position"]["matches whole line when diagnostic has no column info and show_diags_only_under_cursor enabled"] = function()
70+
local diagnostics = {
71+
H.make_diagnostic({ lnum = 5, col = 0, end_col = 0 }),
72+
}
73+
74+
local result = filter.at_position({ options = { show_diags_only_under_cursor = true } }, diagnostics, 5, 12)
75+
MiniTest.expect.equality(#result, 1)
76+
MiniTest.expect.equality(result[1].lnum, 5)
77+
end
78+
79+
T["at_position"]["matches whole line when diagnostic has no column info under default options"] = function()
80+
local diagnostics = {
81+
H.make_diagnostic({ lnum = 5, col = 0, end_col = 0 }),
82+
}
83+
84+
local result = filter.at_position({ options = {} }, diagnostics, 5, 12)
85+
MiniTest.expect.equality(#result, 1)
86+
MiniTest.expect.equality(result[1].lnum, 5)
87+
end
88+
6989
T["under_cursor"] = MiniTest.new_set()
7090

7191
T["under_cursor"]["returns empty for invalid buffer"] = function()

0 commit comments

Comments
 (0)