nvim: auto attach node debugger

This commit is contained in:
Maciej Jur 2024-01-28 13:15:04 +01:00
parent 4b8a51b854
commit 0e48142074
Signed by: kamov
GPG key ID: 191CBFF5F72ECAFD

View file

@ -288,6 +288,16 @@ return {
n '<leader>du' (ui.toggle) 'Debugger: toggle UI'
nv '<leader>de' (ui.eval) 'Debugger: eval'
-- vim.api.nvim_set_hl(0, 'DapBreakpoint', { ctermbg = 0, fg = '#993939', bg = '#31353f' })
-- vim.api.nvim_set_hl(0, 'DapLogPoint', { ctermbg = 0, fg = '#61afef', bg = '#31353f' })
-- vim.api.nvim_set_hl(0, 'DapStopped', { ctermbg = 0, fg = '#98c379', bg = '#31353f' })
--
-- vim.fn.sign_define('DapBreakpoint', { text='', texthl='DapBreakpoint', linehl='DapBreakpoint', numhl='DapBreakpoint' })
-- vim.fn.sign_define('DapBreakpointCondition', { text='ﳁ', texthl='DapBreakpoint', linehl='DapBreakpoint', numhl='DapBreakpoint' })
-- vim.fn.sign_define('DapBreakpointRejected', { text='', texthl='DapBreakpoint', linehl='DapBreakpoint', numhl= 'DapBreakpoint' })
-- vim.fn.sign_define('DapLogPoint', { text='', texthl='DapLogPoint', linehl='DapLogPoint', numhl= 'DapLogPoint' })
-- vim.fn.sign_define('DapStopped', { text='', texthl='DapStopped', linehl='DapStopped', numhl= 'DapStopped' })
ui.setup()
dap.listeners.after.event_initialized["dapui_config"] = ui.open
dap.listeners.after.event_terminated["dapui_config"] = ui.close
@ -440,29 +450,11 @@ return {
local langs = { 'javascript', 'typescript', 'svelte', 'astro' }
for _, lang in ipairs(langs) do
dap.configurations[lang] = {
-- attach to a node process that has been started with
-- `--inspect` for longrunning tasks or `--inspect-brk` for short tasks
-- npm script -> `node --inspect-brk ./node_modules/.bin/vite dev`
{
-- use nvim-dap-vscode-js's pwa-node debug adapter
type = 'pwa-node',
-- attach to an already running node process with --inspect flag
-- default port: 9222
type = 'pwa-node',
request = 'attach',
-- allows us to pick the process using a picker
processId = require('dap.utils').pick_process,
-- name of the debug action you have to select for this config
name = 'Attach debugger to existing `node --inspect` process',
-- for compiled languages like TypeScript or Svelte.js
sourceMaps = true,
-- resolve source maps in nested locations while ignoring node_modules
resolveSourceMapLocations = {
'${workspaceFolder}/**',
'!**/node_modules/**',
},
-- path to src in vite based projects (and most other projects as well)
cwd = '${workspaceFolder}',
-- we don't want to debug code inside node_modules, so skip it!
name = 'Attach debugger to existing `node --inspect` process',
cwd = '${workspaceFolder}',
skipFiles = {
'${workspaceFolder}/node_modules/**/*.js',
'${workspaceFolder}/packages/**/node_modules/**/*.js',
@ -470,6 +462,11 @@ return {
'<node_internals>/**',
'node_modules/**',
},
sourceMaps = true,
resolveSourceMapLocations = {
'${workspaceFolder}/**',
'!**/node_modules/**',
},
},
}
end