Added way to have multiple runners and created shell runner
This commit is contained in:
@ -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"
|
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 = {
|
config.plugins.jpdebug = {
|
||||||
targets = {
|
targets = {
|
||||||
["test"] = {
|
["test"] = {
|
||||||
cwd = ".",
|
type = "shell",
|
||||||
file = "test.lua"
|
cmd = {"C:\\msys64\\msys2_shell.cmd", "-defterm", "-here", "-no-start", "-ucrt64", "-shell", "bash", "-c", "lua test.lua"}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
target = "test"
|
target = "test"
|
||||||
|
|||||||
89
init.lua
89
init.lua
@ -6,8 +6,32 @@ local View = require "core.view"
|
|||||||
local process = require "process" -- Child Processes API
|
local process = require "process" -- Child Processes API
|
||||||
local config = require "core.config"
|
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 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 ----------
|
-- ---------- JPDebugView: a simple scrollable log view ----------
|
||||||
---@class JPDebugView : core.view
|
---@class JPDebugView : core.view
|
||||||
local JPDebugView = View:extend()
|
local JPDebugView = View:extend()
|
||||||
@ -94,36 +118,51 @@ local function run_target(target, name)
|
|||||||
active_views[title] = view
|
active_views[title] = view
|
||||||
end
|
end
|
||||||
|
|
||||||
local opts = {
|
-- Check if we have a runner
|
||||||
cwd = target.cwd,
|
---@diagnostic disable-next-line: unused-local
|
||||||
stdout = process.REDIRECT_PIPE,
|
for i,runner in ipairs(core.jpdebug.runners) do
|
||||||
stderr = process.REDIRECT_PIPE
|
if runner.name and runner.name == target.type then
|
||||||
}
|
-- Found a runner
|
||||||
view:clear()
|
local proc = runner:run(target.cmd, {
|
||||||
local proc = process.start({"lua", target.file}, opts)
|
cwd = target.cwd or ".",
|
||||||
|
env = target.env or {},
|
||||||
|
stdout = process.REDIRECT_PIPE,
|
||||||
|
stderr = process.REDIRECT_PIPE
|
||||||
|
}, name)
|
||||||
|
|
||||||
-- background pump (non-blocking I/O)
|
if proc == nil then
|
||||||
core.add_thread(function()
|
core.error("[jpdebug] Could not run the target")
|
||||||
while true do
|
return
|
||||||
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
|
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
|
end
|
||||||
|
|
||||||
|
---@diagnostic disable-next-line: param-type-mismatch
|
||||||
command.add(nil, {
|
command.add(nil, {
|
||||||
["jpdebug:run"] = function()
|
["jpdebug:run"] = function()
|
||||||
local targets = get_targets()
|
local targets = get_targets()
|
||||||
|
|||||||
20
runners/shell.lua
Normal file
20
runners/shell.lua
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
local core = require "core"
|
||||||
|
local process = require "process"
|
||||||
|
|
||||||
|
---@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
|
||||||
|
|
||||||
2
test.lua
2
test.lua
@ -1,5 +1,5 @@
|
|||||||
print("Starting loop: test 123")
|
print("Starting loop: test 123")
|
||||||
for i = 1, 5 do
|
for i = 1, 4 do
|
||||||
print("i =", i) -- we'll stop here
|
print("i =", i) -- we'll stop here
|
||||||
end
|
end
|
||||||
print("Yaaayyyy it works perfectly fine :)")
|
print("Yaaayyyy it works perfectly fine :)")
|
||||||
|
|||||||
0
mobdebug.lua → vendor/mobdebug.lua
vendored
0
mobdebug.lua → vendor/mobdebug.lua
vendored
Reference in New Issue
Block a user