-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathdiagnostics_tracking.lua
More file actions
66 lines (57 loc) · 1.99 KB
/
diagnostics_tracking.lua
File metadata and controls
66 lines (57 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
-- Diagnostics tracking for Codey
-- Sets up autocommands to notify the app when LSP diagnostics change
-- Requires: vim.g.codey_channel_id to be set before loading
local group = vim.api.nvim_create_augroup('CodeyDiagnostics', { clear = true })
local channel_id = vim.g.codey_channel_id
-- Debounce timer to avoid flooding with rapid diagnostic updates
local debounce_timer = nil
local debounce_ms = 100
local function send_diagnostics(bufnr)
bufnr = bufnr or vim.api.nvim_get_current_buf()
-- Only send for real files
local path = vim.api.nvim_buf_get_name(bufnr)
if path == '' or vim.bo[bufnr].buftype ~= '' then
return
end
local diagnostics = vim.diagnostic.get(bufnr)
if #diagnostics == 0 then
-- Send empty list to clear diagnostics for this file
vim.rpcnotify(channel_id, 'codey_diagnostics', {
path = path,
diagnostics = {},
})
return
end
local formatted = {}
for _, d in ipairs(diagnostics) do
table.insert(formatted, {
line = d.lnum + 1, -- Convert 0-indexed to 1-indexed
col = d.col + 1,
end_line = d.end_lnum and (d.end_lnum + 1) or nil,
end_col = d.end_col and (d.end_col + 1) or nil,
severity = d.severity, -- 1=Error, 2=Warning, 3=Info, 4=Hint
message = d.message,
source = d.source,
})
end
vim.rpcnotify(channel_id, 'codey_diagnostics', {
path = path,
diagnostics = formatted,
})
end
local function send_diagnostics_debounced(bufnr)
if debounce_timer then
vim.fn.timer_stop(debounce_timer)
end
debounce_timer = vim.fn.timer_start(debounce_ms, function()
debounce_timer = nil
send_diagnostics(bufnr)
end)
end
-- Send diagnostics when they change (LSP updates, linter runs, etc.)
vim.api.nvim_create_autocmd('DiagnosticChanged', {
group = group,
callback = function(args)
send_diagnostics_debounced(args.buf)
end,
})