diff --git a/.lite_project.lua b/.lite_project.lua index 030f25f..527b794 100644 --- a/.lite_project.lua +++ b/.lite_project.lua @@ -1,44 +1,10 @@ --- Put project's module settings here. --- This module will be loaded when opening a project, after the user module --- configuration. --- It will be automatically reloaded when saved. - local config = require "core.config" --- you can add some patterns to ignore files within the project --- config.ignore_files = {"^%.", } - --- Patterns are normally applied to the file's or directory's name, without --- its path. See below about how to apply filters on a path. --- --- Here some examples: --- --- "^%." matches any file of directory whose basename begins with a dot. --- --- When there is an '/' or a '/$' at the end, the pattern will only match --- directories. When using such a pattern a final '/' will be added to the name --- of any directory entry before checking if it matches. --- --- "^%.git/" matches any directory named ".git" anywhere in the project. --- --- If a "/" appears anywhere in the pattern (except when it appears at the end or --- is immediately followed by a '$'), then the pattern will be applied to the full --- path of the file or directory. An initial "/" will be prepended to the file's --- or directory's path to indicate the project's root. --- --- "^/node_modules/" will match a directory named "node_modules" at the project's root. --- "^/build.*/" will match any top level directory whose name begins with "build". --- "^/subprojects/.+/" will match any directory inside a top-level folder named "subprojects". - --- You may activate some plugins on a per-project basis to override the user's settings. --- config.plugins.trimwitespace = true - -config.plugins.jpdebug = config.plugins.jpdebug or {} config.plugins.jpdebug = { targets = { ["test"] = { - cwd = ".", - file = "test.lua" + type = "shell", + cmd = {"C:\\msys64\\msys2_shell.cmd", "-defterm", "-here", "-no-start", "-ucrt64", "-shell", "bash", "-c", "lua test.lua"} } }, target = "test" diff --git a/init.lua b/init.lua index 6e8ee87..2a4248b 100644 --- a/init.lua +++ b/init.lua @@ -6,8 +6,32 @@ local View = require "core.view" local process = require "process" -- Child Processes API local config = require "core.config" +core.jpdebug = {} + +-- Global list of all the runners +local runner_shell = require("plugins.jpdebug.runners.shell") +core.jpdebug.runners = { + runner_shell +} + +-- A list of created views local active_views = {} +-- Local helper functions for debugging -------------------------- +---@diagnostic disable-next-line: unused-function +local function dump(o) + if type(o) == 'table' 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 tostring(o) + end +end + -- ---------- JPDebugView: a simple scrollable log view ---------- ---@class JPDebugView : core.view local JPDebugView = View:extend() @@ -94,36 +118,51 @@ local function run_target(target, name) active_views[title] = view end - local opts = { - cwd = target.cwd, - stdout = process.REDIRECT_PIPE, - stderr = process.REDIRECT_PIPE - } - view:clear() - local proc = process.start({"lua", target.file}, opts) + -- 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 + -- Found a runner + local proc = runner:run(target.cmd, { + cwd = target.cwd or ".", + env = target.env or {}, + stdout = process.REDIRECT_PIPE, + stderr = process.REDIRECT_PIPE + }, name) - -- background pump (non-blocking I/O) - core.add_thread(function() - while true do - coroutine.yield(0.016) -- ~60fps - local out = proc:read_stdout() - if out == nil then - -- stdout pipe closed: try drain stderr and break when both closed - local err = proc:read_stderr() - if err ~= nil and err ~= "" then view:push("stderr", err) end - break + if proc == nil then + core.error("[jpdebug] Could not run the target") + return end - if out ~= "" then view:push("stdout", out) end - local err = proc:read_stderr() - if err ~= nil and err ~= "" then view:push("stderr", err) end - end - local code = proc:wait(process.WAIT_INFINITE) - view:push("stdout", ("\n[exit] code=%s\n"):format(tostring(code))) - end) - return view + view:clear() + -- background pump (non-blocking I/O) + core.add_thread(function() + while true do + coroutine.yield(0.016) -- ~60fps + local out = proc:read_stdout() + if out == nil then + -- stdout pipe closed: try drain stderr and break when both closed + local err = proc:read_stderr() + if err ~= nil and err ~= "" then view:push("stderr", err) end + break + end + if out ~= "" then view:push("stdout", out) end + local err = proc:read_stderr() + if err ~= nil and err ~= "" then view:push("stderr", err) end + end + local code = proc:wait(process.WAIT_INFINITE) + view:push("stdout", ("\n[exit] code=%s\n"):format(tostring(code))) + end) + + return view + end + end + -- No suitable runners found + core.error("[jpdebug] No suitable runners found for target %s", name) end +---@diagnostic disable-next-line: param-type-mismatch command.add(nil, { ["jpdebug:run"] = function() local targets = get_targets() diff --git a/runners/shell.lua b/runners/shell.lua new file mode 100644 index 0000000..80754cd --- /dev/null +++ b/runners/shell.lua @@ -0,0 +1,19 @@ +local core = require "core" + +---@class M +local M = { + name = "shell" +} + +function M:run(cmd, opts, name) + core.log("[jpdebug] Running shell command") + if cmd then + local proc = process.start(cmd, opts) + return proc + else + core.error("[jpdebug] command not specified for target %s", name) + end +end + +return M + diff --git a/test.lua b/test.lua index 01400a8..6d72ab0 100644 --- a/test.lua +++ b/test.lua @@ -1,5 +1,5 @@ print("Starting loop: test 123") -for i = 1, 5 do +for i = 1, 4 do print("i =", i) -- we'll stop here end print("Yaaayyyy it works perfectly fine :)") diff --git a/mobdebug.lua b/vendor/mobdebug.lua similarity index 100% rename from mobdebug.lua rename to vendor/mobdebug.lua