Start with luadebug

This commit is contained in:
2025-10-23 23:13:48 +02:00
parent 8cde56a4e8
commit 1cd7b378b6
5 changed files with 94 additions and 24 deletions

View File

@ -13,7 +13,9 @@ core.jpdebug = core.jpdebug or {}
-- Global list of all the runners
core.jpdebug.runners = core.jpdebug.runners or {}
local runner_shell = require("plugins.jpdebug.runners.shell")
local runner_luadebug = require("plugins.jpdebug.runners.luadebug")
core.jpdebug.runners[runner_shell.name] = runner_shell
core.jpdebug.runners[runner_luadebug.name] = runner_luadebug
-- Currently used view
local active_view = nil
@ -67,6 +69,18 @@ local function get_plugin_directory()
return nil
end
-- Simple function splitting strings
local function stringsplit(inputstr, sep)
if sep == nil then
sep = "%s"
end
local t = {}
for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
table.insert(t, str)
end
return t
end
-- ---------- JPDebugView: a simple scrollable log view ----------
---@class JPDebugView : core.view
local JPDebugView = View:extend()
@ -92,10 +106,13 @@ end
function JPDebugView:push(kind, s)
--TODO do some things with kind here
if not s or s == "" then return end
self.lines[#self.lines + 1] = s
if #self.lines > self.max_lines then
local drop = #self.lines - self.max_lines
for _ = 1, drop do table.remove(self.lines, 1) end
local lines = stringsplit(s, "\n")
for _,l in pairs(lines) do
self.lines[#self.lines + 1] = l
if #self.lines > self.max_lines then
local drop = #self.lines - self.max_lines
for _ = 1, drop do table.remove(self.lines, 1) end
end
end
-- autoscroll to bottom
self.scroll.to.y = self:get_scrollable_size()
@ -160,16 +177,12 @@ local function run_target(target, name)
for runner_name,runner in pairs(core.jpdebug.runners) do
if runner_name == target.type then
-- Found a runner
running_proc = runner:run(target.cmd, {
cwd = target.cwd or ".",
env = target.env or {},
stdout = process.REDIRECT_PIPE,
stderr = process.REDIRECT_PIPE
}, name)
running_proc = runner:run(target, name)
running_runner = runner
if running_proc == nil then
core.error("[jpdebug] Could not run the target")
view:push("stderr", "Could not run the target")
return
end
@ -192,8 +205,10 @@ local function run_target(target, name)
local err = runner:read_stderr(running_proc)
if err ~= nil and err ~= "" then view:push("stderr", err) end
end
local code = runner:wait(process.WAIT_INFINITE)
view:push("stdout", ("\n[exit] code=%s\n"):format(tostring(code)))
if running_proc then
local code = runner:wait(running_proc, process.WAIT_INFINITE)
view:push("stdout", ("\n[exit] code=%s\n"):format(tostring(code)))
end
running_proc = nil
running_runner = nil
end)
@ -203,6 +218,7 @@ local function run_target(target, name)
end
-- No suitable runners found
core.error("[jpdebug] No suitable runners found for target %s", name)
view:push("stderr", "No suitable runners found for target "..name)
end
-- ---------- Add toolbar to treeview if plugins are installed ------