aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2026-05-30 16:15:53 +0200
committerFlorian Fischer <florian.fischer@muhq.space>2026-07-15 12:06:32 +0200
commit9d0f7a0b82b1983b44636259733d6d2c39497315 (patch)
treeae14a364d8eedb8e6405701fec156a2eaa0d3d5c
parentfc52af4cb42485338ccc8a7968ec6289de981c2b (diff)
downloadvis-lspc-9d0f7a0b82b1983b44636259733d6d2c39497315.tar.gz
vis-lspc-9d0f7a0b82b1983b44636259733d6d2c39497315.zip
implement backward compatible style handling
Remove diagnostic_style_id and use vis.ui:style_push to obtain one.
-rw-r--r--README.md1
-rw-r--r--init.lua11
-rw-r--r--lspc.lua3
-rw-r--r--util.lua11
4 files changed, 20 insertions, 6 deletions
diff --git a/README.md b/README.md
index b67bd9c..556e4b8 100644
--- a/README.md
+++ b/README.md
@@ -139,7 +139,6 @@ Available options are:
* `autoconfirm_edits = false` - apply workspaceEdits without user confirmation
* `ls_map` - a table mapping `vis` syntax names to language server configurations
* `highlight_diagnostics = 'line'` - highlight the `range` or `line`number of available diagnostics
-* `diagnostic_style_id = nil` - vis style id used to highlight diagnostics, win.STYLE_LEXER_MAX is used by default
* `diagnostic_styles = { error = 'back:red', warning = 'back:yellow', information = 'back:yellow', hint = 'back:yellow', }` - styles used to highlight different diagnostics
* `workspace_edit_remember_cursor = true` - restore the primary cursor position after a workspaceEdit
* `message_level = 3` - the level of shown messages retrieved via `window/showMessage` notifications
diff --git a/init.lua b/init.lua
index 63610c7..33a2ca6 100644
--- a/init.lua
+++ b/init.lua
@@ -593,7 +593,14 @@ end
local function lspc_highlight_server_diagnostics(win, server_diagnostics, style)
if not style then
- style = lspc.diagnostic_style_id or win.STYLE_LEXER_MAX
+ if not lspc.diagnostic_style_id then
+ if vis.API and vis.API > 3215 then
+ lspc.diagnostic_style_id = vis.ui:style_push()
+ else
+ lspc.diagnostic_style_id = win.STYLE_LEXER_MAX
+ end
+ end
+ style = lspc.diagnostic_style_id
end
local level_mapping = {
@@ -605,7 +612,7 @@ local function lspc_highlight_server_diagnostics(win, server_diagnostics, style)
for _, diagnostic in ipairs(server_diagnostics) do
local diagnostic_style = level_mapping[diagnostic.severity] or level_mapping[1]
- assert(win:style_define(style, diagnostic_style))
+ assert(util.style_define(style, diagnostic_style))
if lspc.highlight_diagnostics == 'range' then
local range = diagnostic.vis_range
diff --git a/lspc.lua b/lspc.lua
index 389961d..0f09f5a 100644
--- a/lspc.lua
+++ b/lspc.lua
@@ -28,9 +28,6 @@ local lspc = {
-- should diagnostics be highlighted if available
highlight_diagnostics = 'line',
- -- style id used by lspc to register the style used to highlight diagnostics
- -- by default win.STYLE_LEXER_MAX is used (the last style id available for the lexer styles). See vis/ui.h.
- diagnostic_style_id = nil,
-- styles used by lspc to highlight the diagnostic range
-- must be set by the user
diagnostic_styles = {
diff --git a/util.lua b/util.lua
index aed1032..c4894c8 100644
--- a/util.lua
+++ b/util.lua
@@ -409,4 +409,15 @@ function util.table.merge(weak, strong)
return weak
end
+--- Wrapper to define a style in vis.
+-- @param id The style id
+-- @param style The style description
+function util.style_define(id, style)
+ if vis.API and vis.API > 3215 then
+ return vis.ui:style_define(id, style)
+ else
+ return vis.win:style_define(id, style)
+ end
+end
+
return util