aboutsummaryrefslogtreecommitdiff
path: root/init.lua
diff options
context:
space:
mode:
authorThim Cederlund <thim@cederlund.de>2023-10-11 17:28:59 +0200
committerFlorian Fischer <florian.fischer@muhq.space>2023-10-12 18:52:19 +0200
commit7099e56062861fc8dbb143e78447cce6bf886a97 (patch)
treee4006ea49429281e125cf2e3cae62b0b25d583ba /init.lua
parentc91a9c94b1408a308a33acbe56e8eb9bcf86d197 (diff)
downloadvis-lspc-7099e56062861fc8dbb143e78447cce6bf886a97.tar.gz
vis-lspc-7099e56062861fc8dbb143e78447cce6bf886a97.zip
fix diagnostic highlighting and message
Some language servers report diagnostics with empty ranges, start and end are at the same line and character, which currently results in no highlighting at all. Since the end of a LSP range is exclusive we always subtract 1 from it which results in invalid ranges when the server has sent an empty one. Introduce a check to fix this special case. `textDocument/publishDiagnostics` doesn't always have a `code` field, resulting in `diagnostic.code` being nil and so it is replaced with `diagnostic` in those cases.
Diffstat (limited to 'init.lua')
-rw-r--r--init.lua15
1 files changed, 13 insertions, 2 deletions
diff --git a/init.lua b/init.lua
index 222bd49..c7be0f3 100644
--- a/init.lua
+++ b/init.lua
@@ -575,9 +575,19 @@ local function lspc_highlight_diagnostics(win, diagnostics, style)
for _, diagnostic in ipairs(diagnostics) do
if lspc.highlight_diagnostics == 'range' then
local range = diagnostic.vis_range
+
+ -- LSP ranges use an exclusive finish
+ local finish = range.finish - 1
+
+ -- In some instances the range defined by the diagnostic starts
+ -- and ends at the same position. Highlight the exact position.
+ if range.finish == range.start then
+ finish = range.finish
+ end
+
-- make sure to highlight only ranges which actually contain the diagnostic
if diagnostic.content == win.file:content(range) then
- win:style(style, range.start, range.finish - 1)
+ win:style(style, range.start, finish)
end
elseif lspc.highlight_diagnostics == 'line' then
@@ -1339,7 +1349,8 @@ local function lspc_show_diagnostic(ls, win, line)
for _, diagnostic in ipairs(diagnostics_to_show) do
diagnostics_msg = diagnostics_msg ..
string.format(diagnostics_fmt, diagnostic.start.line,
- diagnostic.start.col, diagnostic.code, diagnostic.message)
+ diagnostic.start.col, diagnostic.code or 'diagnostic',
+ diagnostic.message)
end
if diagnostics_msg ~= '' then