1
0
mirror of https://github.com/dcarrillo/dotfiles.git synced 2025-07-01 23:19:25 +00:00

[neovim] Add commands and keymaps to Neotest

This commit is contained in:
2024-02-04 17:55:49 +01:00
parent 6bd5f85550
commit b80f54b07c
3 changed files with 47 additions and 7 deletions

View File

@ -138,11 +138,25 @@ keymap(
vim.tbl_extend("force", opts, { desc = "Format the current buffer or selection" })
)
-- Neotest
keymap(
"n",
"<leader>tr",
"<cmd>RunTest<cr>",
vim.tbl_extend("force", opts, { desc = "Run test on the current function" })
)
keymap(
"n",
"<leader>tf",
"<cmd>RunTestFile<cr>",
vim.tbl_extend("force", opts, { desc = "Run tests on the current file" })
)
-- Better paste
keymap("v", "p", "P", vim.tbl_extend("force", opts, { desc = "Paste" }))
-- Press jk fast to enter
keymap("i", "jk", "<ESC>", vim.tbl_extend("force", opts, { desc = "Enter in insert mode" }))
-- Press jk fast to exit insert mode
keymap("i", "jk", "<ESC>", vim.tbl_extend("force", opts, { desc = "Exit insert mode" }))
-- Stay in indent mode
keymap("v", "<", "<gv", opts)

View File

@ -1,4 +1,5 @@
local neotest_ns = vim.api.nvim_create_namespace("neotest")
vim.diagnostic.config({
virtual_text = {
format = function(diagnostic)
@ -7,8 +8,33 @@ vim.diagnostic.config({
end,
},
}, neotest_ns)
require("neotest").setup({
vim.api.nvim_create_user_command("CopyDirectoryPath", function()
local path = vim.fn.expand("%:p:h")
vim.fn.setreg("+", path)
vim.notify('Copied "' .. path .. '" to the clipboard!')
end, {})
local neotest = require("neotest")
neotest.setup({
adapters = {
require("neotest-go"),
require("neotest-go")({
recursive_run = true,
experimental = {
test_table = true,
},
args = { "-count=1" },
}),
},
})
vim.api.nvim_create_user_command("RunTest", function()
neotest.run.run()
end, {})
vim.api.nvim_create_user_command("RunTestFile", function()
neotest.run.run(vim.fn.expand('%'))
end, {})