Skip to content

Commit

Permalink
refactor: fill location to automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
topaxi committed Apr 14, 2023
1 parent 6206111 commit da9517a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lua/gh-actions/ui/buffer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function Buffer:nl()
return self
end

function Buffer:get_current_line()
function Buffer:get_current_line_nr()
return math.max(1, #self._lines)
end

Expand Down
17 changes: 8 additions & 9 deletions lua/gh-actions/ui/render.lua
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ end
---@param workflow GhWorkflow
---@param runs GhWorkflowRun[]
function GhActionsRender:workflow(state, workflow, runs)
local workflowline = self:get_current_line()
local workflowline = self:get_current_line_nr()
local runs_n = math.min(5, #runs)

self
Expand All @@ -134,7 +134,6 @@ function GhActionsRender:workflow(state, workflow, runs)
kind = 'workflow',
value = workflow,
from = workflowline,
to = self:get_current_line() - 1,
}

if #runs > 0 then
Expand All @@ -145,7 +144,7 @@ end
---@param state GhActionsState
---@param run GhWorkflowRun
function GhActionsRender:workflow_run(state, run)
local runline = self:get_current_line()
local runline = self:get_current_line_nr()

self
:status_icon(run, { indent = 1 })
Expand All @@ -166,13 +165,12 @@ function GhActionsRender:workflow_run(state, run)
kind = 'workflow_run',
value = run,
from = runline,
to = self:get_current_line() - 1,
}
end

---@param job GhWorkflowRunJob
function GhActionsRender:workflow_job(job)
local jobline = self:get_current_line()
local jobline = self:get_current_line_nr()

self
:status_icon(job, { indent = 2 })
Expand All @@ -190,13 +188,12 @@ function GhActionsRender:workflow_job(job)
kind = 'workflow_job',
value = job,
from = jobline,
to = self:get_current_line() - 1,
}
end

---@param step GhWorkflowRunJobStep
function GhActionsRender:workflow_step(step)
local stepline = self:get_current_line()
local stepline = self:get_current_line_nr()

self
:status_icon(step, { indent = 3 })
Expand All @@ -208,7 +205,6 @@ function GhActionsRender:workflow_step(step)
kind = 'workflow_step',
value = step,
from = stepline,
to = self:get_current_line() - 1,
}
end

Expand All @@ -228,7 +224,10 @@ end

---@param location GhActionsRenderLocation
function GhActionsRender:append_location(location)
table.insert(self.locations, location)
table.insert(
self.locations,
vim.tbl_extend('keep', location, { to = self:get_current_line_nr() - 1 })
)
end

return GhActionsRender

0 comments on commit da9517a

Please sign in to comment.