Skip to content

Commit

Permalink
fix(summary): stop rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
rcarriga committed Sep 11, 2022
1 parent 3f2c3e5 commit 1b83929
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 54 deletions.
27 changes: 17 additions & 10 deletions lua/neotest/consumers/summary/component.lua
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ function SummaryComponent:_render(canvas, tree, expanded, focused, indent)
local is_last_child = index == #children
local position = node:data()

has_running = has_running or self.client:is_running(position.id, { adapter = self.adapter_id })
if expanded[position.id] then
self.expanded_positions[position.id] = true
end
Expand Down Expand Up @@ -213,7 +212,9 @@ function SummaryComponent:_render(canvas, tree, expanded, focused, indent)
neotest.summary.clear_marked({ adapter = self.adapter_id })
end)

local state_icon, state_icon_group = self:_state_icon(position)
local status = self:_get_status(position)
has_running = has_running or status == "running"
local state_icon, state_icon_group = self:_state_icon(status)
canvas:write(" " .. state_icon .. " ", { group = state_icon_group })

local name_groups = { config.highlights[position.type] }
Expand All @@ -233,16 +234,22 @@ function SummaryComponent:_render(canvas, tree, expanded, focused, indent)
return has_running
end

function SummaryComponent:_state_icon(position)
function SummaryComponent:_get_status(position)
local result = self.client:get_results(self.adapter_id)[position.id]
if not result then
if self.client:is_running(position.id, { adapter = self.adapter_id }) then
return config.icons.running_animated[(self.renders % #config.icons.running_animated) + 1],
config.highlights.running
end
return config.icons.unknown, config.highlights.unknown
if result then
return result.status
elseif self.client:is_running(position.id, { adapter = self.adapter_id }) then
return "running"
end
return "unknown"
end

function SummaryComponent:_state_icon(status)
if status ~= "running" or not config.summary.animated then
return icons[status], config.highlights[status]
end
return config.icons[result.status], config.highlights[result.status]
return config.icons.running_animated[(self.renders % #config.icons.running_animated) + 1],
config.highlights.running
end

---@return SummaryComponent
Expand Down
86 changes: 46 additions & 40 deletions lua/neotest/consumers/summary/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -64,49 +64,54 @@ local function render(expanded)
end

async.run(function()
while true do
if not pending_render then
render_cond:wait()
end
pending_render = false
local canvas = Canvas.new(config.summary)
if not client:has_started() then
canvas:write("Parsing tests")
else
local cwd = async.fn.getcwd()
for _, adapter_id in ipairs(client:get_adapters()) do
local tree = client:get_position(nil, { adapter = adapter_id })
canvas:write(
vim.split(adapter_id, ":", { trimempty = true })[1] .. "\n",
{ group = config.highlights.adapter_name }
)
if tree:data().path ~= cwd then
local root_dir = async.fn.fnamemodify(tree:data().path, ":.")
canvas:write(root_dir .. "\n", { group = config.highlights.dir })
end
components[adapter_id] = components[adapter_id] or SummaryComponent(client, adapter_id)
if config.summary.animated then
pending_render = components[adapter_id]:render(canvas, tree, all_expanded, focused)
local _, err = pcall(function()
while true do
if not pending_render then
render_cond:wait()
end
pending_render = false
local canvas = Canvas.new(config.summary)
if not client:has_started() then
canvas:write("Parsing tests")
else
local cwd = async.fn.getcwd()
for _, adapter_id in ipairs(client:get_adapters()) do
local tree = client:get_position(nil, { adapter = adapter_id })
canvas:write(
vim.split(adapter_id, ":", { trimempty = true })[1] .. "\n",
{ group = config.highlights.adapter_name }
)
if tree:data().path ~= cwd then
local root_dir = async.fn.fnamemodify(tree:data().path, ":.")
canvas:write(root_dir .. "\n", { group = config.highlights.dir })
end
components[adapter_id] = components[adapter_id] or SummaryComponent(client, adapter_id)
if config.summary.animated then
pending_render = components[adapter_id]:render(canvas, tree, all_expanded, focused)
or pending_render
else
components[adapter_id]:render(canvas, tree, all_expanded, focused)
end
all_expanded = {}
canvas:write("\n")
end
if canvas:length() > 1 then
canvas:remove_line()
canvas:remove_line()
else
components[adapter_id]:render(canvas, tree, all_expanded, focused)
canvas:write("No tests found")
end
all_expanded = {}
canvas:write("\n")
end
if canvas:length() > 1 then
canvas:remove_line()
canvas:remove_line()
else
canvas:write("No tests found")
local rendered, err = pcall(canvas.render_buffer, canvas, summary_buf)
if not rendered then
logger.error("Couldn't render buffer", err)
end
async.api.nvim_exec("redraw", false)
async.util.sleep(100)
end
local rendered, err = pcall(canvas.render_buffer, canvas, summary_buf)
if not rendered then
logger.error("Couldn't render buffer", err)
end
async.api.nvim_exec("redraw", false)
async.util.sleep(100)
end)
if err then
logger.error("Error in summary consumer", err)
end
end)

Expand Down Expand Up @@ -149,9 +154,10 @@ local function init()
end
local expanded = {}
for pos_id, result in pairs(results) do
if result.status == "failed"
and client:get_position(pos_id, { adapter = adapter_id })
and #client:get_position(pos_id, { adapter = adapter_id }):children() > 0
if
result.status == "failed"
and client:get_position(pos_id, { adapter = adapter_id })
and #client:get_position(pos_id, { adapter = adapter_id }):children() > 0
then
expanded[pos_id] = true
end
Expand Down
9 changes: 5 additions & 4 deletions lua/neotest/lib/file/find.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ function M.find(root, opts)

if not name then
dir_handle = nil
elseif path_type == "directory"
and name:sub(1, 1) ~= "."
and not ignored[name]
and (not filter_dir or filter_dir(name, rel_path, root))
elseif
path_type == "directory"
and name:sub(1, 1) ~= "."
and not ignored[name]
and (not filter_dir or filter_dir(name, rel_path, root))
then
dirs_to_scan[#dirs_to_scan + 1] = rel_path
elseif path_type == "file" then
Expand Down

0 comments on commit 1b83929

Please sign in to comment.