aboutsummaryrefslogtreecommitdiff
path: root/init.lua
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2023-11-16 17:04:36 +0100
committerFlorian Fischer <florian.fischer@muhq.space>2024-04-30 21:43:01 +0200
commit5d0d708ac3bf10d7db39e404fc97ad0afadbed39 (patch)
tree4a3e0308b727fa71c5e5f043a7d6970322fd7554 /init.lua
parent8608bc43a4f555b4a44847b3c83f500d6789a26f (diff)
downloadvis-lspc-5d0d708ac3bf10d7db39e404fc97ad0afadbed39.tar.gz
vis-lspc-5d0d708ac3bf10d7db39e404fc97ad0afadbed39.zip
support navigating in the merged diagnostics of multiple servers
Diffstat (limited to 'init.lua')
-rw-r--r--init.lua63
1 files changed, 39 insertions, 24 deletions
diff --git a/init.lua b/init.lua
index 5c71c01..2a794db 100644
--- a/init.lua
+++ b/init.lua
@@ -1376,18 +1376,45 @@ local lspc_goto_location_methods = {
end,
}
-local function lspc_goto_next_diagnostic(ls, win, reverse)
+local function has_diagnostics(file)
+ if not file or not file.diagnostics then
+ return false
+ end
+
+ -- detect if at least one server has published diagnostics
+ for _, d in pairs(file.diagnostics) do
+ if #d then
+ return true
+ end
+ end
+
+ return false
+end
+
+local function lspc_goto_next_diagnostic(win, reverse)
if not lspc.open_files[win.file.path] then
- lspc_open(ls, win, win.file)
+ vis:command('lspc-open')
end
local open_file = lspc.open_files[win.file.path]
- local diagnostics = open_file.diagnostics
- if not diagnostics or not #diagnostics then
+ if not has_diagnostics(open_file) then
return win.file.path .. ' has no diagnostics available'
end
+ -- merge diagnostics
+ -- TODO: come up with more efficient algorithm
+ local diagnostics = {}
+ for _, server_diagnostics in pairs(open_file.diagnostics) do
+ for _, diagnostic in ipairs(server_diagnostics) do
+ table.insert(diagnostics, diagnostic)
+ end
+ end
+ -- sort the merged diagnostics
+ table.sort(diagnostics, function(d1, d2)
+ return lsp_range_starts_before(d1.range, d2.range)
+ end)
+
local sel = get_selection(win)
local previous_diagnostic
@@ -1431,16 +1458,10 @@ local function lspc_show_diagnostic(win, line)
end
local file = lspc.open_files[win.file.path]
- 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
+ if not has_diagnostics(file) then
return win.file.path .. ' has no diagnostics available'
end
+ local diagnostics = file.diagnostics
line = line or get_selection(win).line
lspc.log('Show diagnostics for ' .. line)
@@ -1646,25 +1667,19 @@ vis:command_register('lspc-open', function(argv, _, win)
lspc_open(ls, win, win.file)
end)
-local function _lspc_next_diagnostic(win, syntax, reverse)
- local ls, err = lspc_get_usable_ls(syntax)
- if err then
- lspc_err(err)
- return
- end
-
- err = lspc_goto_next_diagnostic(ls, win, reverse)
+local function _lspc_next_diagnostic(win, reverse)
+ local err = lspc_goto_next_diagnostic(win, reverse)
if err then
lspc_err(err)
end
end
-vis:command_register('lspc-next-diagnostic', function(argv, _, win)
- _lspc_next_diagnostic(win, argv[1] or win.syntax, false)
+vis:command_register('lspc-next-diagnostic', function(_, _, win)
+ _lspc_next_diagnostic(win, false)
end)
-vis:command_register('lspc-prev-diagnostic', function(argv, _, win)
- _lspc_next_diagnostic(win, argv[1] or win.syntax, true)
+vis:command_register('lspc-prev-diagnostic', function(_, _, win)
+ _lspc_next_diagnostic(win, true)
end)
vis:command_register('lspc-show-diagnostics', function(argv, _, win)