aboutsummaryrefslogtreecommitdiff
path: root/init.lua
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2023-11-16 16:13:56 +0100
committerFlorian Fischer <florian.fischer@muhq.space>2023-11-21 20:18:53 +0100
commitcc2f4949d4949424d939d43e80497d8f5f94b4bc (patch)
treeee142eff6a1a72c4d0c4606b47fd5ccb7df048ea /init.lua
parent68484a2f17583428308427fd16c494e5ba204bc5 (diff)
downloadvis-lspc-cc2f4949d4949424d939d43e80497d8f5f94b4bc.tar.gz
vis-lspc-cc2f4949d4949424d939d43e80497d8f5f94b4bc.zip
support showing diagnostics from multiple language servers
Diffstat (limited to 'init.lua')
-rw-r--r--init.lua54
1 files changed, 31 insertions, 23 deletions
diff --git a/init.lua b/init.lua
index 43d87cd..a470179 100644
--- a/init.lua
+++ b/init.lua
@@ -567,12 +567,12 @@ local function vis_apply_workspaceEdit(_, _, workspaceEdit)
end
end
-local function lspc_highlight_diagnostics(win, diagnostics, style)
+local function lspc_highlight_server_diagnostics(win, server_diagnostics, style)
if not style then
style = lspc.diagnostic_style_id
end
- for _, diagnostic in ipairs(diagnostics) do
+ for _, diagnostic in ipairs(server_diagnostics) do
if lspc.highlight_diagnostics == 'range' then
local range = diagnostic.vis_range
@@ -599,6 +599,12 @@ local function lspc_highlight_diagnostics(win, diagnostics, style)
end
end
+local function lspc_highlight_diagnostics(win, diagnostics, style)
+ for _, server_diagnostics in pairs(diagnostics) do
+ lspc_highlight_server_diagnostics(win, server_diagnostics, style)
+ end
+end
+
local function lspc_clear_highlight_diagnostics(win, diagnostics)
lspc_highlight_diagnostics(win, diagnostics, win.STYLE_DEFAULT)
end
@@ -1002,7 +1008,7 @@ local function lspc_handle_publish_diagnostics(ls, uri, diagnostics)
if file.diagnostics then
lspc_clear_highlight_diagnostics(vis.win, file.diagnostics)
end
- file.diagnostics = diagnostics
+ file.diagnostics[ls] = diagnostics
lspc.log('remembered ' .. #diagnostics .. ' diagnostics for ' .. file_path)
else
@@ -1336,34 +1342,42 @@ local function lspc_goto_next_diagnostic(ls, win, reverse)
end
end
-local function lspc_show_diagnostic(ls, win, line)
+local function lspc_show_diagnostic(win, line)
if not lspc.open_files[win.file.path] then
- lspc_open(ls, win, win.file)
+ vis:command('lspc-open')
end
+ local file = lspc.open_files[win.file.path]
- local open_file = lspc.open_files[win.file.path]
-
- local diagnostics = open_file.diagnostics
- if not diagnostics or #diagnostics == 0 then
+ local diagnostics = file.diagnostics
+ if not diagnostics or not (function() -- detect if at least one server has diagnostics
+ for _, d in pairs(diagnostics) do
+ if #d then
+ return true
+ end
+ end
+ end)() then
return win.file.path .. ' has no diagnostics available'
end
line = line or get_selection(win).line
lspc.log('Show diagnostics for ' .. line)
local diagnostics_to_show = {}
- for _, diagnostic in ipairs(diagnostics) do
- local start = lsp_pos_to_vis_sel(diagnostic.range.start)
- if start.line == line then
- diagnostic.start = start
- table.insert(diagnostics_to_show, diagnostic)
+ for ls, server_diagnostics in pairs(diagnostics) do
+ for _, diagnostic in ipairs(server_diagnostics) do
+ local start = lsp_pos_to_vis_sel(diagnostic.range.start)
+ if start.line == line then
+ diagnostic.start = start
+ diagnostic.server = ls.name
+ table.insert(diagnostics_to_show, diagnostic)
+ end
end
end
- local diagnostics_fmt = '%d:%d %s:%s\n'
+ local diagnostics_fmt = '%s: %d:%d %s:%s\n'
local diagnostics_msg = ''
for _, diagnostic in ipairs(diagnostics_to_show) do
diagnostics_msg = diagnostics_msg ..
- string.format(diagnostics_fmt, diagnostic.start.line,
+ string.format(diagnostics_fmt, diagnostic.server, diagnostic.start.line,
diagnostic.start.col, diagnostic.code or 'diagnostic',
diagnostic.message)
end
@@ -1571,13 +1585,7 @@ vis:command_register('lspc-prev-diagnostic', function(argv, _, win)
end)
vis:command_register('lspc-show-diagnostics', function(argv, _, win)
- local ls, err = lspc_get_usable_ls(argv[1] or win.syntax)
- if err then
- lspc_err(err)
- return
- end
-
- err = lspc_show_diagnostic(ls, win, argv[2])
+ local err = lspc_show_diagnostic(win, argv[1])
if err then
lspc_err(err)
end