Added hot reload of loaders button and did a bit of luadebug
This commit is contained in:
49
init.lua
49
init.lua
@ -12,10 +12,6 @@ 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
|
||||
@ -27,6 +23,9 @@ local selected_target = nil
|
||||
local running_proc = nil
|
||||
local running_runner = nil
|
||||
|
||||
-- Table containing all debug information (like breakpoints)
|
||||
local debug_info = {}
|
||||
|
||||
-- Check if required plugins are installed
|
||||
local required_toolbar_plugins = true
|
||||
if TreeView == nil or ToolbarView == nil then
|
||||
@ -88,6 +87,7 @@ local JPDebugView = View:extend()
|
||||
function JPDebugView:new(title)
|
||||
JPDebugView.super.new(self)
|
||||
self.scrollable = true
|
||||
self.context = "session"
|
||||
self.caption = title or "JP Debug"
|
||||
self.lines = { "ready.\n" }
|
||||
self.max_lines = 5000 -- keep memory bounded
|
||||
@ -162,6 +162,7 @@ local function run_target(target, name)
|
||||
return
|
||||
end
|
||||
|
||||
-- TODO fix this, it throws a node is locked error once in a while
|
||||
local view = nil
|
||||
if active_view then
|
||||
-- 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
|
||||
if runner_name == target.type then
|
||||
-- Found a runner
|
||||
running_proc = runner:run(target, name)
|
||||
running_proc = runner:run(target, name, debug_info)
|
||||
running_runner = runner
|
||||
|
||||
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)
|
||||
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 ------
|
||||
if required_toolbar_plugins and ToolbarView then
|
||||
|
||||
@ -234,13 +264,14 @@ if required_toolbar_plugins and ToolbarView then
|
||||
|
||||
function Toolbar:_rebuild()
|
||||
local t = {
|
||||
{symbol = "A", command = "jpdebug:settarget"},
|
||||
{symbol = "A", command = "jpdebug:set-target"},
|
||||
}
|
||||
if running_proc == nil then
|
||||
table.insert(t, {symbol = "B", command = "jpdebug:run"})
|
||||
else
|
||||
table.insert(t, {symbol = "D", command = "jpdebug:stop"})
|
||||
end
|
||||
table.insert(t, {symbol = "E", command = "jpdebug:reload-runners"})
|
||||
self.toolbar_commands = t
|
||||
end
|
||||
|
||||
@ -291,7 +322,7 @@ command.add(nil, {
|
||||
end,
|
||||
|
||||
-- The set target command
|
||||
["jpdebug:settarget"] = function()
|
||||
["jpdebug:set-target"] = function()
|
||||
core.command_view:enter("Select target", {
|
||||
show_suggestions = true,
|
||||
submit = function(selection)
|
||||
@ -311,5 +342,9 @@ command.add(nil, {
|
||||
})
|
||||
end,
|
||||
|
||||
["jpdebug:reload-runners"] = function()
|
||||
load_runners()
|
||||
end,
|
||||
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user