Added better documentation for linting
This commit is contained in:
45
init.lua
45
init.lua
@ -33,6 +33,10 @@ end
|
|||||||
|
|
||||||
-- Local helper functions ----------------------------------------
|
-- Local helper functions ----------------------------------------
|
||||||
|
|
||||||
|
-- Dump any table to a string
|
||||||
|
---@param o any
|
||||||
|
---@param force bool|nil
|
||||||
|
---@return nil
|
||||||
---@diagnostic disable-next-line: unused-function
|
---@diagnostic disable-next-line: unused-function
|
||||||
local function dump(o, force)
|
local function dump(o, force)
|
||||||
force = force or false
|
force = force or false
|
||||||
@ -48,12 +52,14 @@ local function dump(o, force)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Get the plugin's path
|
||||||
|
---@return string|nil
|
||||||
local function get_plugin_directory()
|
local function get_plugin_directory()
|
||||||
local paths = {
|
local paths = {
|
||||||
USERDIR .. PATHSEP .. "plugins" .. PATHSEP .. "jpdebug",
|
USERDIR .. PATHSEP .. "plugins" .. PATHSEP .. "jpdebug",
|
||||||
DATADIR .. PATHSEP .. "plugins" .. PATHSEP .. "jpdebug"
|
DATADIR .. PATHSEP .. "plugins" .. PATHSEP .. "jpdebug"
|
||||||
}
|
}
|
||||||
for i, v in ipairs(paths) do
|
for _, v in ipairs(paths) do
|
||||||
if system.get_file_info(v) then
|
if system.get_file_info(v) then
|
||||||
return v
|
return v
|
||||||
end
|
end
|
||||||
@ -84,19 +90,12 @@ function JPDebugView:get_scrollable_size()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function JPDebugView:push(kind, s)
|
function JPDebugView:push(kind, s)
|
||||||
|
--TODO do some things with kind here
|
||||||
if not s or s == "" then return end
|
if not s or s == "" then return end
|
||||||
-- split on newlines; prefix stderr
|
self.lines[#self.lines + 1] = s
|
||||||
for line in (s .. "\n"):gmatch("(.-)\n") do
|
if #self.lines > self.max_lines then
|
||||||
if kind == "stderr" then
|
local drop = #self.lines - self.max_lines
|
||||||
line = "[stderr] " .. line
|
for _ = 1, drop do table.remove(self.lines, 1) end
|
||||||
else
|
|
||||||
line = "[stdout] " .. line
|
|
||||||
end
|
|
||||||
self.lines[#self.lines + 1] = line
|
|
||||||
if #self.lines > self.max_lines then
|
|
||||||
local drop = #self.lines - self.max_lines
|
|
||||||
for _ = 1, drop do table.remove(self.lines, 1) end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
-- autoscroll to bottom
|
-- autoscroll to bottom
|
||||||
self.scroll.to.y = self:get_scrollable_size()
|
self.scroll.to.y = self:get_scrollable_size()
|
||||||
@ -122,6 +121,7 @@ function JPDebugView:draw()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function JPDebugView:try_close(do_close)
|
function JPDebugView:try_close(do_close)
|
||||||
|
---@diagnostic disable-next-line: undefined-field
|
||||||
JPDebugView.super.try_close(self, do_close)
|
JPDebugView.super.try_close(self, do_close)
|
||||||
active_view = nil
|
active_view = nil
|
||||||
end
|
end
|
||||||
@ -139,7 +139,11 @@ end
|
|||||||
|
|
||||||
-- ---------- run target & pipe stdout/stderr into the view ----------
|
-- ---------- run target & pipe stdout/stderr into the view ----------
|
||||||
local function run_target(target, name)
|
local function run_target(target, name)
|
||||||
local title = ("JP Debug: %s"):format(name)
|
-- Check if something is alredy running
|
||||||
|
if running_proc then
|
||||||
|
core.error("[jpdebug] Already a runner active")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
local view = nil
|
local view = nil
|
||||||
if active_view then
|
if active_view then
|
||||||
@ -147,7 +151,7 @@ local function run_target(target, name)
|
|||||||
view = active_view
|
view = active_view
|
||||||
else
|
else
|
||||||
-- Otherwhise lets make one
|
-- Otherwhise lets make one
|
||||||
view = JPDebugView(title)
|
view = JPDebugView()
|
||||||
core.root_view:get_active_node():add_view(view)
|
core.root_view:get_active_node():add_view(view)
|
||||||
active_view = view
|
active_view = view
|
||||||
end
|
end
|
||||||
@ -202,7 +206,7 @@ local function run_target(target, name)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- ---------- Add toolbar to treeview if plugins are installed ------
|
-- ---------- Add toolbar to treeview if plugins are installed ------
|
||||||
if required_toolbar_plugins then
|
if required_toolbar_plugins and ToolbarView then
|
||||||
|
|
||||||
---@class Toolbar: core.view
|
---@class Toolbar: core.view
|
||||||
local Toolbar = ToolbarView:extend()
|
local Toolbar = ToolbarView:extend()
|
||||||
@ -225,11 +229,13 @@ if required_toolbar_plugins then
|
|||||||
end
|
end
|
||||||
|
|
||||||
function Toolbar:update()
|
function Toolbar:update()
|
||||||
|
---@diagnostic disable-next-line: undefined-field
|
||||||
Toolbar.super.update(self)
|
Toolbar.super.update(self)
|
||||||
self:_rebuild()
|
self:_rebuild()
|
||||||
end
|
end
|
||||||
|
|
||||||
local toolbar_view = Toolbar()
|
local toolbar_view = Toolbar()
|
||||||
|
---@diagnostic disable-next-line: unused-local
|
||||||
local toolbar_node = TreeView.node.b:split("up", toolbar_view, {y = true})
|
local toolbar_node = TreeView.node.b:split("up", toolbar_view, {y = true})
|
||||||
|
|
||||||
end
|
end
|
||||||
@ -257,8 +263,9 @@ command.add(nil, {
|
|||||||
|
|
||||||
["jpdebug:stop"] = function()
|
["jpdebug:stop"] = function()
|
||||||
core.log(dump(running_proc))
|
core.log(dump(running_proc))
|
||||||
running_proc:kill()
|
if running_runner then
|
||||||
running_runner:kill(running_proc)
|
running_runner:kill(running_proc)
|
||||||
|
end
|
||||||
core.log("[jpdebug] Stopped runner")
|
core.log("[jpdebug] Stopped runner")
|
||||||
if active_view then
|
if active_view then
|
||||||
active_view:push("stdout", " ... Stopped")
|
active_view:push("stdout", " ... Stopped")
|
||||||
@ -287,6 +294,6 @@ command.add(nil, {
|
|||||||
end
|
end
|
||||||
})
|
})
|
||||||
end,
|
end,
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
local core = require "core"
|
local core = require "core"
|
||||||
local process = require "process"
|
local process = require "process"
|
||||||
|
|
||||||
---@class M
|
---@class M
|
||||||
local M = {
|
local M = {
|
||||||
@ -7,6 +7,10 @@ local M = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
-- Run a shell command
|
-- Run a shell command
|
||||||
|
---@param cmd table|string List of command pieces or in full
|
||||||
|
---@param opts table Options to run the command. Should contain env (table), cwd (string), stdout and stdin
|
||||||
|
---@param name string Name of the target to run
|
||||||
|
---@return process|nil
|
||||||
function M:run(cmd, opts, name)
|
function M:run(cmd, opts, name)
|
||||||
core.log("[jpdebug] Running shell command")
|
core.log("[jpdebug] Running shell command")
|
||||||
if cmd then
|
if cmd then
|
||||||
@ -18,26 +22,32 @@ function M:run(cmd, opts, name)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Wait untill it ends, possibly with timeout
|
-- Wait untill it ends, possibly with timeout
|
||||||
|
---@param proc process Process object
|
||||||
|
---@param time any Time field, process.WAIT_INFINITE
|
||||||
function M:wait(proc, time)
|
function M:wait(proc, time)
|
||||||
return proc:wait(time)
|
return proc:wait(time)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Read the stdout, returns nil if process has stopped
|
-- Read the stdout, returns nil if process has stopped
|
||||||
|
---@param proc process Process object
|
||||||
function M:read_stdout(proc)
|
function M:read_stdout(proc)
|
||||||
return proc:read_stdout()
|
return proc:read_stdout()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Read the stderr
|
-- Read the stderr
|
||||||
|
---@param proc process Process object
|
||||||
function M:read_stderr(proc)
|
function M:read_stderr(proc)
|
||||||
return proc:read_stderr()
|
return proc:read_stderr()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Kill the process
|
-- Kill the process
|
||||||
|
---@param proc process Process object
|
||||||
function M:kill(proc)
|
function M:kill(proc)
|
||||||
proc:kill()
|
proc:kill()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Terminate the process
|
-- Terminate the process
|
||||||
|
---@param proc process Process object
|
||||||
function M:terminate(proc)
|
function M:terminate(proc)
|
||||||
proc:terminate()
|
proc:terminate()
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user