Added set target function

This commit is contained in:
2025-10-23 19:46:39 +02:00
parent f9b8d67b5c
commit 232d05d244
2 changed files with 42 additions and 13 deletions

View File

@ -2,10 +2,14 @@ local config = require "core.config"
config.plugins.jpdebug = {
targets = {
["test"] = {
["test - msys"] = {
type = "shell",
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"
}

View File

@ -3,20 +3,22 @@ local core = require "core"
local style = require "core.style"
local command = require "core.command"
local View = require "core.view"
local process = require "process" -- Child Processes API
local process = require "process"
local config = require "core.config"
core.jpdebug = {}
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")
core.jpdebug.runners = {
runner_shell
}
core.jpdebug.runners[runner_shell.name] = runner_shell
-- A list of created views
local active_views = {}
-- The selected target
local selected_target = nil
-- Local helper functions for debugging --------------------------
---@diagnostic disable-next-line: unused-function
local function dump(o)
@ -40,7 +42,7 @@ function JPDebugView:new(title)
JPDebugView.super.new(self)
self.scrollable = true
self.caption = title or "JP Debug"
self.lines = { "[jpdebug] ready.\n" }
self.lines = { "ready.\n" }
self.max_lines = 5000 -- keep memory bounded
self.font = style.code_font
self.line_h = self.font:get_height()
@ -99,7 +101,7 @@ local function get_targets()
end
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
end
@ -119,9 +121,8 @@ local function run_target(target, name)
end
-- Check if we have a runner
---@diagnostic disable-next-line: unused-local
for i,runner in ipairs(core.jpdebug.runners) do
if runner.name and runner.name == target.type then
for runner_name,runner in pairs(core.jpdebug.runners) do
if runner_name == target.type then
-- Found a runner
local proc = runner:run(target.cmd, {
cwd = target.cwd or ".",
@ -164,6 +165,8 @@ end
---@diagnostic disable-next-line: param-type-mismatch
command.add(nil, {
-- The run command
["jpdebug:run"] = function()
local targets = get_targets()
local target = get_selected_target()
@ -180,4 +183,26 @@ command.add(nil, {
return
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,
})