Skip to content

Commit

Permalink
perf(summary): reduce renders using render loop
Browse files Browse the repository at this point in the history
Massifively reduces renders of the summary window by queuing renders
rather than instantly rendering every time an update happens. Updates
can now be much more common due to streamed results

See #78
  • Loading branch information
rcarriga committed Jul 27, 2022
1 parent aab54ae commit 2f5e9f6
Showing 1 changed file with 41 additions and 25 deletions.
66 changes: 41 additions & 25 deletions lua/neotest/consumers/summary/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ end

local components = {}

local render_cond = async.control.Condvar.new()

local focused
local all_expanded = {}
local function render(expanded)
if not is_open() then
return
Expand All @@ -64,35 +67,47 @@ local function render(expanded)
vim.schedule(render)
end)
end
local canvas = Canvas.new(config.summary)
if not ready 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(adapter_id .. "\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 })
for pos_id, _ in pairs(expanded or {}) do
all_expanded[pos_id] = true
end
render_cond:notify_all()
end

async.run(function()
while true do
render_cond:wait()
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(adapter_id .. "\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)
components[adapter_id]:render(canvas, tree, all_expanded, focused)
all_expanded = {}
canvas:write("\n")
end
if canvas:length() > 1 then
canvas:remove_line()
canvas:remove_line()
else
canvas:write("No tests found")
end
components[adapter_id] = components[adapter_id] or SummaryComponent(client, adapter_id)
components[adapter_id]:render(canvas, tree, expanded or {}, focused)
canvas:write("\n")
end
if canvas:length() > 1 then
canvas:remove_line()
canvas:remove_line()
else
canvas:write("No tests found")
local rendered, err = canvas:render_buffer(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 = canvas:render_buffer(summary_buf)
if not rendered then
logger.error("Couldn't render buffer", err)
end
async.api.nvim_exec("redraw", false)
end
end)

local function expand(pos_id, recursive, focus)
local tree = client:get_position(pos_id)
Expand Down Expand Up @@ -129,6 +144,7 @@ local function init()
client.listeners.results = function(adapter_id, results)
if not config.summary.expand_errors then
render()
return
end
local expanded = {}
for pos_id, result in pairs(results) do
Expand Down

0 comments on commit 2f5e9f6

Please sign in to comment.