Skip to content

Commit

Permalink
feat(typescript): add debugger adapters to vsscode launch.json dete…
Browse files Browse the repository at this point in the history
…ction in `nvim-dap`
  • Loading branch information
mehalter committed Jun 9, 2024
1 parent 51eb1c1 commit 8832006
Showing 1 changed file with 33 additions and 16 deletions.
49 changes: 33 additions & 16 deletions lua/astrocommunity/pack/typescript/dap.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,34 @@ return {
optional = true,
config = function()
local dap = require "dap"
dap.adapters["pwa-node"] = {
type = "server",
host = "localhost",
port = "${port}",
executable = {
command = "node",
args = {
require("mason-registry").get_package("js-debug-adapter"):get_install_path()
.. "/js-debug/src/dapDebugServer.js",
"${port}",
if not dap.adapters["pwa-node"] then
dap.adapters["pwa-node"] = {
type = "server",
host = "localhost",
port = "${port}",
executable = {
command = "node",
args = {
require("mason-registry").get_package("js-debug-adapter"):get_install_path()
.. "/js-debug/src/dapDebugServer.js",
"${port}",
},
},
},
}
}
end
if not dap.adapters.node then
dap.adapters.node = function(cb, config)
if config.type == "node" then config.type = "pwa-node" end
local pwa_adapter = dap.adapters["pwa-node"]
if type(pwa_adapter) == "function" then
pwa_adapter(cb, config)
else
cb(pwa_adapter)
end
end
end

local js_filetypes = { "typescript", "javascript", "typescriptreact", "javascriptreact" }
local js_config = {
{
type = "pwa-node",
Expand All @@ -33,10 +48,12 @@ return {
},
}

if not dap.configurations.javascript then
dap.configurations.javascript = js_config
else
require("astrocore").extend_tbl(dap.configurations.javascript, js_config)
for _, language in ipairs(js_filetypes) do
if not dap.configurations[language] then dap.configurations[language] = js_config end
end

local vscode_filetypes = require("dap.ext.vscode").type_to_filetypes
vscode_filetypes["node"] = js_filetypes
vscode_filetypes["pwa-node"] = js_filetypes
end,
}

0 comments on commit 8832006

Please sign in to comment.