Added way to have multiple runners and created shell runner

This commit is contained in:
U-ENGINEERO\joppe.blondel
2025-10-23 16:17:09 +02:00
parent e89a6f815e
commit 8ad1b2539b
5 changed files with 86 additions and 62 deletions

View File

@ -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 = {"^%.", <some-patterns>}
-- 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"

View File

@ -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,14 +118,24 @@ local function run_target(target, name)
active_views[title] = view
end
local opts = {
cwd = target.cwd,
-- 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
}
view:clear()
local proc = process.start({"lua", target.file}, opts)
}, name)
if proc == nil then
core.error("[jpdebug] Could not run the target")
return
end
view:clear()
-- background pump (non-blocking I/O)
core.add_thread(function()
while true do
@ -122,8 +156,13 @@ local function run_target(target, name)
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()

19
runners/shell.lua Normal file
View File

@ -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

View File

@ -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 :)")

View File