Added better documentation for linting

This commit is contained in:
2025-10-23 22:18:48 +02:00
parent 7b822746d3
commit 8cde56a4e8
2 changed files with 37 additions and 20 deletions

View File

@ -33,6 +33,10 @@ end
-- Local helper functions ----------------------------------------
-- Dump any table to a string
---@param o any
---@param force bool|nil
---@return nil
---@diagnostic disable-next-line: unused-function
local function dump(o, force)
force = force or false
@ -48,12 +52,14 @@ local function dump(o, force)
end
end
-- Get the plugin's path
---@return string|nil
local function get_plugin_directory()
local paths = {
USERDIR .. 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
return v
end
@ -84,20 +90,13 @@ function JPDebugView:get_scrollable_size()
end
function JPDebugView:push(kind, s)
--TODO do some things with kind here
if not s or s == "" then return end
-- split on newlines; prefix stderr
for line in (s .. "\n"):gmatch("(.-)\n") do
if kind == "stderr" then
line = "[stderr] " .. line
else
line = "[stdout] " .. line
end
self.lines[#self.lines + 1] = line
self.lines[#self.lines + 1] = s
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
-- autoscroll to bottom
self.scroll.to.y = self:get_scrollable_size()
core.redraw = true
@ -122,6 +121,7 @@ function JPDebugView:draw()
end
function JPDebugView:try_close(do_close)
---@diagnostic disable-next-line: undefined-field
JPDebugView.super.try_close(self, do_close)
active_view = nil
end
@ -139,7 +139,11 @@ end
-- ---------- run target & pipe stdout/stderr into the view ----------
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
if active_view then
@ -147,7 +151,7 @@ local function run_target(target, name)
view = active_view
else
-- Otherwhise lets make one
view = JPDebugView(title)
view = JPDebugView()
core.root_view:get_active_node():add_view(view)
active_view = view
end
@ -202,7 +206,7 @@ local function run_target(target, name)
end
-- ---------- Add toolbar to treeview if plugins are installed ------
if required_toolbar_plugins then
if required_toolbar_plugins and ToolbarView then
---@class Toolbar: core.view
local Toolbar = ToolbarView:extend()
@ -225,11 +229,13 @@ if required_toolbar_plugins then
end
function Toolbar:update()
---@diagnostic disable-next-line: undefined-field
Toolbar.super.update(self)
self:_rebuild()
end
local toolbar_view = Toolbar()
---@diagnostic disable-next-line: unused-local
local toolbar_node = TreeView.node.b:split("up", toolbar_view, {y = true})
end
@ -257,8 +263,9 @@ command.add(nil, {
["jpdebug:stop"] = function()
core.log(dump(running_proc))
running_proc:kill()
if running_runner then
running_runner:kill(running_proc)
end
core.log("[jpdebug] Stopped runner")
if active_view then
active_view:push("stdout", " ... Stopped")

View File

@ -7,6 +7,10 @@ local M = {
}
-- 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)
core.log("[jpdebug] Running shell command")
if cmd then
@ -18,26 +22,32 @@ function M:run(cmd, opts, name)
end
-- 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)
return proc:wait(time)
end
-- Read the stdout, returns nil if process has stopped
---@param proc process Process object
function M:read_stdout(proc)
return proc:read_stdout()
end
-- Read the stderr
---@param proc process Process object
function M:read_stderr(proc)
return proc:read_stderr()
end
-- Kill the process
---@param proc process Process object
function M:kill(proc)
proc:kill()
end
-- Terminate the process
---@param proc process Process object
function M:terminate(proc)
proc:terminate()
end