From 8832006efb65219fe3898d8aad398c2264bff34c Mon Sep 17 00:00:00 2001 From: Micah Halter Date: Sun, 9 Jun 2024 12:50:33 -0400 Subject: [PATCH] feat(typescript): add debugger adapters to vsscode `launch.json` detection in `nvim-dap` --- lua/astrocommunity/pack/typescript/dap.lua | 49 +++++++++++++++------- 1 file changed, 33 insertions(+), 16 deletions(-) diff --git a/lua/astrocommunity/pack/typescript/dap.lua b/lua/astrocommunity/pack/typescript/dap.lua index 1042f712d..fab8261ad 100644 --- a/lua/astrocommunity/pack/typescript/dap.lua +++ b/lua/astrocommunity/pack/typescript/dap.lua @@ -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", @@ -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, }