feat: get client side js debugging working

This commit is contained in:
Stevan Freeborn
2025-01-29 23:10:01 -06:00
parent d633f724ea
commit 9e6a671b98
+56 -12
View File
@@ -8,7 +8,7 @@ return {
local dap = require("dap") local dap = require("dap")
local dapui = require("dapui") local dapui = require("dapui")
dap.defaults.fallback.exception_breakpoints = { "raised", "uncaught" } dap.defaults.fallback.exception_breakpoints = { "uncaught" }
dapui.setup({ dapui.setup({
controls = { controls = {
@@ -92,44 +92,86 @@ return {
}, },
}) })
dap.adapters["pwa-node"] = { for _, adapterType in ipairs({ "node", "chrome", "msedge" }) do
local pwaType = "pwa-" .. adapterType
dap.adapters[pwaType] = {
type = "server", type = "server",
host = "localhost", host = "localhost",
port = "${port}", port = "${port}",
executable = { executable = {
command = "node", command = "node",
args = { "C:/Users/sfree/AppData/Local/nvim-data/vscode-js-debug/src/dapDebugServer.js", "${port}" }, args = {
vim.fn.stdpath("data") .. "/mason/packages/js-debug-adapter/js-debug/src/dapDebugServer.js",
"${port}",
},
}, },
} }
for _, language in ipairs({ "typescript", "javascript" }) do -- this allow us to handle launch.json configurations
-- which specify type as "node" or "chrome" or "msedge"
dap.adapters[adapterType] = function(cb, config)
local nativeAdapter = dap.adapters[pwaType]
config.type = pwaType
if type(nativeAdapter) == "function" then
nativeAdapter(cb, config)
else
cb(nativeAdapter)
end
end
end
local enter_launch_url = function()
local url = vim.fn.input("URL to launch: ", "http://localhost:")
vim.cmd('echo ""')
return url
end
for _, language in ipairs({ "typescript", "javascript", "typescriptreact", "javascriptreact", "vue" }) do
dap.configurations[language] = { dap.configurations[language] = {
{ {
type = "pwa-node", type = "pwa-node",
request = "launch", request = "launch",
name = "Launch file", name = "Launch file using Node.js (nvim-dap)",
program = "${file}", program = "${file}",
cwd = "${workspaceFolder}", cwd = "${workspaceFolder}",
}, },
{ {
type = "pwa-node", type = "pwa-node",
request = "attach", request = "attach",
name = "Attach", name = "Attach to process using Node.js (nvim-dap)",
processId = require("dap.utils").pick_process, processId = require("dap.utils").pick_process,
cwd = "${workspaceFolder}", cwd = "${workspaceFolder}",
}, },
} -- requires ts-node to be installed globally or locally
end
dap.configurations.javascript = {
{ {
type = "pwa-node", type = "pwa-node",
request = "launch", request = "launch",
name = "Launch file", name = "Launch file using Node.js with ts-node/register (nvim-dap)",
program = "${file}", program = "${file}",
cwd = "${workspaceFolder}", cwd = "${workspaceFolder}",
runtimeArgs = { "-r", "ts-node/register" },
},
{
type = "pwa-chrome",
request = "launch",
name = "Launch Chrome (nvim-dap)",
url = enter_launch_url,
webRoot = "${workspaceFolder}",
sourceMaps = true,
},
{
type = "pwa-msedge",
request = "launch",
name = "Launch Edge (nvim-dap)",
url = enter_launch_url,
webRoot = "${workspaceFolder}",
sourceMaps = true,
}, },
} }
end
dap.adapters.coreclr = { dap.adapters.coreclr = {
type = "executable", type = "executable",
@@ -183,7 +225,7 @@ return {
dap.configurations.cs = { dap.configurations.cs = {
{ {
type = "coreclr", type = "coreclr",
name = "launch - netcoredbg", name = "Launch - coreclr (nvim-dap)",
request = "launch", request = "launch",
program = function() program = function()
if vim.fn.confirm("Rebuild first?", "&yes\n&no", 2) == 1 then if vim.fn.confirm("Rebuild first?", "&yes\n&no", 2) == 1 then
@@ -213,6 +255,8 @@ return {
vim.keymap.set("n", "<Leader>dbl", dap.list_breakpoints, { desc = "Clear all breakpoints" }) vim.keymap.set("n", "<Leader>dbl", dap.list_breakpoints, { desc = "Clear all breakpoints" })
local continue = function() local continue = function()
-- support for vscode launch.json is partial.
-- not all configuration options and features supported
if vim.fn.filereadable(".vscode/launch.json") then if vim.fn.filereadable(".vscode/launch.json") then
require("dap.ext.vscode").load_launchjs() require("dap.ext.vscode").load_launchjs()
end end