aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2023-10-12 20:14:57 +0200
committerFlorian Fischer <florian.fischer@muhq.space>2023-10-12 20:14:57 +0200
commitecd67870e578c061b06ecc4072477da5e9ea9f52 (patch)
tree9565632676b0f2c9b400970b0e9f801648b4c611
parent7099e56062861fc8dbb143e78447cce6bf886a97 (diff)
downloadvis-lspc-ecd67870e578c061b06ecc4072477da5e9ea9f52.tar.gz
vis-lspc-ecd67870e578c061b06ecc4072477da5e9ea9f52.zip
fix wandering empty diagnostic highlights
The last commit introduces support for highlighting empty selections by properly calculating their vis ranges. However File:content does return an empty string for empty ranges and we can not check whether the diagnostic still applies to the same position. This is fixed by faking a one character range when receiving an empty one. Doing so we get a valid one-character content we can compare and still have proper highlighting because we unconditionally decrement the range end in highlight_diagnostics. Fixes: 7099e56062861fc8dbb143e78447cce6bf886a97
-rw-r--r--init.lua15
1 files changed, 9 insertions, 6 deletions
diff --git a/init.lua b/init.lua
index c7be0f3..ff473f0 100644
--- a/init.lua
+++ b/init.lua
@@ -579,12 +579,6 @@ local function lspc_highlight_diagnostics(win, diagnostics, style)
-- 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, finish)
@@ -991,6 +985,15 @@ local function lspc_handle_publish_diagnostics(ls, uri, diagnostics)
-- And because we can't do it during a WIN_HIGHLIGHT events because
-- lsp_range_to_vis_range modifies the primary selection
diagnostic.vis_range = lsp_range_to_vis_range(vis.win, diagnostic.range)
+
+ -- In some instances the range defined by the diagnostic starts
+ -- and ends at the same position. Highlight the exact position.
+ if diagnostic.vis_range.finish == diagnostic.vis_range.start then
+ -- We fake a one char range to retrieve its content.
+ -- In highlight_diagnostics we inconditionally decrement finish anyway.
+ diagnostic.vis_range.finish = diagnostic.vis_range.finish + 1
+ end
+
-- Remember the content of the diagnostic to only highlight it if the content
-- did not change
diagnostic.content = vis.win.file:content(diagnostic.vis_range)