Start with luadebug
This commit is contained in:
@ -9,7 +9,12 @@ config.plugins.jpdebug = {
|
||||
["test"] = {
|
||||
type = "shell",
|
||||
cmd = {"lua", "test.lua"}
|
||||
}
|
||||
},
|
||||
["luadebug"] = {
|
||||
type = "luadebug",
|
||||
entry = "test.lua",
|
||||
cwd = ".",
|
||||
},
|
||||
},
|
||||
default_target = "test"
|
||||
default_target = "luadebug"
|
||||
}
|
||||
|
||||
40
init.lua
40
init.lua
@ -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 ------
|
||||
|
||||
46
runners/luadebug.lua
Normal file
46
runners/luadebug.lua
Normal file
@ -0,0 +1,46 @@
|
||||
local core = require "core"
|
||||
local process = require "process"
|
||||
|
||||
---@class LDB
|
||||
local LDB = {
|
||||
name = "luadebug"
|
||||
}
|
||||
|
||||
---@param target table Target table
|
||||
---@param name string Name of the target to run
|
||||
---@return process|nil
|
||||
function LDB:run(target, name)
|
||||
end
|
||||
|
||||
-- Wait untill it ends, possibly with timeout
|
||||
---@param proc process Process object
|
||||
---@param time any Time field, process.WAIT_INFINITE
|
||||
function LDB:wait(proc, time)
|
||||
return proc:wait(time)
|
||||
end
|
||||
|
||||
-- Read the stdout, returns nil if process has stopped
|
||||
---@param proc process Process object
|
||||
function LDB:read_stdout(proc)
|
||||
return proc:read_stdout()
|
||||
end
|
||||
|
||||
-- Read the stderr
|
||||
---@param proc process Process object
|
||||
function LDB:read_stderr(proc)
|
||||
return proc:read_stderr()
|
||||
end
|
||||
|
||||
-- Kill the process
|
||||
---@param proc process Process object
|
||||
function LDB:kill(proc)
|
||||
proc:kill()
|
||||
end
|
||||
|
||||
-- Terminate the process
|
||||
---@param proc process Process object
|
||||
function LDB:terminate(proc)
|
||||
proc:terminate()
|
||||
end
|
||||
|
||||
return LDB
|
||||
@ -7,14 +7,19 @@ local M = {
|
||||
}
|
||||
|
||||
-- Run a shell command
|
||||
---@param cmd table|string List of command pieces or in full
|
||||
---@param opts table Options to run the command. Should contain env (table), cwd (string), stdout and stdin
|
||||
---@param target table Target table
|
||||
---@param name string Name of the target to run
|
||||
---@return process|nil
|
||||
function M:run(cmd, opts, name)
|
||||
function M:run(target, name)
|
||||
core.log("[jpdebug] Running shell command")
|
||||
if cmd then
|
||||
local proc = process.start(cmd, opts)
|
||||
local opts = {
|
||||
cwd = target.cwd or ".",
|
||||
env = target.env or {},
|
||||
stdout = process.REDIRECT_PIPE,
|
||||
stderr = process.REDIRECT_PIPE
|
||||
}
|
||||
if target.cmd then
|
||||
local proc = process.start(target.cmd, opts)
|
||||
return proc
|
||||
else
|
||||
core.error("[jpdebug] command not specified for target %s", name)
|
||||
|
||||
Reference in New Issue
Block a user