From 5dc5b06933b10a4db7d2eb1d0bed9bf3746ca83b Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 12 Jul 2026 14:44:58 +0800 Subject: [PATCH] debug typescript working --- lua/kickstart/plugins/debug.lua | 80 +++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/lua/kickstart/plugins/debug.lua b/lua/kickstart/plugins/debug.lua index fe588d8a..5c77216f 100644 --- a/lua/kickstart/plugins/debug.lua +++ b/lua/kickstart/plugins/debug.lua @@ -93,3 +93,83 @@ require('dap-go').setup { detached = vim.fn.has 'win32' == 0, }, } + +-- ========================================== +-- JavaScript / TypeScript / Next.js Setup +-- ========================================== + +-- 1. Define the adapters using the js-debug-adapter installed by Mason +-- We use the direct path to dapDebugServer.js to avoid PATH/binary linking issues. +local js_debug_adapter_path = vim.fs.joinpath( + vim.fn.stdpath('data'), + 'mason', + 'packages', + 'js-debug-adapter', + 'js-debug', + 'src', + 'dapDebugServer.js' +) + +local node_terminal = { + type = 'server', + host = 'localhost', + port = '${port}', + executable = { + command = 'node', + args = { + js_debug_adapter_path, + '${port}', + }, + }, +} + +local chrome = { + type = 'server', + host = 'localhost', + port = '${port}', + executable = { + command = 'node', + args = { + js_debug_adapter_path, + '${port}', + }, + }, +} + +require('dap').adapters['pwa-node'] = node_terminal +require('dap').adapters['node_terminal'] = node_terminal + +require('dap').adapters['pwa-chrome'] = chrome +require('dap').adapters['chrome'] = chrome + +-- 2. Define configurations for TS/JS +local js_based_languages = { 'typescript', 'javascript', 'typescriptreact' } + +for _, language in ipairs(js_based_languages) do + require('dap').configurations[language] = { + -- Server-side Next.js debugging + { + type = 'pwa-node', + request = 'launch', + name = 'Nvim: Debug JS Server', + runtimeExecutable = 'npm', + runtimeArgs = { 'run', 'dev' }, + cwd = '${workspaceFolder}', + -- 'integratedTerminal' launches a Neovim terminal split and runs the command there + console = 'integratedTerminal', + -- sourceMaps = true, -- Uncomment if breakpoints in `.next` aren't mapping correctly + }, + -- Client-side Next.js debugging + { + type = 'pwa-chrome', + request = 'launch', + name = 'Nvim: Debug JS Client', + url = 'http://localhost:3000', + webRoot = '${workspaceFolder}', + -- By default, pwa-chrome uses a clean, isolated Chrome profile. + -- Uncomment the line below if you want it to use your default Chrome profile (so you can use your extensions). + -- userDataDir = false, + -- sourceMaps = true, + }, + } +end