diff --git a/lua/custom/plugins/neotest.lua b/lua/custom/plugins/neotest.lua index f94fa35..fc0084f 100644 --- a/lua/custom/plugins/neotest.lua +++ b/lua/custom/plugins/neotest.lua @@ -9,102 +9,7 @@ return { 'alfaix/neotest-gtest', 'andythigpen/nvim-coverage', }, - keys = { - { - 'tn', - function() - local neotest = require('neotest') - neotest.run.run() - end, - desc = 'Test: Run nearest', - }, - { - 'tf', - function() - local neotest = require('neotest') - neotest.run.run(vim.fn.expand('%')) - end, - desc = 'Test: Run file', - }, - { - 'ta', - function() - local neotest = require('neotest') - neotest.run.run(vim.fn.getcwd()) - end, - desc = 'Test: Run all (cwd)', - }, - { - 'td', - function() - local neotest = require('neotest') - neotest.run.run({ strategy = 'dap' }) - end, - desc = 'Test: Debug nearest', - }, - { - 'tx', - function() - require('neotest').run.stop() - end, - desc = 'Test: Stop', - }, - { - 'ts', - function() - require('neotest').summary.toggle() - end, - desc = 'Test: Toggle summary', - }, - { - 'to', - function() - require('neotest').output.open({ enter = true, auto_close = false }) - end, - desc = 'Test: Show output', - }, - { - 'tw', - function() - require('neotest').watch.toggle(vim.fn.expand('%')) - end, - desc = 'Test: Watch file', - }, - { - ']t', - function() - require('neotest').jump.next({ status = 'failed' }) - end, - desc = 'Test: Next failed', - }, - { - '[t', - function() - require('neotest').jump.prev({ status = 'failed' }) - end, - desc = 'Test: Prev failed', - }, - { - 'tC', - function() - local ok, coverage = pcall(require, 'coverage') - if ok then - coverage.toggle() - end - end, - desc = 'Test: Toggle coverage', - }, - { - 'tL', - function() - local ok, coverage = pcall(require, 'coverage') - if ok then - coverage.load(true) - end - end, - desc = 'Test: Load coverage', - }, - }, + event = 'VeryLazy', config = function() local neotest = require('neotest') @@ -117,9 +22,6 @@ return { require('neotest-gtest').setup({ debug_adapter = 'codelldb', }), - require('neotest-gotest')({ - args = { '-count=1', '-timeout=30s' }, - }), }, output = { open_on_run = false }, summary = { open = 'botright vsplit | vertical resize 60' }, @@ -131,6 +33,61 @@ return { auto_reload = true, }) end + + -- Keymaps (defined after setup to ensure modules are available) + vim.keymap.set('n', 'tn', function() + neotest.run.run() + end, { desc = 'Test: Run nearest' }) + + vim.keymap.set('n', 'tf', function() + neotest.run.run(vim.fn.expand('%')) + end, { desc = 'Test: Run file' }) + + vim.keymap.set('n', 'ta', function() + neotest.run.run(vim.fn.getcwd()) + end, { desc = 'Test: Run all (cwd)' }) + + vim.keymap.set('n', 'td', function() + neotest.run.run({ strategy = 'dap' }) + end, { desc = 'Test: Debug nearest' }) + + vim.keymap.set('n', 'tx', function() + neotest.run.stop() + end, { desc = 'Test: Stop' }) + + vim.keymap.set('n', 'ts', function() + neotest.summary.toggle() + end, { desc = 'Test: Toggle summary' }) + + vim.keymap.set('n', 'to', function() + neotest.output.open({ enter = true, auto_close = false }) + end, { desc = 'Test: Show output' }) + + vim.keymap.set('n', 'tw', function() + neotest.watch.toggle(vim.fn.expand('%')) + end, { desc = 'Test: Watch file' }) + + vim.keymap.set('n', ']t', function() + neotest.jump.next({ status = 'failed' }) + end, { desc = 'Test: Next failed' }) + + vim.keymap.set('n', '[t', function() + neotest.jump.prev({ status = 'failed' }) + end, { desc = 'Test: Prev failed' }) + + vim.keymap.set('n', 'tC', function() + local ok, cov = pcall(require, 'coverage') + if ok then + cov.toggle() + end + end, { desc = 'Test: Toggle coverage' }) + + vim.keymap.set('n', 'tL', function() + local ok, cov = pcall(require, 'coverage') + if ok then + cov.load(true) + end + end, { desc = 'Test: Load coverage' }) end, }, }