From 52584d61e9186529905cea6468e303653c08a13c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ensar=20Saraj=C4=8Di=C4=87?= Date: Wed, 3 Mar 2021 18:07:02 +0100 Subject: [PATCH] Prepare nvim.dap for python --- .../config/nvim/after/ftplugin/gitcommit.vim | 6 +-- .../config/nvim/after/ftplugin/python.vim | 6 ++- symlinks/config/nvim/lua/plugin/dap.lua | 52 +++++++++++++++++++ 3 files changed, 60 insertions(+), 4 deletions(-) diff --git a/symlinks/config/nvim/after/ftplugin/gitcommit.vim b/symlinks/config/nvim/after/ftplugin/gitcommit.vim index 19915a8..9b64d11 100644 --- a/symlinks/config/nvim/after/ftplugin/gitcommit.vim +++ b/symlinks/config/nvim/after/ftplugin/gitcommit.vim @@ -1,4 +1,4 @@ -set textwidth=72 -set spell -set cc=+1 +setlocal textwidth=72 +setlocal spell +setlocal cc=+1 let b:undo_ftplugin .= '|setlocal textwidth< spell< cc<' diff --git a/symlinks/config/nvim/after/ftplugin/python.vim b/symlinks/config/nvim/after/ftplugin/python.vim index 3e80fcc..6cea5de 100644 --- a/symlinks/config/nvim/after/ftplugin/python.vim +++ b/symlinks/config/nvim/after/ftplugin/python.vim @@ -4,4 +4,8 @@ " Without this, weird issues occurred with asdf + direnv + python virtualenv setlocal shell=/bin/sh -let b:undo_ftplugin .= "|setlocal shell<" + +setlocal textwidth=79 +setlocal cc=+1 + +let b:undo_ftplugin .= "|setlocal shell< textwidth< cc<" diff --git a/symlinks/config/nvim/lua/plugin/dap.lua b/symlinks/config/nvim/lua/plugin/dap.lua index 043037d..aea6df2 100644 --- a/symlinks/config/nvim/lua/plugin/dap.lua +++ b/symlinks/config/nvim/lua/plugin/dap.lua @@ -10,5 +10,57 @@ dap.adapters.python = { args = { '-m', 'debugpy.adapter' }; } +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"; + + + program = "${file}"; -- This configuration will launch the current file if used. + }, +} + -- Nvim DAP Treesitter integration vim.g.dap_virtual_text = true + +-- Keymaps +local function set_keymap(...) vim.api.nvim_set_keymap(...) end + +default_opts = {noremap = true, silent = true} +set_keymap('n', 'db', "lua require'dap'.toggle_breakpoint()", default_opts) +set_keymap('n', 'dc', "lua require'dap'.continue()", default_opts) +set_keymap('n', 'dso', "lua require'dap'.step_over()", default_opts) +set_keymap('n', 'dsi', "lua require'dap'.step_into()", default_opts) +set_keymap('n', 'dro', "lua require'dap'.open()", default_opts) + +-- Debugger Hover map +local api = vim.api +local keymap_restore = {} +dap.custom_event_handlers['event_initialized']['me'] = function() + for _, buf in pairs(api.nvim_list_bufs()) do + local keymaps = api.nvim_buf_get_keymap(buf, 'n') + for _, keymap in pairs(keymaps) do + if keymap.lhs == "K" then + table.insert(keymap_restore, keymap) + api.nvim_buf_del_keymap(buf, 'n', 'K') + end + end + end + api.nvim_set_keymap( + 'n', 'K', 'lua require("dap.ui.variables").hover()', { silent = true }) +end + +dap.custom_event_handlers['event_terminated']['me'] = function() + for _, keymap in pairs(keymap_restore) do + api.nvim_buf_set_keymap( + keymap.buffer, + keymap.mode, + keymap.lhs, + keymap.rhs, + { silent = keymap.silent == 1 } + ) + end + keymap_restore = {} +end