-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug_live.lua
More file actions
62 lines (52 loc) · 1.59 KB
/
debug_live.lua
File metadata and controls
62 lines (52 loc) · 1.59 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
local logfile = io.open("/tmp/gptcode_debug.log", "w")
local function log(msg)
if logfile then
logfile:write(os.date("%H:%M:%S") .. " " .. msg .. "\n")
logfile:flush()
end
print("[DEBUG] " .. msg)
end
log("=== DEBUG START ===")
local original_jobstart = vim.fn.jobstart
vim.fn.jobstart = function(cmd, opts)
log("jobstart: " .. table.concat(cmd, " "))
local wrapped_opts = vim.deepcopy(opts)
local original_stdout = opts.on_stdout
wrapped_opts.on_stdout = function(j, data, n)
if data then
for _, line in ipairs(data) do
if line ~= "" then
log("STDOUT[" .. j .. "]: " .. line:sub(1, 150))
end
end
end
if original_stdout then
original_stdout(j, data, n)
end
end
local original_exit = opts.on_exit
wrapped_opts.on_exit = function(j, c, n)
log("EXIT[" .. j .. "]: code=" .. c)
if original_exit then
original_exit(j, c, n)
end
end
local job = original_jobstart(cmd, wrapped_opts)
log("Job ID: " .. job)
return job
end
local original_chansend = vim.fn.chansend
vim.fn.chansend = function(job, data)
log("chansend[" .. job .. "]: " .. data:sub(1, 100))
return original_chansend(job, data)
end
local original_input = vim.ui.input
vim.ui.input = function(opts, callback)
log("vim.ui.input: " .. opts.prompt)
return original_input(opts, function(response)
log("vim.ui.input response: " .. tostring(response))
callback(response)
end)
end
log("Hooks installed. Tail -f /tmp/gptcode_debug.log to monitor")
vim.notify("Debug hooks active. Check /tmp/gptcode_debug.log", vim.log.levels.INFO)