diff --git a/lua/neotest/consumers/watch/init.lua b/lua/neotest/consumers/watch/init.lua index 6c9283c..69ddd66 100644 --- a/lua/neotest/consumers/watch/init.lua +++ b/lua/neotest/consumers/watch/init.lua @@ -29,6 +29,17 @@ local neotest = {} ---@class neotest.consumers.watch neotest.watch = {} +local init = function(client) + client.listeners.discover_positions = function(_, tree) + for _, watcher in pairs(watchers) do + if watcher.tree:data().path == tree:data().path + and not watcher.discover_positions_event.is_set() then + watcher.discover_positions_event.set() + end + end + end +end + local function get_valid_client(bufnr) local clients = nio.lsp.get_clients({ bufnr = bufnr }) for _, client in ipairs(clients) do @@ -200,7 +211,8 @@ function neotest.watch.is_watching(position_id) end neotest.watch = setmetatable(neotest.watch, { - __call = function() + __call = function(_, client) + init(client) return neotest.watch end, }) diff --git a/lua/neotest/consumers/watch/watcher.lua b/lua/neotest/consumers/watch/watcher.lua index c77ba35..c7058cd 100644 --- a/lua/neotest/consumers/watch/watcher.lua +++ b/lua/neotest/consumers/watch/watcher.lua @@ -6,6 +6,8 @@ local config = require("neotest.config") ---@class neotest.consumers.watch.Watcher ---@field lsp_client nio.lsp.Client ---@field autocmd_id? string +---@field tree neotest.Tree +---@field discover_positions_event nio.control.Future local Watcher = {} function Watcher:new(lsp_client) @@ -159,6 +161,9 @@ function Watcher:watch(tree, args) logger.debug("Built dependencies in", elapsed, "ms for", tree:data().id, ":", dependencies) local dependants = self:_build_dependants(dependencies) + self.tree = tree + self.discover_positions_event = nio.control.future() + self.autocmd_id = nio.api.nvim_create_autocmd("BufWritePost", { callback = function(autocmd_args) if type(args.run_predicate) == "function" and not args.run_predicate(autocmd_args.buf) then @@ -172,6 +177,9 @@ function Watcher:watch(tree, args) return end + self.discover_positions_event.wait() + self.discover_positions_event = nio.control.future() + if tree:data().type ~= "dir" then run.run(vim.tbl_extend("keep", { tree:data().id }, args)) else