diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2023-04-15 12:11:57 +0200 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2023-10-06 13:04:09 +0200 |
| commit | efd5262f2c45d3289e482b1091d3c1d44cf67a42 (patch) | |
| tree | eb7cf97bbe06acb7c310aff0f1cd99e77ec38766 /init.lua | |
| parent | 2751145b885aea02aabbc193af359da9cb9127e6 (diff) | |
| download | vis-lspc-ca66b67e1d6f526af95d5b1cc4b40bf91dec80c4.tar.gz vis-lspc-ca66b67e1d6f526af95d5b1cc4b40bf91dec80c4.zip | |
support highlighting the line number of available diagnosticsv0.2.0
Diffstat (limited to 'init.lua')
| -rw-r--r-- | init.lua | 38 |
1 files changed, 32 insertions, 6 deletions
@@ -567,16 +567,39 @@ local function vis_apply_workspaceEdit(_, _, workspaceEdit) end end -local function lspc_highlight_diagnostics(win, diagnostics) +local function lspc_highlight_diagnostics(win, diagnostics, style) + if not style then + style = lspc.diagnostic_style_id + end + for _, diagnostic in ipairs(diagnostics) do local range = diagnostic.vis_range - -- make sure to highlight only ranges which actually contain the diagnostic - if diagnostic.content == win.file:content(range) then - win:style(lspc.diagnostic_style_id, range.start, range.finish - 1) + + if lspc.highlight_diagnostics == 'range' then + -- 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) + end + + elseif lspc.highlight_diagnostics == 'line' then + if not win.style_lineno then + lspc_err('Vis build does not support style_lineno') + return + end + + local start_line = range.start.line + 1 + local end_line = range['end'].line + 1 + for line = start_line, end_line, 1 do + win:style_lineno(style, line) + end end end end +local function lspc_clear_highlight_diagnostics(win, diagnostics) + lspc_highlight_diagnostics(win, diagnostics, win.STYLE_DEFAULT) +end + -- send a rpc message to a language server local function ls_rpc(ls, req) req.jsonrpc = '2.0' @@ -964,6 +987,9 @@ local function lspc_handle_publish_diagnostics(ls, uri, diagnostics) diagnostic.content = vis.win.file:content(diagnostic.vis_range) end + if file.diagnostics then + lspc_clear_highlight_diagnostics(vis.win, file.diagnostics) + end file.diagnostics = diagnostics lspc.log('remember diagnostics for ' .. file_path) @@ -1499,10 +1525,10 @@ vis.events.subscribe(vis.events.FILE_OPEN, function(file) lspc_open(ls, win, file) end) -vis:option_register('lspc-highlight-diagnostics', 'bool', function(value) +vis:option_register('lspc-highlight-diagnostics', 'string', function(value) lspc.highlight_diagnostics = value return true -end, 'Should lspc highlight diagnostics if available') +end, 'How should lspc highlight available diagnostics') vis:option_register('lspc-menu-cmd', 'string', function(value) lspc.menu_cmd = value |
