2024-04-03 17:27:42 +00:00
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 ' ,
2024-04-03 20:23:40 +00:00
command = ' /root/.local/share/nvim/mason/packages/debugpy/venv/bin/python ' ,
2024-04-03 17:27:42 +00:00
args = { ' -m ' , ' debugpy.adapter ' } ,
2024-04-03 20:23:40 +00:00
--args = { '-m', 'debugpy.adapter' },
2024-04-03 17:27:42 +00:00
}
-- setup dapui
local dapui = require ( " dapui " )
2024-04-03 19:51:16 +00:00
dapui.setup ( )
2024-04-03 17:27:42 +00:00
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 {
2024-04-03 19:51:16 +00:00
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)
2024-04-03 17:27:42 +00:00
highlight_changed_variables = true , -- highlight changed values with NvimDapVirtualTextChanged, else always NvimDapVirtualText
2024-04-03 19:51:16 +00:00
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)
2024-04-03 17:27:42 +00:00
--- 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:
2024-04-03 19:51:16 +00:00
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!)
2024-04-03 17:27:42 +00:00
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
}