Added hot reload of loaders button and did a bit of luadebug
This commit is contained in:
@ -14,6 +14,7 @@ config.plugins.jpdebug = {
|
|||||||
type = "luadebug",
|
type = "luadebug",
|
||||||
entry = "test.lua",
|
entry = "test.lua",
|
||||||
cwd = ".",
|
cwd = ".",
|
||||||
|
lua = {"C:\\msys64\\msys2_shell.cmd", "-defterm", "-here", "-no-start", "-ucrt64", "-shell", "bash", "-c", "lua"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
default_target = "luadebug"
|
default_target = "luadebug"
|
||||||
|
|||||||
49
init.lua
49
init.lua
@ -12,10 +12,6 @@ core.jpdebug = core.jpdebug or {}
|
|||||||
|
|
||||||
-- Global list of all the runners
|
-- Global list of all the runners
|
||||||
core.jpdebug.runners = core.jpdebug.runners or {}
|
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
|
-- Currently used view
|
||||||
local active_view = nil
|
local active_view = nil
|
||||||
@ -27,6 +23,9 @@ local selected_target = nil
|
|||||||
local running_proc = nil
|
local running_proc = nil
|
||||||
local running_runner = nil
|
local running_runner = nil
|
||||||
|
|
||||||
|
-- Table containing all debug information (like breakpoints)
|
||||||
|
local debug_info = {}
|
||||||
|
|
||||||
-- Check if required plugins are installed
|
-- Check if required plugins are installed
|
||||||
local required_toolbar_plugins = true
|
local required_toolbar_plugins = true
|
||||||
if TreeView == nil or ToolbarView == nil then
|
if TreeView == nil or ToolbarView == nil then
|
||||||
@ -88,6 +87,7 @@ local JPDebugView = View:extend()
|
|||||||
function JPDebugView:new(title)
|
function JPDebugView:new(title)
|
||||||
JPDebugView.super.new(self)
|
JPDebugView.super.new(self)
|
||||||
self.scrollable = true
|
self.scrollable = true
|
||||||
|
self.context = "session"
|
||||||
self.caption = title or "JP Debug"
|
self.caption = title or "JP Debug"
|
||||||
self.lines = { "ready.\n" }
|
self.lines = { "ready.\n" }
|
||||||
self.max_lines = 5000 -- keep memory bounded
|
self.max_lines = 5000 -- keep memory bounded
|
||||||
@ -162,6 +162,7 @@ local function run_target(target, name)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- TODO fix this, it throws a node is locked error once in a while
|
||||||
local view = nil
|
local view = nil
|
||||||
if active_view then
|
if active_view then
|
||||||
-- If there is already a view use that one
|
-- If there is already a view use that one
|
||||||
@ -177,7 +178,7 @@ local function run_target(target, name)
|
|||||||
for runner_name,runner in pairs(core.jpdebug.runners) do
|
for runner_name,runner in pairs(core.jpdebug.runners) do
|
||||||
if runner_name == target.type then
|
if runner_name == target.type then
|
||||||
-- Found a runner
|
-- Found a runner
|
||||||
running_proc = runner:run(target, name)
|
running_proc = runner:run(target, name, debug_info)
|
||||||
running_runner = runner
|
running_runner = runner
|
||||||
|
|
||||||
if running_proc == nil then
|
if running_proc == nil then
|
||||||
@ -221,6 +222,35 @@ local function run_target(target, name)
|
|||||||
view:push("stderr", "No suitable runners found for target "..name)
|
view:push("stderr", "No suitable runners found for target "..name)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function hot_require(name, into)
|
||||||
|
-- blow away the cached module
|
||||||
|
package.loaded[name] = nil
|
||||||
|
local fresh = require(name)
|
||||||
|
|
||||||
|
if into then
|
||||||
|
-- wipe old table (keep the identity)
|
||||||
|
for k in pairs(into) do into[k] = nil end
|
||||||
|
-- copy new fields in
|
||||||
|
for k, v in pairs(fresh) do into[k] = v end
|
||||||
|
-- copy metatable too, if any
|
||||||
|
local mt = getmetatable(fresh)
|
||||||
|
if mt then setmetatable(into, mt) end
|
||||||
|
return into
|
||||||
|
else
|
||||||
|
return fresh
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function load_runners()
|
||||||
|
local runner_shell = hot_require("plugins.jpdebug.runners.shell", core.jpdebug.runners.shell)
|
||||||
|
local runner_luadebug = hot_require("plugins.jpdebug.runners.luadebug", core.jpdebug.runners.luadebug)
|
||||||
|
core.jpdebug.runners[runner_shell.name] = runner_shell
|
||||||
|
core.jpdebug.runners[runner_luadebug.name] = runner_luadebug
|
||||||
|
core.log("[jpdebug] Runners loaded")
|
||||||
|
end
|
||||||
|
-- And call it while loading the plugin
|
||||||
|
load_runners()
|
||||||
|
|
||||||
-- ---------- Add toolbar to treeview if plugins are installed ------
|
-- ---------- Add toolbar to treeview if plugins are installed ------
|
||||||
if required_toolbar_plugins and ToolbarView then
|
if required_toolbar_plugins and ToolbarView then
|
||||||
|
|
||||||
@ -234,13 +264,14 @@ if required_toolbar_plugins and ToolbarView then
|
|||||||
|
|
||||||
function Toolbar:_rebuild()
|
function Toolbar:_rebuild()
|
||||||
local t = {
|
local t = {
|
||||||
{symbol = "A", command = "jpdebug:settarget"},
|
{symbol = "A", command = "jpdebug:set-target"},
|
||||||
}
|
}
|
||||||
if running_proc == nil then
|
if running_proc == nil then
|
||||||
table.insert(t, {symbol = "B", command = "jpdebug:run"})
|
table.insert(t, {symbol = "B", command = "jpdebug:run"})
|
||||||
else
|
else
|
||||||
table.insert(t, {symbol = "D", command = "jpdebug:stop"})
|
table.insert(t, {symbol = "D", command = "jpdebug:stop"})
|
||||||
end
|
end
|
||||||
|
table.insert(t, {symbol = "E", command = "jpdebug:reload-runners"})
|
||||||
self.toolbar_commands = t
|
self.toolbar_commands = t
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -291,7 +322,7 @@ command.add(nil, {
|
|||||||
end,
|
end,
|
||||||
|
|
||||||
-- The set target command
|
-- The set target command
|
||||||
["jpdebug:settarget"] = function()
|
["jpdebug:set-target"] = function()
|
||||||
core.command_view:enter("Select target", {
|
core.command_view:enter("Select target", {
|
||||||
show_suggestions = true,
|
show_suggestions = true,
|
||||||
submit = function(selection)
|
submit = function(selection)
|
||||||
@ -311,5 +342,9 @@ command.add(nil, {
|
|||||||
})
|
})
|
||||||
end,
|
end,
|
||||||
|
|
||||||
|
["jpdebug:reload-runners"] = function()
|
||||||
|
load_runners()
|
||||||
|
end,
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,25 @@
|
|||||||
local core = require "core"
|
local core = require "core"
|
||||||
local process = require "process"
|
local process = require "process"
|
||||||
|
|
||||||
|
-- Dump any table to a string
|
||||||
|
---@param o any
|
||||||
|
---@param force bool|nil
|
||||||
|
---@return nil
|
||||||
|
---@diagnostic disable-next-line: unused-function
|
||||||
|
local function dump(o, force)
|
||||||
|
force = force or false
|
||||||
|
if type(o) == 'table' or force then
|
||||||
|
local s = '{ '
|
||||||
|
for k,v in pairs(o) do
|
||||||
|
if type(k) ~= 'number' then k = '"'..k..'"' end
|
||||||
|
s = s .. '['..k..'] = ' .. dump(v) .. ','
|
||||||
|
end
|
||||||
|
return s .. '} '
|
||||||
|
else
|
||||||
|
return type(o)..": "..tostring(o)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
---@class LDB
|
---@class LDB
|
||||||
local LDB = {
|
local LDB = {
|
||||||
name = "luadebug"
|
name = "luadebug"
|
||||||
@ -8,8 +27,42 @@ local LDB = {
|
|||||||
|
|
||||||
---@param target table Target table
|
---@param target table Target table
|
||||||
---@param name string Name of the target to run
|
---@param name string Name of the target to run
|
||||||
|
---@praam debuginfo table Debugging information
|
||||||
---@return process|nil
|
---@return process|nil
|
||||||
function LDB:run(target, name)
|
function LDB:run(target, name, debuginfo)
|
||||||
|
if target.entry == nil then
|
||||||
|
core.error("[jpdebug][luadebug] target.entry is required")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local entry = target.entry
|
||||||
|
local lua = target.lua or {"lua"}
|
||||||
|
local cwd = target.cwd or "."
|
||||||
|
local env = target.env or {}
|
||||||
|
|
||||||
|
-- Build the inline lua launcher
|
||||||
|
local dbg_call = string.format([[
|
||||||
|
print("Here will the call to mobdebug be")
|
||||||
|
]])
|
||||||
|
local launcher = string.format([[
|
||||||
|
%s
|
||||||
|
dofile(%q)
|
||||||
|
]], dbg_call, entry)
|
||||||
|
|
||||||
|
-- Spawn the process
|
||||||
|
local cmd = lua
|
||||||
|
-- table.insert(lua, "-e")
|
||||||
|
table.insert(lua, entry)
|
||||||
|
local proc = process.start(cmd, {
|
||||||
|
cwd = cwd,
|
||||||
|
env = env,
|
||||||
|
stdout = process.REDIRECT_PIPE,
|
||||||
|
stderr = process.REDIRECT_PIPE,
|
||||||
|
})
|
||||||
|
if proc == nil then
|
||||||
|
core.error("[jpdebug][luadebug] Failed to start "..entry)
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
return proc
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Wait untill it ends, possibly with timeout
|
-- Wait untill it ends, possibly with timeout
|
||||||
|
|||||||
@ -9,8 +9,10 @@ local M = {
|
|||||||
-- Run a shell command
|
-- Run a shell command
|
||||||
---@param target table Target table
|
---@param target table Target table
|
||||||
---@param name string Name of the target to run
|
---@param name string Name of the target to run
|
||||||
|
---@praam debuginfo table Debugging information
|
||||||
---@return process|nil
|
---@return process|nil
|
||||||
function M:run(target, name)
|
---@diagnostic disable-next-line: unused-local
|
||||||
|
function M:run(target, name, debuginfo)
|
||||||
core.log("[jpdebug] Running shell command")
|
core.log("[jpdebug] Running shell command")
|
||||||
local opts = {
|
local opts = {
|
||||||
cwd = target.cwd or ".",
|
cwd = target.cwd or ".",
|
||||||
|
|||||||
Reference in New Issue
Block a user