Add debugging, keymaps for tests and which-key

This commit is contained in:
Zam Kokott
2025-12-04 08:49:57 +00:00
parent 6d7b993478
commit 6073938c44
5 changed files with 150 additions and 19 deletions

View File

@@ -21,21 +21,21 @@ vim.o.relativenumber = true
vim.cmd.set("splitright") vim.cmd.set("splitright")
vim.keymap.set("n", "<leader>/", function() vim.keymap.set("n", "<leader>/", function()
vim.cmd.vnew() vim.cmd.vnew()
end) end, { desc = "Pane split right" })
vim.cmd.set("splitbelow") vim.cmd.set("splitbelow")
vim.keymap.set("n", "<leader>-", function() vim.keymap.set("n", "<leader>-", function()
vim.cmd.new() vim.cmd.new()
end) end, { desc = "Pane split down" })
vim.api.nvim_set_keymap('n', '<c-k>', ':wincmd k<CR>', { noremap = true, silent = true }); vim.api.nvim_set_keymap('n', '<c-k>', ':wincmd k<CR>', { noremap = true, silent = true, desc = "Move to up windows" });
vim.api.nvim_set_keymap('n', '<c-h>', ':wincmd h<CR>', { noremap = true, silent = true }); vim.api.nvim_set_keymap('n', '<c-h>', ':wincmd h<CR>', { noremap = true, silent = true, desc = "Move to left windows" });
vim.api.nvim_set_keymap('n', '<c-j>', ':wincmd j<CR>', { noremap = true, silent = true }); vim.api.nvim_set_keymap('n', '<c-j>', ':wincmd j<CR>', { noremap = true, silent = true, desc = "Move to down windows" });
vim.api.nvim_set_keymap('n', '<c-l>', ':wincmd l<CR>', { noremap = true, silent = true }); vim.api.nvim_set_keymap('n', '<c-l>', ':wincmd l<CR>', { noremap = true, silent = true, desc = "Move to right windows" });
vim.api.nvim_set_keymap('n', 'gb', ':bnext<CR>', { noremap = true, silent = true }); vim.api.nvim_set_keymap('n', 'gb', ':bnext<CR>', { noremap = true, silent = true, desc = "Go back last buffer" });
vim.api.nvim_set_keymap('t', '<c-[><c-[>', '<C-\\><C-n>', { noremap = true, silent = true }); vim.api.nvim_set_keymap('t', '<c-[><c-[>', '<C-\\><C-n>', { noremap = true, silent = true, desc = "Escape Terminal" });
vim.api.nvim_create_autocmd('TermOpen', { vim.api.nvim_create_autocmd('TermOpen', {
group = vim.api.nvim_create_augroup('custom-term-open', { clear = true }), group = vim.api.nvim_create_augroup('custom-term-open', { clear = true }),
callback = function() callback = function()
@@ -47,8 +47,7 @@ vim.api.nvim_create_autocmd('TermOpen', {
-- Telescope -- Telescope
local builtin = require("telescope.builtin") local builtin = require("telescope.builtin")
vim.keymap.set('n', '<C-p>', builtin.find_files, {}) vim.keymap.set('n', '<leader>fg', builtin.live_grep, { desc = "Telescope live grep" })
vim.keymap.set('n', '<leader>fg', builtin.live_grep, {})
vim.keymap.set('n', 'gl', builtin.lsp_references, { desc = "Telescope show references" }) vim.keymap.set('n', 'gl', builtin.lsp_references, { desc = "Telescope show references" })
vim.keymap.set('n', '<leader>d', builtin.diagnostics, { desc = "Telescope open diagnostics" }) vim.keymap.set('n', '<leader>d', builtin.diagnostics, { desc = "Telescope open diagnostics" })
vim.keymap.set('n', '<leader>ff', builtin.find_files, { desc = "Telescope find files" }) vim.keymap.set('n', '<leader>ff', builtin.find_files, { desc = "Telescope find files" })
@@ -56,19 +55,42 @@ vim.keymap.set('n', '<leader>ff', builtin.find_files, { desc = "Telescope find f
-- Formating -- Formating
vim.keymap.set("n", "<leader>gf", function() vim.keymap.set("n", "<leader>gf", function()
require("conform").format({ lsp_format = "fallback" }) require("conform").format({ lsp_format = "fallback" })
end, {}) end, { desc = "Format buffer" })
-- Filesystem -- Filesystem
vim.keymap.set("n", "<leader>e", ":Oil<CR>", {}) vim.keymap.set("n", "<leader>e", ":Oil<CR>", { desc = "Open file explorer: OIL" })
-- Neotest -- Neotest
vim.keymap.set("n", "<leader>no", require("neotest").output.open, {}) local neotest = require("neotest")
vim.keymap.set("n", "<leader>ts", function()
neotest.summary.toggle()
end, { desc = "Neotest open summary" })
vim.keymap.set("n", "<leader>to", neotest.output.open, { desc = "Neotest open output" })
vim.keymap.set("n", "<leader>td", function() neotest.run.run({ suite = false, strategy = "dap" }) end,
{ desc = "Neotest debug closest test" })
-- Debugging
local dap = require("dap")
vim.keymap.set("n", "<leader>db", dap.toggle_breakpoint,
{ nowait = true, remap = false, desc = "Debug toggle breakpoint" })
vim.keymap.set("n", "<leader>dc", dap.continue, { nowait = true, remap = false, desc = "Debug continue" })
vim.keymap.set("n", "<leader>di", dap.step_into, { nowait = true, remap = false, desc = "Debug step into" })
vim.keymap.set("n", "<leader>do", dap.step_over, { nowait = true, remap = false, desc = "Debug step over" })
vim.keymap.set("n", "<leader>dr", dap.repl.open, { nowait = true, remap = false, desc = "Debug open repl" })
vim.keymap.set("n", "<leader>dq", function()
dap.terminate()
require("dapui").close()
require("nvim-dap-virtual-text").toggle()
end, { nowait = true, remap = false, desc = "Debug close" })
vim.keymap.set("n", "<leader>dl", dap.list_breakpoints, { nowait = true, remap = false, desc = "Debug list breakpoints" })
-- Lsp Config -- Lsp Config
vim.keymap.set("n", "K", vim.lsp.buf.hover, {}) vim.keymap.set("n", "K", vim.lsp.buf.hover, { desc = "Show hover information" })
vim.keymap.set("n", "gd", vim.lsp.buf.definition, {}) vim.keymap.set("n", "gd", vim.lsp.buf.definition, { desc = "Goto definition" })
vim.keymap.set({ "n", "v" }, "<leader>ca", vim.lsp.buf.code_action, {}) vim.keymap.set({ "n", "v" }, "<leader>ca", vim.lsp.buf.code_action, { desc = "LSP code action" })
vim.keymap.set("n", "<leader>cr", vim.lsp.buf.rename, {}) vim.keymap.set("n", "<leader>cr", vim.lsp.buf.rename, { desc = "LSP rename" })
-- Motions -- Motions
vim.keymap.set("n", "<C-d>", "<C-d>zz", {}) vim.keymap.set("n", "<C-d>", "<C-d>zz", {})

View File

@@ -9,11 +9,15 @@
"lazy.nvim": { "branch": "main", "commit": "85c7ff3711b730b4030d03144f6db6375044ae82" }, "lazy.nvim": { "branch": "main", "commit": "85c7ff3711b730b4030d03144f6db6375044ae82" },
"lazydev.nvim": { "branch": "main", "commit": "5231c62aa83c2f8dc8e7ba957aa77098cda1257d" }, "lazydev.nvim": { "branch": "main", "commit": "5231c62aa83c2f8dc8e7ba957aa77098cda1257d" },
"lualine.nvim": { "branch": "master", "commit": "3946f0122255bc377d14a59b27b609fb3ab25768" }, "lualine.nvim": { "branch": "master", "commit": "3946f0122255bc377d14a59b27b609fb3ab25768" },
"mason-nvim-dap.nvim": { "branch": "main", "commit": "9a10e096703966335bd5c46c8c875d5b0690dade" },
"mason.nvim": { "branch": "main", "commit": "ad7146aa61dcaeb54fa900144d768f040090bff0" }, "mason.nvim": { "branch": "main", "commit": "ad7146aa61dcaeb54fa900144d768f040090bff0" },
"mini.icons": { "branch": "main", "commit": "ff2e4f1d29f659cc2bad0f9256f2f6195c6b2428" }, "mini.icons": { "branch": "main", "commit": "ff2e4f1d29f659cc2bad0f9256f2f6195c6b2428" },
"neotest": { "branch": "master", "commit": "deadfb1af5ce458742671ad3a013acb9a6b41178" }, "neotest": { "branch": "master", "commit": "deadfb1af5ce458742671ad3a013acb9a6b41178" },
"neotest-go": { "branch": "main", "commit": "59b50505053f9c45a9febb79e11a56206c3e3901" }, "neotest-go": { "branch": "main", "commit": "59b50505053f9c45a9febb79e11a56206c3e3901" },
"neotest-python": { "branch": "master", "commit": "b0d3a861bd85689d8ed73f0590c47963a7eb1bf9" }, "neotest-python": { "branch": "master", "commit": "b0d3a861bd85689d8ed73f0590c47963a7eb1bf9" },
"nvim-dap": { "branch": "master", "commit": "5860c7c501eb428d3137ee22c522828d20cca0b3" },
"nvim-dap-ui": { "branch": "master", "commit": "cf91d5e2d07c72903d052f5207511bf7ecdb7122" },
"nvim-dap-virtual-text": { "branch": "master", "commit": "fbdb48c2ed45f4a8293d0d483f7730d24467ccb6" },
"nvim-lint": { "branch": "master", "commit": "baf7c91c2b868b12446df511d4cdddc98e9bf66e" }, "nvim-lint": { "branch": "master", "commit": "baf7c91c2b868b12446df511d4cdddc98e9bf66e" },
"nvim-lspconfig": { "branch": "master", "commit": "c8503e63c6afab3ed34b49865a4a4edbb1ebf4a8" }, "nvim-lspconfig": { "branch": "master", "commit": "c8503e63c6afab3ed34b49865a4a4edbb1ebf4a8" },
"nvim-nio": { "branch": "master", "commit": "21f5324bfac14e22ba26553caf69ec76ae8a7662" }, "nvim-nio": { "branch": "master", "commit": "21f5324bfac14e22ba26553caf69ec76ae8a7662" },
@@ -23,5 +27,6 @@
"plenary.nvim": { "branch": "master", "commit": "b9fd5226c2f76c951fc8ed5923d85e4de065e509" }, "plenary.nvim": { "branch": "master", "commit": "b9fd5226c2f76c951fc8ed5923d85e4de065e509" },
"telescope-ui-select.nvim": { "branch": "master", "commit": "6e51d7da30bd139a6950adf2a47fda6df9fa06d2" }, "telescope-ui-select.nvim": { "branch": "master", "commit": "6e51d7da30bd139a6950adf2a47fda6df9fa06d2" },
"telescope.nvim": { "branch": "master", "commit": "6312868392331c9c0f22725041f1ec2bef57c751" }, "telescope.nvim": { "branch": "master", "commit": "6312868392331c9c0f22725041f1ec2bef57c751" },
"tiny-inline-diagnostic.nvim": { "branch": "main", "commit": "08e65d82d48416ab140b3dea26eea4fb9739bc47" } "tiny-inline-diagnostic.nvim": { "branch": "main", "commit": "08e65d82d48416ab140b3dea26eea4fb9739bc47" },
"which-key.nvim": { "branch": "main", "commit": "3aab2147e74890957785941f0c1ad87d0a44c15a" }
} }

77
lua/plugins/dap.lua Normal file
View File

@@ -0,0 +1,77 @@
return {
"mfussenegger/nvim-dap",
event = "VeryLazy",
dependencies = {
"rcarriga/nvim-dap-ui",
"nvim-neotest/nvim-nio",
"jay-babu/mason-nvim-dap.nvim",
"theHamsta/nvim-dap-virtual-text",
},
config = function()
local mason_dap = require("mason-nvim-dap")
local dap = require("dap")
local ui = require("dapui")
local dap_virtual_text = require("nvim-dap-virtual-text")
-- Dap Virtual Text
dap_virtual_text.setup()
mason_dap.setup({
ensure_installed = { "python" },
automatic_installation = true,
handlers = {
function(config)
require("mason-nvim-dap").default_setup(config)
end,
},
})
-- Configurations
dap.configurations = {
python = {
{
-- The first three options are required by nvim-dap
type = "python", -- the type here established the link to the adapter definition: `dap.adapters.python`
request = "launch",
name = "Launch file",
-- Options below are for debugpy, see https://github.com/microsoft/debugpy/wiki/Debug-configuration-settings for supported options
program = "${file}", -- This configuration will launch the current file if used.
pythonPath = function()
-- debugpy supports launching an application with a different interpreter then the one used to launch debugpy itself.
-- The code below looks for a `venv` or `.venv` folder in the current directly and uses the python within.
-- You could adapt this - to for example use the `VIRTUAL_ENV` environment variable.
local cwd = vim.fn.getcwd()
if vim.fn.executable(cwd .. "/venv/bin/python") == 1 then
return cwd .. "/venv/bin/python"
elseif vim.fn.executable(cwd .. "/.venv/bin/python") == 1 then
return cwd .. "/.venv/bin/python"
else
return "/usr/bin/python"
end
end,
},
},
}
-- Dap UI
ui.setup()
vim.fn.sign_define("DapBreakpoint", { text = "🐞" })
dap.listeners.before.attach.dapui_config = function()
ui.open()
end
dap.listeners.before.launch.dapui_config = function()
ui.open()
end
dap.listeners.before.event_terminated.dapui_config = function()
ui.close()
end
dap.listeners.before.event_exited.dapui_config = function()
ui.close()
end
end
}

View File

@@ -6,7 +6,7 @@ return {
python = { 'dmypy' } python = { 'dmypy' }
} }
vim.api.nvim_create_autocmd({ "BufEnter", "BufWritePost", "TextChanged", "InsertLeave" }, { vim.api.nvim_create_autocmd({ "BufEnter", "BufWritePost", "InsertLeave" }, {
callback = function() callback = function()
-- try_lint without arguments runs the linters defined in `linters_by_ft` -- try_lint without arguments runs the linters defined in `linters_by_ft`
-- for the current filetype -- for the current filetype

27
lua/plugins/which-key.lua Normal file
View File

@@ -0,0 +1,27 @@
return {
"folke/which-key.nvim",
event = "VeryLazy",
opts = {
-- your configuration comes here
-- or leave it empty to use the default settings
-- refer to the configuration section below
},
keys = {
{
"<leader>?",
function()
require("which-key").show({ global = false })
end,
desc = "Buffer Local Keymaps (which-key)",
},
},
config = function()
local wk = require("which-key")
wk.add({
{ "<leader>d", group = "Debug" },
{ "<leader>f", group = "Files" },
{ "<leader>t", group = "Test" },
{ "<leader>c", group = "Code" },
})
end
}