Debugging java/typescript in nodejs with dap #1103
Replies: 3 comments 4 replies
-
Here are some general nixvim tips, but I don't know about the question exactly though :/ I'd suggest looking around the nvim-dap-vscode-js repo for more information on that :/ I'd suggest avoiding If using flakes you can also add plugins to your nix flake inputs. You can do: extraConfigLua = ''
require("dap-vscode-js") ...
''; (Notice that with |
Beta Was this translation helpful? Give feedback.
-
So the extraConfigLua helped me out. That did get me 90% of the way. this is what my config looks like now extraPlugins = [(
pkgs.fetchFromGitHub {
owner = "mxsdev";
repo = "nvim-dap-vscode-js";
rev = "e7c05495934a658c8aa10afd995dacd796f76091";
sha256 = "sha256-lZABpKpztX3NpuN4Y4+E8bvJZVV5ka7h8x9vL4r9Pjk=";
}
)];
extraConfigLua = ''
require("dap-vscode-js").setup({
adapters = { 'pwa-node', 'pwa-chrome', 'pwa-msedge', 'node-terminal', 'pwa-extensionHost' },
})
for _, language in ipairs({ "typescript", "javascript" }) do
require("dap").configurations[language] = {
{
type = "pwa-node",
request = "launch",
name = "Launch file",
program = "''${file}",
cwd = "''${workspaceFolder}",
},
{
type = "pwa-node",
request = "attach",
name = "Attach",
processId = require'dap.utils'.pick_process,
cwd = "''${workspaceFolder}",
}
}
end
'';
plugins = {
packer = {
enable = true;
plugins = [
{
name = "microsoft/vscode-js-debug";
opt = true;
run = "npm install --legacy-peer-deps && npx gulp vsDebugServerBundle && mv dist out";
}];
};
#... Now I guess the reason for avoiding packer is that it is not really deterministic and I need to run :PackerSync right? Would also like to get rid of this then. However there is a section in the documentation of nvim-dap-vscode-js that I also need to fetch and build microsoft/vscode-js-debug. Fetching it can be easily done with pkgs.fetchFromGitHub as well I guess. But do you also know how I could substitute the opt and run portions of the plugin configuration? |
Beta Was this translation helpful? Give feedback.
-
alright. Thanks again for the help. I have been able to set up the configuration in the meantime with your help. If someone has the same challenges as I had. Here is my current config for typescript { pkgs, ... }:
let
nvim-dap-vscode-js = pkgs.vimUtils.buildVimPlugin {
name = "vim-dap-vscode-js";
src = pkgs.fetchFromGitHub {
owner = "mxsdev";
repo = "nvim-dap-vscode-js";
rev = "e7c05495934a658c8aa10afd995dacd796f76091";
sha256 = "sha256-lZABpKpztX3NpuN4Y4+E8bvJZVV5ka7h8x9vL4r9Pjk=";
};
};
in
{
programs.nixvim = {
plugins.dap = {
enable = true;
extensions = {
dap-ui.enable = true;
dap-virtual-text.enable = true;
};
};
plugins.lsp = {
enable = true;
tsserver.enable = true;
eslint.enable = true;
};
plugins.nvim-cmp = {
enable = true;
autoEnableSources = true;
sources = [
{ name = "nvim_lsp"; }
{ name = "path"; }
{ name = "buffer"; }
];
};
extraPlugins = [
nvim-dap-vscode-js
];
keymaps = [
# Dap
{ mode = "n"; action = "<cmd>DapToggleBreakpoint<cr>"; key = "<leader>b"; }
{ mode = "n"; action = "<cmd>DapContinue<cr>"; key = "<F5>"; }
{ mode = "n"; action = "<cmd>DapStepOver<cr>"; key = "<F10>"; }
{ mode = "n"; action = "<cmd>DapStepInto<cr>"; key = "<F11>"; }
{ mode = "n"; action = "<cmd>DapStepOut<cr>"; key = "<F12>"; }
{ mode = "n"; action = "<cmd>lua function() require 'dap'.set_breakpooint(vim.fn.input('Breakpoint condition: '))<cr>"; key = "<leader>B"; }
# Dap-ui
{ mode = "n"; action = "<cmd>lua require(\"dapui\").toggle()<cr>"; key = "<leader>d"; }
# LSP
{ mode = "n"; action = "<cmd>lua vim.lsp.buf.rename()<cr>"; key="<F2>"; }
{ mode = "n"; action = "<cmd>lua vim.lsp.buf.hover()<cr>"; key="<leader>h"; }
];
extraConfigLua = ''
local dap, dapui = require("dap"), require("dapui")
local dap_vscode_js = require("dap-vscode-js")
-- DEBUG LISTENERS
dap.listeners.before.attach.dapui_config = function()
dapui.open()
end
dap.listeners.before.launch.dapui_config = function()
dapui.open()
end
dap.listeners.before.event_terminated.dapui_config = function()
dapui.close()
end
dap.listeners.before.event_exited.dapui_config = function()
dapui.close()
end
dap.set_log_level('DEBUG')
-- DEBUG VS CODE
dap_vscode_js.setup({
adapters = { 'pwa-node', 'pwa-chrome', 'pwa-msedge', 'node-terminal', 'pwa-extensionHost' }
})
-- DEBUG CONFIG TYPESCRIPT
dap.configurations.typescript = {
{
type = "pwa-node",
request = "launch",
name = "Launch file",
program = "''${file}",
cwd = "''${workspaceFolder}",
},
{
type = "pwa-node",
request = "attach",
name = "Attach",
processId = require'dap.utils'.pick_process,
cwd = "''${workspaceFolder}",
},
{
type = "pwa-node",
request = "launch",
name = "Run Application",
program = "dist/index.js",
cwd = "''${workspaceFolder}",
},
{
type = "pwa-node",
request = "launch",
name = "Run npm test",
program = "node_modules/mocha/bin/_mocha",
cwd = "''${workspaceFolder}",
}
}
'';
};
} |
Beta Was this translation helpful? Give feedback.
-
I am currently trying to switch to vim using nixvim which was a breeze so far even tough i am not only new to nixvim but vim in general. However at the moment I am stuck trying to get debugging up and running. I tried multiple approaches with packer that are close to what I found online for regular nvim setups but failed. Now I tried to move forward from error message to error message. However at the moment I am stuck without being able to move forward. This is what I have set up so far
I can set breakpoints and dap in general seems to work. However when I try to start a debug session I receive this error
Now I know that especially the part around dap.adapters is pretty much nonsense in my config. However I was not able to find any helpful info (at least that I could understand) online nor could I make something of the source code that would help me further. I'd be very happy if someone could help me out and point me into the right direction. In any case nixvim is great work and I've been enjoying it very much being able to configure everything in the "nix way"
Beta Was this translation helpful? Give feedback.
All reactions