nvim-lua.kickstart.nvim/lua/kickstart/plugins/debug.lua

257 lines
7.3 KiB
Lua
Raw Normal View History

-- debug.lua
--
-- Shows how to use the DAP plugin to debug your code.
--
-- Primarily focused on configuring the debugger for Go, but can
-- be extended to other languages as well. That's why it's called
-- kickstart.nvim and not kitchen-sink.nvim ;)
return {
-- NOTE: Yes, you can install new plugins here!
'mfussenegger/nvim-dap',
-- NOTE: And you can specify dependencies as well
dependencies = {
-- Creates a beautiful debugger UI
'rcarriga/nvim-dap-ui',
2025-06-11 10:48:56 -04:00
'nvim-neotest/nvim-nio',
-- Installs the debug adapters for you
'williamboman/mason.nvim',
'jay-babu/mason-nvim-dap.nvim',
-- Add your own debuggers here
'leoluz/nvim-dap-go',
2024-03-03 12:42:45 -05:00
'microsoft/vscode-js-debug',
'mxsdev/nvim-dap-vscode-js',
2025-01-06 16:38:01 -05:00
'julianolf/nvim-dap-lldb',
'vadimcn/codelldb',
},
2025-06-11 10:48:56 -04:00
keys = {
{
'<F5>',
function()
require('dap').continue()
end,
desc = 'Debug: Start/Continue',
},
{
'<F1>',
function()
require('dap').step_into()
end,
desc = 'Debug: Step Into',
},
{
'<F2>',
function()
require('dap').step_over()
end,
desc = 'Debug: Step Over',
},
{
'<F3>',
function()
require('dap').step_out()
end,
desc = 'Debug: Step Out',
},
{
'<leader>b',
function()
require('dap').toggle_breakpoint()
end,
desc = 'Debug: Toggle Breakpoint',
},
{
'<leader>B',
function()
require('dap').set_breakpoint(vim.fn.input 'Breakpoint condition: ')
end,
desc = 'Debug: Set Breakpoint',
},
-- Toggle to see last session result. Without this, you can't see session output in case of unhandled exception.
{
'<F7>',
function()
require('dapui').toggle()
end,
desc = 'Debug: See last session result.',
},
},
config = function()
local dap = require 'dap'
local dapui = require 'dapui'
2025-01-06 16:38:01 -05:00
dap.adapters.lldb = {
type = 'server',
2025-06-11 10:48:56 -04:00
command = vim.fn.expand '$HOME/.local/share/nvim/mason/bin/codelldb',
2025-01-06 16:38:01 -05:00
host = '127.0.0.1',
port = 13000,
}
dap.configurations.cpp = {
{
name = 'Launch Editor (Development)',
type = 'lldb',
request = 'launch',
program = '/home/wil/dev/ue5/Engine/Binaries/Linux/UnrealEditor',
preLaunchTask = 'Editor Linux Development Build',
args = {
'/home/wil/dev/sro/game/SRO.uproject',
'--port ${port}',
},
-- terminal = 'integrated',
cwd = '/home/wil/dev/ue5',
-- visualizerFile = '/home/wil/dev/ue5/Engine/Extras/VisualStudioDebugging/Unreal.natvis',
-- showDisplayString = 'true',
},
}
require('mason-nvim-dap').setup {
-- Makes a best effort to setup the various debuggers with
-- reasonable debug configurations
2025-01-06 16:38:01 -05:00
automatic_installation = true,
-- You'll need to check that you have the required things installed
-- online, please don't ask me how to install them :)
ensure_installed = {
-- Update this to ensure that you have the debuggers for the langs you want
2025-06-11 10:48:56 -04:00
'delve',
2024-03-03 12:42:45 -05:00
'js',
'node2',
'cppdbg',
'python',
'javadbg',
'javatest',
},
2024-03-03 12:42:45 -05:00
handlers = {
2025-06-11 10:48:56 -04:00
-- function(config)
-- require('mason-nvim-dap').default_setup(config)
-- end,
},
}
-- Dap UI setup
-- For more information, see |:help nvim-dap-ui|
dapui.setup {
-- Set icons to characters that are more likely to work in every terminal.
-- Feel free to remove or use ones that you like more! :)
-- Don't feel like these are good choices.
icons = { expanded = '', collapsed = '', current_frame = '*' },
controls = {
icons = {
pause = '',
play = '',
step_into = '',
step_over = '',
step_out = '',
step_back = 'b',
run_last = '▶▶',
terminate = '',
2025-06-11 10:48:56 -04:00
disconnect = '',
},
},
}
dap.listeners.after.event_initialized['dapui_config'] = dapui.open
2025-06-11 10:48:56 -04:00
dap.listeners.before.event_terminated['dapui_config'] = dapui.close
dap.listeners.before.event_exited['dapui_config'] = dapui.close
2024-06-17 18:26:31 -04:00
dap.defaults.fallback.exception_breakpoints = { 'Notice', 'Warning', 'Error', 'Exception' }
2024-03-03 12:42:45 -05:00
-- Install golang specific config
2025-06-11 10:48:56 -04:00
require('dap-go').setup{
delve = {
detached = vim.fn.has 'win32' == 0,
},
}
2024-03-03 12:42:45 -05:00
-- Install javascript specific config
2025-06-11 10:48:56 -04:00
require('dap-vscode-js').setup {
debugger_path = vim.fn.stdpath 'data' .. '/mason/packages/js-debug-adapter',
debugger_cmd = { 'js-debug-adapter' },
adapters = { 'pwa-node', 'pwa-chrome', 'pwa-msedge', 'node-terminal', 'pwa-extensionHost' },
2024-03-03 12:42:45 -05:00
}
2025-06-11 10:48:56 -04:00
for _, jsLang in ipairs { 'typescript', 'javascript' } do
require('dap').configurations[jsLang] = {
2024-03-03 12:42:45 -05:00
{
2025-06-11 10:48:56 -04:00
type = 'pwa-node',
request = 'launch',
name = 'Launch file',
program = '${file}',
cwd = '${workspaceFolder}',
2024-03-03 12:42:45 -05:00
},
{
2025-06-11 10:48:56 -04:00
type = 'pwa-node',
request = 'attach',
name = 'Attach',
processId = require('dap.utils').pick_process,
cwd = '${workspaceFolder}',
2024-03-03 12:42:45 -05:00
},
{
2025-06-11 10:48:56 -04:00
type = 'pwa-node',
request = 'launch',
name = 'Debug Jest Tests',
2024-03-03 12:42:45 -05:00
-- trace = true, -- include debugger info
2025-06-11 10:48:56 -04:00
runtimeExecutable = 'node',
2024-03-03 12:42:45 -05:00
runtimeArgs = {
2025-06-11 10:48:56 -04:00
'./node_modules/jest/bin/jest.js',
'--runInBand',
2024-03-03 12:42:45 -05:00
},
2025-06-11 10:48:56 -04:00
rootPath = '${workspaceFolder}',
cwd = '${workspaceFolder}',
console = 'integratedTerminal',
internalConsoleOptions = 'neverOpen',
2024-03-03 12:42:45 -05:00
},
{
2024-06-17 18:26:31 -04:00
name = 'Debug Main Process (Electron)',
type = 'pwa-node',
request = 'launch',
program = '${workspaceFolder}/node_modules/.bin/electron',
args = {
'${workspaceFolder}/dist/index.js',
},
outFiles = {
'${workspaceFolder}/dist/*.js',
},
resolveSourceMapLocations = {
'${workspaceFolder}/dist/**/*.js',
'${workspaceFolder}/dist/*.js',
},
rootPath = '${workspaceFolder}',
cwd = '${workspaceFolder}',
sourceMaps = true,
skipFiles = { '<node_internals>/**' },
protocol = 'inspector',
console = 'integratedTerminal',
2024-03-03 12:42:45 -05:00
},
{
2024-06-17 18:26:31 -04:00
name = 'Compile & Debug Main Process (Electron)',
type = custom_adapter,
request = 'launch',
preLaunchTask = 'npm run build-ts',
program = '${workspaceFolder}/node_modules/.bin/electron',
args = {
'${workspaceFolder}/dist/index.js',
},
outFiles = {
'${workspaceFolder}/dist/*.js',
},
resolveSourceMapLocations = {
'${workspaceFolder}/dist/**/*.js',
'${workspaceFolder}/dist/*.js',
},
rootPath = '${workspaceFolder}',
cwd = '${workspaceFolder}',
sourceMaps = true,
skipFiles = { '<node_internals>/**' },
protocol = 'inspector',
console = 'integratedTerminal',
2024-03-03 12:42:45 -05:00
},
}
end
end,
}