From a16fcac4633fb380a1a096c1f701931782b1b4e8 Mon Sep 17 00:00:00 2001 From: Garrett Andreson Date: Fri, 10 May 2024 13:27:49 -0600 Subject: [PATCH] Adding python --- lua/custom/plugins/nvim-dap-python.lua | 44 +++++++ lua/custom/plugins/nvim-dap-ui.lua | 115 +++++++++++++++++++ lua/custom/plugins/nvim-dap-virtual-text.lua | 18 +++ 3 files changed, 177 insertions(+) create mode 100644 lua/custom/plugins/nvim-dap-python.lua create mode 100644 lua/custom/plugins/nvim-dap-ui.lua create mode 100644 lua/custom/plugins/nvim-dap-virtual-text.lua diff --git a/lua/custom/plugins/nvim-dap-python.lua b/lua/custom/plugins/nvim-dap-python.lua new file mode 100644 index 00000000..25c4e92b --- /dev/null +++ b/lua/custom/plugins/nvim-dap-python.lua @@ -0,0 +1,44 @@ +return { + -- https://github.com/mfussenegger/nvim-dap-python + 'mfussenegger/nvim-dap-python', + ft = 'python', + dependencies = { + -- https://github.com/mfussenegger/nvim-dap + 'mfussenegger/nvim-dap', + }, + config = function() + -- Update the path passed to setup to point to your system or virtual env python binary + require('dap-python').setup '/Library/Frameworks/Python.framework/Versions/3.12/bin/python3' + vim.keymap.set('n', 'bb', "lua require'dap'.toggle_breakpoint()") + vim.keymap.set('n', 'bc', "lua require'dap'.set_breakpoint(vim.fn.input('Breakpoint condition: '))") + vim.keymap.set('n', 'bl', "lua require'dap'.set_breakpoint(nil, nil, vim.fn.input('Log point message: '))") + vim.keymap.set('n', 'br', "lua require'dap'.clear_breakpoints()") + vim.keymap.set('n', 'ba', 'Telescope dap list_breakpoints') + vim.keymap.set('n', 'dc', "lua require'dap'.continue()") + vim.keymap.set('n', 'dj', "lua require'dap'.step_over()") + vim.keymap.set('n', 'dk', "lua require'dap'.step_into()") + vim.keymap.set('n', 'do', "lua require'dap'.step_out()") + vim.keymap.set('n', 'dd', function() + require('dap').disconnect() + require('dapui').close() + end) + vim.keymap.set('n', 'dt', function() + require('dap').terminate() + require('dapui').close() + end) + vim.keymap.set('n', 'dr', "lua require'dap'.repl.toggle()") + vim.keymap.set('n', 'dl', "lua require'dap'.run_last()") + vim.keymap.set('n', 'di', function() + require('dap.ui.widgets').hover() + end) + vim.keymap.set('n', 'd?', function() + local widgets = require 'dap.ui.widgets' + widgets.centered_float(widgets.scopes) + end) + vim.keymap.set('n', 'df', 'Telescope dap frames') + vim.keymap.set('n', 'dh', 'Telescope dap commands') + vim.keymap.set('n', 'de', function() + require('telescope.builtin').diagnostics { default_text = ':E:' } + end) + end, +} diff --git a/lua/custom/plugins/nvim-dap-ui.lua b/lua/custom/plugins/nvim-dap-ui.lua new file mode 100644 index 00000000..e515708d --- /dev/null +++ b/lua/custom/plugins/nvim-dap-ui.lua @@ -0,0 +1,115 @@ +-- Debugging Support +return { + -- https://github.com/rcarriga/nvim-dap-ui + 'rcarriga/nvim-dap-ui', + event = 'VeryLazy', + dependencies = { + -- https://github.com/mfussenegger/nvim-dap + 'mfussenegger/nvim-dap', + -- https://github.com/theHamsta/nvim-dap-virtual-text + 'theHamsta/nvim-dap-virtual-text', -- inline variable text while debugging + -- https://github.com/nvim-telescope/telescope-dap.nvim + 'nvim-telescope/telescope-dap.nvim', -- telescope integration with dap + 'nvim-neotest/nvim-nio', + }, + opts = { + controls = { + element = 'repl', + enabled = false, + icons = { + disconnect = '', + pause = '', + play = '', + run_last = '', + step_back = '', + step_into = '', + step_out = '', + step_over = '', + terminate = '', + }, + }, + element_mappings = {}, + expand_lines = true, + floating = { + border = 'single', + mappings = { + close = { 'q', '' }, + }, + }, + force_buffers = true, + icons = { + collapsed = '', + current_frame = '', + expanded = '', + }, + layouts = { + { + elements = { + { + id = 'scopes', + size = 0.50, + }, + { + id = 'stacks', + size = 0.30, + }, + { + id = 'watches', + size = 0.10, + }, + { + id = 'breakpoints', + size = 0.10, + }, + }, + size = 40, + position = 'left', -- Can be "left" or "right" + }, + { + elements = { + 'repl', + 'console', + }, + size = 10, + position = 'bottom', -- Can be "bottom" or "top" + }, + }, + mappings = { + edit = 'e', + expand = { '', '<2-LeftMouse>' }, + open = 'o', + remove = 'd', + repl = 'r', + toggle = 't', + }, + render = { + indent = 1, + max_value_lines = 100, + }, + }, + config = function(_, opts) + local dap = require 'dap' + require('dapui').setup(opts) + + dap.listeners.after.event_initialized['dapui_config'] = function() + require('dapui').open() + end + + dap.listeners.before.event_terminated['dapui_config'] = function() + -- Commented to prevent DAP UI from closing when unit tests finish + -- require('dapui').close() + end + + dap.listeners.before.event_exited['dapui_config'] = function() + -- Commented to prevent DAP UI from closing when unit tests finish + -- require('dapui').close() + end + + -- Add dap configurations based on your language/adapter settings + -- https://github.com/mfussenegger/nvim-dap/wiki/Debug-Adapter-installation + -- dap.configurations.xxxxxxxxxx = { + -- { + -- }, + -- } + end, +} diff --git a/lua/custom/plugins/nvim-dap-virtual-text.lua b/lua/custom/plugins/nvim-dap-virtual-text.lua new file mode 100644 index 00000000..ad060a73 --- /dev/null +++ b/lua/custom/plugins/nvim-dap-virtual-text.lua @@ -0,0 +1,18 @@ +-- Inline Debug Text +return { + -- https://github.com/theHamsta/nvim-dap-virtual-text + 'theHamsta/nvim-dap-virtual-text', + lazy = true, + opts = { + -- Display debug text as a comment + commented = true, + -- Customize virtual text + 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, + }, +}