diff options
| -rw-r--r-- | init.lua | 4 | ||||
| -rw-r--r-- | util.lua | 8 | ||||
| -rwxr-xr-x | util_test.lua | 30 |
3 files changed, 37 insertions, 5 deletions
@@ -594,7 +594,7 @@ end local function lspc_highlight_server_diagnostics(win, server_diagnostics, style) if not style then if not lspc.diagnostic_style_id then - if vis.API and vis.API > 3215 then + if (vis.API and vis.API > 3215) or (vis.ui and vis.ui.style_push) then lspc.diagnostic_style_id = vis.ui:style_push() else lspc.diagnostic_style_id = win.STYLE_LEXER_MAX @@ -612,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(util.style_define(style, diagnostic_style)) + assert(util.style_define(style, diagnostic_style, win)) if lspc.highlight_diagnostics == 'range' then local range = diagnostic.vis_range @@ -412,11 +412,13 @@ 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 +-- @param win The optional window object for older vis versions +function util.style_define(id, style, win) + if (vis.API and vis.API > 3215) or (vis.ui and vis.ui.style_define) then return vis.ui:style_define(id, style) else - return vis.win:style_define(id, style) + local w = win or vis.win + return w and w:style_define(id, style) end end diff --git a/util_test.lua b/util_test.lua index 63393b1..99f34f0 100755 --- a/util_test.lua +++ b/util_test.lua @@ -73,4 +73,34 @@ function test_table_merge() -- luacheck: ignore 111 lunatest.assert_equal(t.foo.bar.nose, 'nose') end +function test_style_define() -- luacheck: ignore 111 + -- Modern vis: vis.ui.style_define present + vis.API = 0 + vis.ui = { + style_define = function(self, id, style) + return id == 1 and style == 'fore:red' + end, + } + lunatest.assert_true(util.style_define(1, 'fore:red')) + + -- Modern vis: vis.API > 3215 + vis.API = 3216 + lunatest.assert_true(util.style_define(1, 'fore:red')) + + -- Older vis: fallback with explicit win + vis.API = nil + vis.ui = nil + local win = { + style_define = function(self, id, style) + return id == 2 and style == 'fore:blue' + end, + } + lunatest.assert_true(util.style_define(2, 'fore:blue', win)) + + -- Older vis: fallback with vis.win + vis.win = win + lunatest.assert_true(util.style_define(2, 'fore:blue')) + vis.win = nil +end + lunatest.run() |
