From 1b4d92f8fe6ab66e26882e27ee4599d5e7948503 Mon Sep 17 00:00:00 2001 From: Maciej Lebiest Date: Wed, 3 Apr 2024 19:27:42 +0200 Subject: [PATCH] cleaning, initial DAP setup --- Containerfile | 19 +++++------ README.md | 8 +++++ lua/general.lua | 5 +++ lua/lazy-load.lua | 5 +++ lua/plugins/nvim-dap.lua | 74 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 101 insertions(+), 10 deletions(-) create mode 100644 lua/plugins/nvim-dap.lua diff --git a/Containerfile b/Containerfile index 5b9a575..112c9bb 100644 --- a/Containerfile +++ b/Containerfile @@ -1,12 +1,13 @@ -FROM registry.fedoraproject.org/fedora-minimal:39 +FROM registry.fedoraproject.org/fedora-minimal USER root +ENV LANG="en_US.UTF-8" + ENV NEOVIM_PKGS="\ wget \ unzip \ git \ - python3-pip \ neovim \ ripgrep \ fd-find \ @@ -14,7 +15,7 @@ ENV NEOVIM_PKGS="\ ShellCheck \ tree-sitter-cli \ wl-clipboard \ - clang" + python3-neovim" ENV GENERAL_PKGS="\ bash-completion \ @@ -22,9 +23,9 @@ ENV GENERAL_PKGS="\ fzf \ tar" -ENV PYTHON_DEVEL_PKGS="\ - python3\ - conda" +ENV PYTHON_DEVEL_PKGS="python3 python3-pip" + +ENV PIP_PKGS="debugpy" ENV BUILD_ONLY_PKGS="python3-devel" @@ -49,9 +50,9 @@ ENV MASON_PKGS=" \ yaml-language-server \ markdownlint \ ansible-language-server \ + ansible-lint \ helm-ls" -ENV PIP_PKGS="pynvim ansible ansible-lint" COPY . /root/.config/nvim # install system dependencies @@ -61,11 +62,9 @@ RUN dnf5 install -y \ dnf5 remove -y ${BUILD_ONLY_PKGS} && \ dnf5 -y autoremove && \ dnf5 clean all && \ - rm /root/.config/nvim/lazy-lock.json; \ nvim --headless \ +"MasonInstall ${MASON_PKGS}" \ - +qa ; \ - chown -R root:root /root/.local/share/nvim/mason/packages/sqlls/node_modules/sql-language-server/ && \ + +qa && \ echo '[ -f /usr/share/fzf/shell/key-bindings.bash ] && source /usr/share/fzf/shell/key-bindings.bash' >> /root/.bashrc ENTRYPOINT [ "/usr/bin/nvim" ] diff --git a/README.md b/README.md index 1984123..74eeddc 100644 --- a/README.md +++ b/README.md @@ -223,6 +223,14 @@ All that is saved in image, so that is why image is so heavy. |----|----| |\l|disable (search) highlighting| +#### DAP - Debug Adapter Protocol + +|keys|action| +|----|----| +|\ d b|set breakpoint| +|\ d c|launch/continue| +|\ d g|toggle dap UI| + #### Opened files navigation |keys|action| diff --git a/lua/general.lua b/lua/general.lua index b121d1e..ed2020f 100644 --- a/lua/general.lua +++ b/lua/general.lua @@ -39,6 +39,11 @@ map("n", "gs", ":Telescope git_status") map("n", "gc", ":Telescope git_commits") map("n", "gb", ":Telescope git_branches") +-- dap +map("n", "db", ":lua require'dap'.toggle_breakpoint()") +map("n", "dc", ":lua require'dap'.continue()") +map("n", "dg", ":lua require'dapui'.toggle()") + -- tab lines in normal and visual mode map("n", "", ">>") map("n", "", "<<") diff --git a/lua/lazy-load.lua b/lua/lazy-load.lua index 9213941..07df3b4 100644 --- a/lua/lazy-load.lua +++ b/lua/lazy-load.lua @@ -29,6 +29,11 @@ require("lazy").setup({ }) end, }, + { + "rcarriga/nvim-dap-ui", + dependencies = { "mfussenegger/nvim-dap", "nvim-neotest/nvim-nio", "theHamsta/nvim-dap-virtual-text" }, + config = require('plugins.nvim-dap').init + }, { 'hrsh7th/cmp-nvim-lsp' }, { 'hrsh7th/cmp-buffer' }, { 'hrsh7th/cmp-cmdline' }, diff --git a/lua/plugins/nvim-dap.lua b/lua/plugins/nvim-dap.lua new file mode 100644 index 0000000..76590ad --- /dev/null +++ b/lua/plugins/nvim-dap.lua @@ -0,0 +1,74 @@ +return { + init = function() + local dap = require('dap') + -- configurations + dap.configurations.python = { + { + type = 'python', + request = 'launch', + name = "Launch file", + program = "${file}", + pythonPath = function() + return '/usr/bin/python' + end, + }, + } + + -- adapters + dap.adapters.python = { + type = 'executable', + command = '/usr/bin/python', + args = { '-m', 'debugpy.adapter' }, + } + + -- setup dapui + local dapui = require("dapui") + dap.listeners.before.attach.dapui_config = function() + dapui.open() + end + dap.listeners.before.launch.dapui_config = function() + dapui.open() + end + dap.listeners.before.event_terminated.dapui_config = function() + dapui.close() + end + dap.listeners.before.event_exited.dapui_config = function() + dapui.close() + end + + -- setup dap virtual text + require("nvim-dap-virtual-text").setup { + enabled = true, -- enable this plugin (the default) + enabled_commands = true, -- create commands DapVirtualTextEnable, DapVirtualTextDisable, DapVirtualTextToggle, (DapVirtualTextForceRefresh for refreshing when debug adapter did not notify its termination) + highlight_changed_variables = true, -- highlight changed values with NvimDapVirtualTextChanged, else always NvimDapVirtualText + highlight_new_as_changed = false, -- highlight new variables in the same way as changed variables (if highlight_changed_variables) + show_stop_reason = true, -- show stop reason when stopped for exceptions + commented = false, -- prefix virtual text with comment string + only_first_definition = true, -- only show virtual text at first definition (if there are multiple) + all_references = false, -- show virtual text on all all references of the variable (not only definitions) + clear_on_continue = false, -- clear virtual text on "continue" (might cause flickering when stepping) + --- A callback that determines how a variable is displayed or whether it should be omitted + --- @param variable Variable https://microsoft.github.io/debug-adapter-protocol/specification#Types_Variable + --- @param buf number + --- @param stackframe dap.StackFrame https://microsoft.github.io/debug-adapter-protocol/specification#Types_StackFrame + --- @param node userdata tree-sitter node identified as variable definition of reference (see `:h tsnode`) + --- @param options nvim_dap_virtual_text_options Current options for nvim-dap-virtual-text + --- @return string|nil A text how the virtual text should be displayed or nil, if this variable shouldn't be displayed + display_callback = function(variable, buf, stackframe, node, options) + if options.virt_text_pos == 'inline' then + return ' = ' .. variable.value + else + return variable.name .. ' = ' .. variable.value + end + end, + -- position of virtual text, see `:h nvim_buf_set_extmark()`, default tries to inline the virtual text. Use 'eol' to set to end of line + virt_text_pos = vim.fn.has 'nvim-0.10' == 1 and 'inline' or 'eol', + + -- experimental features: + all_frames = false, -- show virtual text for all stack frames not only current. Only works for debugpy on my machine. + virt_lines = false, -- show virtual lines instead of virtual text (will flicker!) + virt_text_win_col = nil -- position the virtual text at a fixed window column (starting from the first text column) , + -- e.g. 80 to position at column 80, see `:h nvim_buf_set_extmark()` + } + end +}