diff --git a/init.lua b/init.lua index a50c76f..c9b7a35 100644 --- a/init.lua +++ b/init.lua @@ -21,21 +21,21 @@ vim.o.relativenumber = true vim.cmd.set("splitright") vim.keymap.set("n", "/", function() vim.cmd.vnew() -end) +end, { desc = "Pane split right" }) vim.cmd.set("splitbelow") vim.keymap.set("n", "-", function() vim.cmd.new() -end) +end, { desc = "Pane split down" }) -vim.api.nvim_set_keymap('n', '', ':wincmd k', { noremap = true, silent = true }); -vim.api.nvim_set_keymap('n', '', ':wincmd h', { noremap = true, silent = true }); -vim.api.nvim_set_keymap('n', '', ':wincmd j', { noremap = true, silent = true }); -vim.api.nvim_set_keymap('n', '', ':wincmd l', { noremap = true, silent = true }); +vim.api.nvim_set_keymap('n', '', ':wincmd k', { noremap = true, silent = true, desc = "Move to up windows" }); +vim.api.nvim_set_keymap('n', '', ':wincmd h', { noremap = true, silent = true, desc = "Move to left windows" }); +vim.api.nvim_set_keymap('n', '', ':wincmd j', { noremap = true, silent = true, desc = "Move to down windows" }); +vim.api.nvim_set_keymap('n', '', ':wincmd l', { noremap = true, silent = true, desc = "Move to right windows" }); -vim.api.nvim_set_keymap('n', 'gb', ':bnext', { noremap = true, silent = true }); +vim.api.nvim_set_keymap('n', 'gb', ':bnext', { noremap = true, silent = true, desc = "Go back last buffer" }); -vim.api.nvim_set_keymap('t', '', '', { noremap = true, silent = true }); +vim.api.nvim_set_keymap('t', '', '', { noremap = true, silent = true, desc = "Escape Terminal" }); vim.api.nvim_create_autocmd('TermOpen', { group = vim.api.nvim_create_augroup('custom-term-open', { clear = true }), callback = function() @@ -47,8 +47,7 @@ vim.api.nvim_create_autocmd('TermOpen', { -- Telescope local builtin = require("telescope.builtin") -vim.keymap.set('n', '', builtin.find_files, {}) -vim.keymap.set('n', 'fg', builtin.live_grep, {}) +vim.keymap.set('n', 'fg', builtin.live_grep, { desc = "Telescope live grep" }) vim.keymap.set('n', 'gl', builtin.lsp_references, { desc = "Telescope show references" }) vim.keymap.set('n', 'd', builtin.diagnostics, { desc = "Telescope open diagnostics" }) vim.keymap.set('n', 'ff', builtin.find_files, { desc = "Telescope find files" }) @@ -56,19 +55,42 @@ vim.keymap.set('n', 'ff', builtin.find_files, { desc = "Telescope find f -- Formating vim.keymap.set("n", "gf", function() require("conform").format({ lsp_format = "fallback" }) -end, {}) +end, { desc = "Format buffer" }) -- Filesystem -vim.keymap.set("n", "e", ":Oil", {}) +vim.keymap.set("n", "e", ":Oil", { desc = "Open file explorer: OIL" }) + -- Neotest -vim.keymap.set("n", "no", require("neotest").output.open, {}) +local neotest = require("neotest") +vim.keymap.set("n", "ts", function() + neotest.summary.toggle() +end, { desc = "Neotest open summary" }) +vim.keymap.set("n", "to", neotest.output.open, { desc = "Neotest open output" }) +vim.keymap.set("n", "td", function() neotest.run.run({ suite = false, strategy = "dap" }) end, + { desc = "Neotest debug closest test" }) + +-- Debugging +local dap = require("dap") +vim.keymap.set("n", "db", dap.toggle_breakpoint, + { nowait = true, remap = false, desc = "Debug toggle breakpoint" }) +vim.keymap.set("n", "dc", dap.continue, { nowait = true, remap = false, desc = "Debug continue" }) +vim.keymap.set("n", "di", dap.step_into, { nowait = true, remap = false, desc = "Debug step into" }) +vim.keymap.set("n", "do", dap.step_over, { nowait = true, remap = false, desc = "Debug step over" }) +vim.keymap.set("n", "dr", dap.repl.open, { nowait = true, remap = false, desc = "Debug open repl" }) +vim.keymap.set("n", "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", "dl", dap.list_breakpoints, { nowait = true, remap = false, desc = "Debug list breakpoints" }) + -- Lsp Config -vim.keymap.set("n", "K", vim.lsp.buf.hover, {}) -vim.keymap.set("n", "gd", vim.lsp.buf.definition, {}) -vim.keymap.set({ "n", "v" }, "ca", vim.lsp.buf.code_action, {}) -vim.keymap.set("n", "cr", vim.lsp.buf.rename, {}) +vim.keymap.set("n", "K", vim.lsp.buf.hover, { desc = "Show hover information" }) +vim.keymap.set("n", "gd", vim.lsp.buf.definition, { desc = "Goto definition" }) +vim.keymap.set({ "n", "v" }, "ca", vim.lsp.buf.code_action, { desc = "LSP code action" }) +vim.keymap.set("n", "cr", vim.lsp.buf.rename, { desc = "LSP rename" }) -- Motions vim.keymap.set("n", "", "zz", {}) diff --git a/lazy-lock.json b/lazy-lock.json index 125daf0..f4cda2e 100644 --- a/lazy-lock.json +++ b/lazy-lock.json @@ -9,11 +9,15 @@ "lazy.nvim": { "branch": "main", "commit": "85c7ff3711b730b4030d03144f6db6375044ae82" }, "lazydev.nvim": { "branch": "main", "commit": "5231c62aa83c2f8dc8e7ba957aa77098cda1257d" }, "lualine.nvim": { "branch": "master", "commit": "3946f0122255bc377d14a59b27b609fb3ab25768" }, + "mason-nvim-dap.nvim": { "branch": "main", "commit": "9a10e096703966335bd5c46c8c875d5b0690dade" }, "mason.nvim": { "branch": "main", "commit": "ad7146aa61dcaeb54fa900144d768f040090bff0" }, "mini.icons": { "branch": "main", "commit": "ff2e4f1d29f659cc2bad0f9256f2f6195c6b2428" }, "neotest": { "branch": "master", "commit": "deadfb1af5ce458742671ad3a013acb9a6b41178" }, "neotest-go": { "branch": "main", "commit": "59b50505053f9c45a9febb79e11a56206c3e3901" }, "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-lspconfig": { "branch": "master", "commit": "c8503e63c6afab3ed34b49865a4a4edbb1ebf4a8" }, "nvim-nio": { "branch": "master", "commit": "21f5324bfac14e22ba26553caf69ec76ae8a7662" }, @@ -23,5 +27,6 @@ "plenary.nvim": { "branch": "master", "commit": "b9fd5226c2f76c951fc8ed5923d85e4de065e509" }, "telescope-ui-select.nvim": { "branch": "master", "commit": "6e51d7da30bd139a6950adf2a47fda6df9fa06d2" }, "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" } } diff --git a/lua/plugins/dap.lua b/lua/plugins/dap.lua new file mode 100644 index 0000000..6d63dfa --- /dev/null +++ b/lua/plugins/dap.lua @@ -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 +} diff --git a/lua/plugins/linter.lua b/lua/plugins/linter.lua index 55dceda..38800db 100644 --- a/lua/plugins/linter.lua +++ b/lua/plugins/linter.lua @@ -6,7 +6,7 @@ return { python = { 'dmypy' } } - vim.api.nvim_create_autocmd({ "BufEnter", "BufWritePost", "TextChanged", "InsertLeave" }, { + vim.api.nvim_create_autocmd({ "BufEnter", "BufWritePost", "InsertLeave" }, { callback = function() -- try_lint without arguments runs the linters defined in `linters_by_ft` -- for the current filetype diff --git a/lua/plugins/which-key.lua b/lua/plugins/which-key.lua new file mode 100644 index 0000000..52806d5 --- /dev/null +++ b/lua/plugins/which-key.lua @@ -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 = { + { + "?", + function() + require("which-key").show({ global = false }) + end, + desc = "Buffer Local Keymaps (which-key)", + }, + }, + config = function() + local wk = require("which-key") + wk.add({ + { "d", group = "Debug" }, + { "f", group = "Files" }, + { "t", group = "Test" }, + { "c", group = "Code" }, + }) + end +}