From ef2af39c45dafd77f81dd1e0df54b11db876c9a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=B3n=C3=A1n=20Carrigan?= Date: Wed, 8 Mar 2023 08:59:41 +0000 Subject: [PATCH] feat(state): expose positions --- doc/neotest.txt | 18 ++++++++++++++++-- lua/neotest/consumers/state/init.lua | 13 +++++++++++++ lua/neotest/types/tree.lua | 4 ++-- 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/doc/neotest.txt b/doc/neotest.txt index 6360da26..23d1359a 100644 --- a/doc/neotest.txt +++ b/doc/neotest.txt @@ -676,6 +676,20 @@ Fields~ {skipped} `(integer)` {running} `(integer)` + *neotest.state.positions()* +`positions`({adapter_id}, {args}) + +Get the known positions for the entire suite or for a buffer. +Parameters~ +{adapter_id} `(string)` +{args?} `(neotest.state.PositionsArgs)` +Return~ +`(neotest.Tree)` | nil + + *neotest.state.PositionsArgs* +Fields~ +{buffer?} `(integer)` Returns positions for this buffer + ============================================================================== *neotest.Client* @@ -1357,13 +1371,13 @@ Return~ `Tree:iter_nodes`() Return~ -`(fun(): integer,)` neotest.Tree +`(fun(): integer,neotest.Tree)` *neotest.Tree:iter()* `Tree:iter`() Return~ -`(fun(): integer,)` neotest.Position +`(fun(): integer,neotest.Position)` *neotest.Tree:node()* `Tree:node`({index}) diff --git a/lua/neotest/consumers/state/init.lua b/lua/neotest/consumers/state/init.lua index 18fcb9d3..2dd0a34e 100644 --- a/lua/neotest/consumers/state/init.lua +++ b/lua/neotest/consumers/state/init.lua @@ -105,6 +105,19 @@ end ---@field skipped integer ---@field running integer +--- Get the known positions for the entire suite or for a buffer. +---@param adapter_id string +---@param args? neotest.state.PositionsArgs +---@return neotest.Tree | nil +function neotest.state.positions(adapter_id, args) + local state = state_from_args(adapter_id, args) + + return state and state.positions +end + +---@class neotest.state.PositionsArgs +---@field buffer? integer Returns positions for this buffer + neotest.summary = setmetatable(neotest.state, { __call = function(_, client) init(client) diff --git a/lua/neotest/types/tree.lua b/lua/neotest/types/tree.lua index 09529ea2..65700cc3 100644 --- a/lua/neotest/types/tree.lua +++ b/lua/neotest/types/tree.lua @@ -189,7 +189,7 @@ function neotest.Tree:root() return node end ----@return fun(): integer, neotest.Tree +---@return fun(): integer,neotest.Tree function neotest.Tree:iter_nodes() local child_i = 0 local total_i = 1 @@ -218,7 +218,7 @@ function neotest.Tree:iter_nodes() end end ----@return fun(): integer, neotest.Position +---@return fun(): integer,neotest.Position function neotest.Tree:iter() local node_iter = self:iter_nodes() return function()