diff --git a/doc/neotest.txt b/doc/neotest.txt index 4386813f..afcc576b 100644 --- a/doc/neotest.txt +++ b/doc/neotest.txt @@ -74,6 +74,7 @@ neotest.setup({user_config}) *neotest.setup()* running = "NeotestRunning", select_win = "NeotestWinSelect", skipped = "NeotestSkipped", + target = "NeotestTarget", test = "NeotestTest" }, icons = { @@ -118,6 +119,7 @@ neotest.setup({user_config}) *neotest.setup()* mappings = { attach = "a", clear_marked = "M", + clear_target = "T", expand = { "", "<2-LeftMouse>" }, expand_all = "e", jumpto = "i", @@ -126,7 +128,8 @@ neotest.setup({user_config}) *neotest.setup()* run = "r", run_marked = "R", short = "O", - stop = "u" + stop = "u", + target = "t" } } } @@ -492,6 +495,15 @@ neotest.summary.clear_marked({args}) *neotest.summary.clear_marked()* {adapter} (string) Adapter ID, if not given all adapters are used +neotest.summary.target({adapter_id}, {position_id}) *neotest.summary.target()* + Set the target for an adapter tree + + + Parameters: ~ + {adapter_id} (string) + {position_id} (string|nil) Position ID to target, nil to reset target + + ================================================================================ *neotest.jump* diff --git a/lua/neotest/config/init.lua b/lua/neotest/config/init.lua index 2d4cad28..65c63519 100644 --- a/lua/neotest/config/init.lua +++ b/lua/neotest/config/init.lua @@ -15,6 +15,7 @@ vim.cmd([[ hi default NeotestAdapterName ctermfg=Red guifg=#F70067 hi default NeotestWinSelect ctermfg=Cyan guifg=#00f1f5 gui=bold hi default NeotestMarked ctermfg=Brown guifg=#F79000 gui=bold + hi default NeotestTarget ctermfg=Red guifg=#F70067 ]]) ---@class neotest.Config @@ -114,6 +115,7 @@ local default_config = { adapter_name = "NeotestAdapterName", select_win = "NeotestWinSelect", marked = "NeotestMarked", + target = "NeotestTarget", }, floating = { border = "rounded", @@ -143,6 +145,8 @@ local default_config = { mark = "m", run_marked = "R", clear_marked = "M", + target = "t", + clear_target = "T", }, }, output = { diff --git a/lua/neotest/consumers/summary/component.lua b/lua/neotest/consumers/summary/component.lua index 443497a9..4aaca4ef 100644 --- a/lua/neotest/consumers/summary/component.lua +++ b/lua/neotest/consumers/summary/component.lua @@ -10,11 +10,13 @@ local lib = require("neotest.lib") ---@field child_components table ---@field marked table ---@field adapter_id integer +---@field target string? local SummaryComponent = {} function SummaryComponent:new(client, adapter_id) local elem = { client = client, + target = nil, expanded_positions = {}, adapter_id = adapter_id, marked = {}, @@ -37,6 +39,20 @@ end ---@param canvas Canvas ---@param tree neotest.Tree function SummaryComponent:render(canvas, tree, expanded, focused, indent) + if self.target then + tree = tree:get_key(self.target) + if not tree then + return + end + canvas:add_mapping("clear_target", function() + require("neotest").summary.target(self.adapter_id) + end) + canvas:write(tree:data().name .. "\n", { group = config.highlights.target }) + end + self:_render(canvas, tree, expanded, focused, indent) +end + +function SummaryComponent:_render(canvas, tree, expanded, focused, indent) indent = indent or "" local children = tree:children() local neotest = require("neotest") @@ -95,7 +111,14 @@ function SummaryComponent:render(canvas, tree, expanded, focused, indent) neotest.summary.render(positions) end) ) + + canvas:add_mapping("target", function() + neotest.summary.target(self.adapter_id, position.id) + end) end + canvas:add_mapping("clear_target", function() + neotest.summary.target(self.adapter_id) + end) if position.type ~= "dir" then canvas:add_mapping("jumpto", function() local buf = vim.fn.bufadd(position.path) @@ -164,7 +187,7 @@ function SummaryComponent:render(canvas, tree, expanded, focused, indent) canvas:write(position.name .. "\n", { group = name_groups }) if self.expanded_positions[position.id] then - self:render(canvas, node, expanded, focused, chid_indent) + self:_render(canvas, node, expanded, focused, chid_indent) end end end diff --git a/lua/neotest/consumers/summary/init.lua b/lua/neotest/consumers/summary/init.lua index 5d20f543..438d1ad1 100644 --- a/lua/neotest/consumers/summary/init.lua +++ b/lua/neotest/consumers/summary/init.lua @@ -1,3 +1,4 @@ +local lib = require("neotest.lib") local logger = require("neotest.logging") local config = require("neotest.config") local Canvas = require("neotest.consumers.summary.canvas") @@ -248,6 +249,18 @@ function neotest.summary.clear_marked(args) render() end +---Set the target for an adapter tree +---@param adapter_id string +---@param position_id string | nil: Position ID to target, nil to reset target +function neotest.summary.target(adapter_id, position_id) + local component = components[adapter_id] + if not component then + lib.notify(("No tree found for adapter %s"):format(adapter_id)) + end + component.target = position_id + render() +end + function neotest.summary.expand(pos_id, recursive) async.run(function() expand(pos_id, recursive)