Added better documentation for linting
This commit is contained in:
45
init.lua
45
init.lua
@ -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,19 +90,12 @@ 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
|
||||
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
|
||||
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
|
||||
-- autoscroll to bottom
|
||||
self.scroll.to.y = self:get_scrollable_size()
|
||||
@ -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()
|
||||
running_runner:kill(running_proc)
|
||||
if running_runner then
|
||||
running_runner:kill(running_proc)
|
||||
end
|
||||
core.log("[jpdebug] Stopped runner")
|
||||
if active_view then
|
||||
active_view:push("stdout", " ... Stopped")
|
||||
@ -287,6 +294,6 @@ command.add(nil, {
|
||||
end
|
||||
})
|
||||
end,
|
||||
|
||||
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user