Skip to content

Commit

Permalink
feat: vscode-js-debug
Browse files Browse the repository at this point in the history
  • Loading branch information
willruggiano committed Jun 28, 2023
1 parent 6baf039 commit 6754438
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 34 deletions.
6 changes: 6 additions & 0 deletions nix/sources.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
91 changes: 57 additions & 34 deletions plugins/dap.lua
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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",
Expand All @@ -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"
Expand Down
3 changes: 3 additions & 0 deletions plugins/spec.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
};
Expand Down

0 comments on commit 6754438

Please sign in to comment.