diff --git a/.lite_project.lua b/.lite_project.lua index 527b794..e0f6d3c 100644 --- a/.lite_project.lua +++ b/.lite_project.lua @@ -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" } diff --git a/init.lua b/init.lua index 2a4248b..dde8cb6 100644 --- a/init.lua +++ b/init.lua @@ -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, }) +