Added set target function
This commit is contained in:
@ -2,10 +2,14 @@ local config = require "core.config"
|
|||||||
|
|
||||||
config.plugins.jpdebug = {
|
config.plugins.jpdebug = {
|
||||||
targets = {
|
targets = {
|
||||||
["test"] = {
|
["test - msys"] = {
|
||||||
type = "shell",
|
type = "shell",
|
||||||
cmd = {"C:\\msys64\\msys2_shell.cmd", "-defterm", "-here", "-no-start", "-ucrt64", "-shell", "bash", "-c", "lua test.lua"}
|
cmd = {"C:\\msys64\\msys2_shell.cmd", "-defterm", "-here", "-no-start", "-ucrt64", "-shell", "bash", "-c", "lua test.lua"}
|
||||||
|
},
|
||||||
|
["test"] = {
|
||||||
|
type = "shell",
|
||||||
|
cmd = {"lua", "test.lua"}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
target = "test"
|
default_target = "test"
|
||||||
}
|
}
|
||||||
|
|||||||
45
init.lua
45
init.lua
@ -3,20 +3,22 @@ local core = require "core"
|
|||||||
local style = require "core.style"
|
local style = require "core.style"
|
||||||
local command = require "core.command"
|
local command = require "core.command"
|
||||||
local View = require "core.view"
|
local View = require "core.view"
|
||||||
local process = require "process" -- Child Processes API
|
local process = require "process"
|
||||||
local config = require "core.config"
|
local config = require "core.config"
|
||||||
|
|
||||||
core.jpdebug = {}
|
core.jpdebug = core.jpdebug or {}
|
||||||
|
|
||||||
-- Global list of all the runners
|
-- Global list of all the runners
|
||||||
|
core.jpdebug.runners = core.jpdebug.runners or {}
|
||||||
local runner_shell = require("plugins.jpdebug.runners.shell")
|
local runner_shell = require("plugins.jpdebug.runners.shell")
|
||||||
core.jpdebug.runners = {
|
core.jpdebug.runners[runner_shell.name] = runner_shell
|
||||||
runner_shell
|
|
||||||
}
|
|
||||||
|
|
||||||
-- A list of created views
|
-- A list of created views
|
||||||
local active_views = {}
|
local active_views = {}
|
||||||
|
|
||||||
|
-- The selected target
|
||||||
|
local selected_target = nil
|
||||||
|
|
||||||
-- Local helper functions for debugging --------------------------
|
-- Local helper functions for debugging --------------------------
|
||||||
---@diagnostic disable-next-line: unused-function
|
---@diagnostic disable-next-line: unused-function
|
||||||
local function dump(o)
|
local function dump(o)
|
||||||
@ -40,7 +42,7 @@ function JPDebugView:new(title)
|
|||||||
JPDebugView.super.new(self)
|
JPDebugView.super.new(self)
|
||||||
self.scrollable = true
|
self.scrollable = true
|
||||||
self.caption = title or "JP Debug"
|
self.caption = title or "JP Debug"
|
||||||
self.lines = { "[jpdebug] ready.\n" }
|
self.lines = { "ready.\n" }
|
||||||
self.max_lines = 5000 -- keep memory bounded
|
self.max_lines = 5000 -- keep memory bounded
|
||||||
self.font = style.code_font
|
self.font = style.code_font
|
||||||
self.line_h = self.font:get_height()
|
self.line_h = self.font:get_height()
|
||||||
@ -99,7 +101,7 @@ local function get_targets()
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function get_selected_target()
|
local function get_selected_target()
|
||||||
local t = (config.plugins and config.plugins.jpdebug and config.plugins.jpdebug.target) or {}
|
local t = selected_target or ((config.plugins and config.plugins.jdebug and config.plugins.jpdebug.default_target) or nil)
|
||||||
return t
|
return t
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -119,9 +121,8 @@ local function run_target(target, name)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Check if we have a runner
|
-- Check if we have a runner
|
||||||
---@diagnostic disable-next-line: unused-local
|
for runner_name,runner in pairs(core.jpdebug.runners) do
|
||||||
for i,runner in ipairs(core.jpdebug.runners) do
|
if runner_name == target.type then
|
||||||
if runner.name and runner.name == target.type then
|
|
||||||
-- Found a runner
|
-- Found a runner
|
||||||
local proc = runner:run(target.cmd, {
|
local proc = runner:run(target.cmd, {
|
||||||
cwd = target.cwd or ".",
|
cwd = target.cwd or ".",
|
||||||
@ -164,6 +165,8 @@ end
|
|||||||
|
|
||||||
---@diagnostic disable-next-line: param-type-mismatch
|
---@diagnostic disable-next-line: param-type-mismatch
|
||||||
command.add(nil, {
|
command.add(nil, {
|
||||||
|
|
||||||
|
-- The run command
|
||||||
["jpdebug:run"] = function()
|
["jpdebug:run"] = function()
|
||||||
local targets = get_targets()
|
local targets = get_targets()
|
||||||
local target = get_selected_target()
|
local target = get_selected_target()
|
||||||
@ -180,4 +183,26 @@ command.add(nil, {
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
|
||||||
|
-- The set target command
|
||||||
|
["jpdebug:settarget"] = function()
|
||||||
|
core.command_view:enter("Select target", {
|
||||||
|
show_suggestions = true,
|
||||||
|
submit = function(selection)
|
||||||
|
if get_targets()[selection] then
|
||||||
|
selected_target = selection
|
||||||
|
else
|
||||||
|
core.error("[jpdebug] '%s' not a target", selection)
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
suggest = function(_)
|
||||||
|
local l = {}
|
||||||
|
for name, _ in pairs(get_targets()) do
|
||||||
|
table.insert(l, name)
|
||||||
|
end
|
||||||
|
return l
|
||||||
|
end
|
||||||
|
})
|
||||||
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user