From 6754438801eea0cab07d4bc3a826e1747a3f9f88 Mon Sep 17 00:00:00 2001 From: Will Ruggiano Date: Wed, 28 Jun 2023 10:19:09 -0600 Subject: [PATCH] feat: vscode-js-debug --- nix/sources.json | 6 ++++ plugins/dap.lua | 91 ++++++++++++++++++++++++++++++------------------ plugins/spec.nix | 3 ++ 3 files changed, 66 insertions(+), 34 deletions(-) diff --git a/nix/sources.json b/nix/sources.json index 7cc1089..f49d92a 100644 --- a/nix/sources.json +++ b/nix/sources.json @@ -341,6 +341,12 @@ "rev": "9dc45a6eb33871f4c5cb2ba08fa307467657471e", "type": "git" }, + "nvim-dap-vscode-js": { + "branch": "main", + "repo": "git@github.com:mxsdev/nvim-dap-vscode-js", + "rev": "03bd29672d7fab5e515fc8469b7d07cc5994bbf6", + "type": "git" + }, "nvim-lspconfig": { "branch": "master", "repo": "git@github.com:neovim/nvim-lspconfig", diff --git a/plugins/dap.lua b/plugins/dap.lua index d143cf2..307d3f8 100644 --- a/plugins/dap.lua +++ b/plugins/dap.lua @@ -1,26 +1,14 @@ return function() local dap = require "dap" - local json = require "rapidjson" local utils = require "dap.utils" - dap.set_log_level "TRACE" - - dap.configurations.lua = { - { - type = "nlua", - request = "attach", - name = "Attach to running Neovim instance", - host = function() - return "127.0.0.1" - end, - port = function() - local val = tonumber(vim.fn.input "Port: ") - assert(val, "Please provide a port number") - return val - end, - }, + require("dap-vscode-js").setup { + adapters = { "pwa-node", "pwa-chrome", "pwa-msedge", "node-terminal", "pwa-extensionHost" }, + debugger_path = vim.fn.expand "~/dev/vscode-js-debug", } + dap.set_log_level "TRACE" + dap.configurations.cpp = { { name = "Attach", @@ -43,6 +31,55 @@ return function() }, } + dap.configurations.lua = { + { + type = "nlua", + request = "attach", + name = "Attach to running Neovim instance", + host = function() + return "127.0.0.1" + end, + port = function() + local val = tonumber(vim.fn.input "Port: ") + assert(val, "Please provide a port number") + return val + end, + }, + } + + for _, lang in ipairs { "javascript", "typescript" } do + dap.configurations[lang] = { + { + type = "pwa-node", + request = "launch", + name = "Launch file", + program = "${file}", + cwd = "${workspaceFolder}", + }, + { + type = "pwa-node", + request = "attach", + name = "Attach", + processId = utils.pick_process, + cwd = "${workspaceFolder}", + }, + { + type = "pwa-node", + request = "launch", + name = "Debug Jest Tests", + runtimeExecutable = "node", + runtimeArgs = { + "./node_modules/jest/bin/jest.js", + "--runInBand", + }, + rootPath = "${workspaceFolder}", + cwd = "${workspaceFolder}", + console = "integratedTerminal", + internalConsoleOptions = "neverOpen", + }, + } + end + dap.adapters.cppdbg = { type = "executable", command = "lldb-vscode", @@ -53,28 +90,14 @@ return function() callback { type = "server", host = config.host, port = config.port } end - local loaded_launch_json = {} - local launch_json = ".vscode/launch.json" + require("dap.ext.vscode").load_launchjs(nil, { + ["pwa-node"] = { "javascript", "typescript" }, + }) vim.api.nvim_create_user_command("Debug", function() - if vim.fn.filereadable(launch_json) == 1 and loaded_launch_json[launch_json] == nil then - local config = json.load(launch_json) - for _, c in ipairs(config.configurations) do - if c.type == "cppdbg" then - table.insert(dap.configurations.cpp, c) - end - end - loaded_launch_json[launch_json] = true - end dap.continue() end, { desc = "Start debugger" }) - vim.api.nvim_create_user_command("DebugConfig", function() - if vim.fn.exists(launch_json) then - vim.cmd(string.format("edit %s", launch_json)) - end - end, { desc = "Edit debuffer config" }) - vim.g.dap_virtual_text = true local dapui = require "dapui" diff --git a/plugins/spec.nix b/plugins/spec.nix index 5388a26..9f71675 100644 --- a/plugins/spec.nix +++ b/plugins/spec.nix @@ -139,6 +139,9 @@ in rec { src = sources.nvim-dap-virtual-text; config = true; }; + nvim-dap-vscode-js = { + src = sources.nvim-dap-vscode-js; + }; inherit rapidjson; }; };