Skip to content

Commit

Permalink
perf(diagnostic): avoid checking bufnr for each path
Browse files Browse the repository at this point in the history
Potentially helps with #78
  • Loading branch information
rcarriga committed Jul 31, 2022
1 parent c4fed39 commit 4fdce02
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions lua/neotest/consumers/diagnostic.lua
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,21 @@ local function init(client)

client.listeners.results = function(adapter_id, results)
local files = {}
local tree = client:get_position(nil, { adapter = adapter_id })
if not tree then
return
end
--- Could be thousands of file paths in the results. To avoid checking if each one is loaded which involves a
--- vimscript call to bufnr, we create the set of buffers that are loaded and check against that.
local valid_bufs = {}
for _, bufnr in async.api.nvim_list_bufs() do
local bufpath = async.fn.fnamemodify(async.api.nvim_buf_get_name(bufnr), ":p")
valid_bufs[bufpath] = true
end

for pos_id, _ in pairs(results) do
local node = client:get_position(pos_id, { adapter = adapter_id })
if node and node:data().type ~= "dir" then
local node = tree:get_key(pos_id)
if node and node:data().type ~= "dir" and valid_bufs[node:data().path] then
files[node:data().path] = true
end
end
Expand Down

0 comments on commit 4fdce02

Please sign in to comment.