From 11ce8f0f19e31d5b890aa2b0f831cf27f6cc1228 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Crist=C3=B3bal=20Gajardo=20Vera?= Date: Wed, 4 Sep 2024 07:38:30 -0400 Subject: [PATCH] refactor(neotest): replace table keybindings by opts function instead --- lua/astrocommunity/test/neotest/init.lua | 70 ++++++++++++++++-------- 1 file changed, 47 insertions(+), 23 deletions(-) diff --git a/lua/astrocommunity/test/neotest/init.lua b/lua/astrocommunity/test/neotest/init.lua index bd2bc7099..9100872e5 100644 --- a/lua/astrocommunity/test/neotest/init.lua +++ b/lua/astrocommunity/test/neotest/init.lua @@ -1,34 +1,58 @@ -local prefix = "T" +---@type LazySpec return { "nvim-neotest/neotest", lazy = true, dependencies = { "nvim-lua/plenary.nvim", "nvim-neotest/nvim-nio", + { "AstroNvim/astroui", opts = { icons = { Tests = "󰗇" } } }, { "AstroNvim/astrocore", - opts = { - mappings = { - n = { - [prefix] = { desc = "󰗇 Tests" }, - [prefix .. "t"] = { function() require("neotest").run.run() end, desc = "Run test" }, - [prefix .. "d"] = { function() require("neotest").run.run { strategy = "dap" } end, desc = "Debug test" }, - [prefix .. "f"] = { - function() require("neotest").run.run(vim.fn.expand "%") end, - desc = "Run all tests in file", - }, - [prefix .. "p"] = { - function() require("neotest").run.run(vim.fn.getcwd()) end, - desc = "Run all tests in project", - }, - [prefix .. ""] = { function() require("neotest").summary.toggle() end, desc = "Test Summary" }, - [prefix .. "o"] = { function() require("neotest").output.open() end, desc = "Output hover" }, - [prefix .. "O"] = { function() require("neotest").output_panel.toggle() end, desc = "Output window" }, - ["]T"] = { function() require("neotest").jump.next() end, desc = "Next test" }, - ["[T"] = { function() require("neotest").jump.prev() end, desc = "previous test" }, - }, - }, - }, + opts = function(_, opts) + local maps = opts.mappings + + local prefix = "T" + + maps.n[prefix] = { + desc = require("astroui").get_icon("Tests", 1, true) .. "Tests", + } + maps.n[prefix .. "t"] = { + function() require("neotest").run.run() end, + desc = "Run test", + } + maps.n[prefix .. "d"] = { + function() require("neotest").run.run { strategy = "dap" } end, + desc = "Debug test", + } + maps.n[prefix .. "f"] = { + function() require("neotest").run.run(vim.fn.expand "%") end, + desc = "Run all tests in file", + } + maps.n[prefix .. "p"] = { + function() require("neotest").run.run(vim.fn.getcwd()) end, + desc = "Run all tests in project", + } + maps.n[prefix .. ""] = { + function() require("neotest").summary.toggle() end, + desc = "Test Summary", + } + maps.n[prefix .. "o"] = { + function() require("neotest").output.open() end, + desc = "Output hover", + } + maps.n[prefix .. "O"] = { + function() require("neotest").output_panel.toggle() end, + desc = "Output window", + } + maps.n["]T"] = { + function() require("neotest").jump.next() end, + desc = "Next test", + } + maps.n["[T"] = { + function() require("neotest").jump.prev() end, + desc = "Previous test", + } + end, }, { "folke/neodev.nvim",