|
| 1 | +if vim.g.vscode then |
| 2 | + return |
| 3 | +end |
| 4 | + |
| 5 | +local ok_dap, dap = pcall(require, 'dap') |
| 6 | +if not ok_dap then |
| 7 | + return |
| 8 | +end |
| 9 | + |
| 10 | +local ok_ui, dapui = pcall(require, 'dapui') |
| 11 | +if ok_ui then |
| 12 | + dapui.setup() |
| 13 | + |
| 14 | + dap.listeners.after.event_initialized['dapui_config'] = function() |
| 15 | + dapui.open() |
| 16 | + end |
| 17 | + dap.listeners.before.event_terminated['dapui_config'] = function() |
| 18 | + dapui.close() |
| 19 | + end |
| 20 | + dap.listeners.before.event_exited['dapui_config'] = function() |
| 21 | + dapui.close() |
| 22 | + end |
| 23 | +end |
| 24 | + |
| 25 | +pcall(function() |
| 26 | + require('nvim-dap-virtual-text').setup() |
| 27 | +end) |
| 28 | + |
| 29 | +pcall(function() |
| 30 | + require('dap-go').setup() |
| 31 | +end) |
| 32 | + |
| 33 | +pcall(function() |
| 34 | + local js_debug_path = vim.fn.stdpath 'data' .. '/mason/packages/js-debug-adapter/js-debug/src/dapDebugServer.js' |
| 35 | + |
| 36 | + dap.adapters['pwa-node'] = { |
| 37 | + type = 'server', |
| 38 | + host = '127.0.0.1', |
| 39 | + port = '${port}', |
| 40 | + executable = { |
| 41 | + command = 'node', |
| 42 | + args = { js_debug_path, '${port}' }, |
| 43 | + }, |
| 44 | + } |
| 45 | + |
| 46 | + dap.configurations.javascript = { |
| 47 | + { |
| 48 | + type = 'pwa-node', |
| 49 | + request = 'launch', |
| 50 | + name = 'Launch file', |
| 51 | + program = '${file}', |
| 52 | + cwd = '${workspaceFolder}', |
| 53 | + }, |
| 54 | + { |
| 55 | + type = 'pwa-node', |
| 56 | + request = 'attach', |
| 57 | + name = 'Attach', |
| 58 | + processId = require('dap.utils').pick_process, |
| 59 | + cwd = '${workspaceFolder}', |
| 60 | + }, |
| 61 | + } |
| 62 | + |
| 63 | + dap.configurations.typescript = dap.configurations.javascript |
| 64 | + dap.configurations.javascriptreact = dap.configurations.javascript |
| 65 | + dap.configurations.typescriptreact = dap.configurations.javascript |
| 66 | +end) |
| 67 | + |
| 68 | +local map = function(lhs, rhs, desc) |
| 69 | + vim.keymap.set('n', lhs, rhs, { desc = desc }) |
| 70 | +end |
| 71 | + |
| 72 | +map('<F5>', dap.continue, 'DAP continue') |
| 73 | +map('<F10>', dap.step_over, 'DAP step over') |
| 74 | +map('<F11>', dap.step_into, 'DAP step into') |
| 75 | +map('<F12>', dap.step_out, 'DAP step out') |
| 76 | +map('<leader>db', dap.toggle_breakpoint, 'DAP toggle breakpoint') |
| 77 | +map('<leader>dB', function() |
| 78 | + dap.set_breakpoint(vim.fn.input 'Breakpoint condition: ') |
| 79 | +end, 'DAP conditional breakpoint') |
| 80 | +map('<leader>dr', dap.repl.open, 'DAP open REPL') |
| 81 | +map('<leader>dl', dap.run_last, 'DAP run last') |
| 82 | + |
| 83 | +if ok_ui then |
| 84 | + map('<leader>du', dapui.toggle, 'DAP UI toggle') |
| 85 | +end |
| 86 | + |
| 87 | +map('<leader>dt', dap.terminate, 'DAP terminate') |
0 commit comments