Open boris-beginin-lmnd opened 2 years ago
Okay thats strange, i am able to debug an entrypoint to app, but i cant debug api controllers 🤔
Hi! Thanks for the nice words :)
Unfortunately I can't help much with the provided info. If you could provide code which creates the problem, ideally a minimum example, that would help me (as well as anyone else who has the bug or wants to contribute) approach the problem.
If you could also set your dap log level to TRACE
that would be great, since then I can read through all the requests. There's also logging for this plugin - see the docs for info - which might be helpful (again, log level set to TRACE
)
able to debug an entrypoint to app, i cant debug api controllers
Are these both done with attach
?
There's a chance that the api backend might run the endpoints in separate threads, or run them in a separate process, which I know that this plugin sometimes has problems with.
@mxsdev I have the same error. Here is a screenshot of my configuration and how it behaves:
As you can see, the debugger gets attached but it ignores the breakpoint.
I'm using a very basic configuration of AstroVim, here are the steps to replicate it:
git clone git@github.com:/AstroNvim/AstroNvim ~/.config/Test
git clone https://github.com/AstroNvim/user_example ~/.config/Test/lua/user
NVIM_APPNAME=Test nvim
And then modify the file ~/.config/Test/lua/user/plugins/dap.lua
with this:
local lazy_dir = vim.fn.stdpath("data") .. "/lazy"
return {
"mfussenegger/nvim-dap",
enabled = vim.fn.has "win32" == 0,
dependencies = {
{
"mxsdev/nvim-dap-vscode-js",
opts = {
debugger_path = string.format("%s/vscode-js-debug/", lazy_dir),
adapters = { "pwa-node" }
},
},
{ "theHamsta/nvim-dap-virtual-text", config = true },
{ "rcarriga/nvim-dap-ui", config = true },
{
"microsoft/vscode-js-debug",
build = "npm install --legacy-peer-deps && npx gulp vsDebugServerBundle && mv dist out"
}
},
config = function()
local dap = require "dap"
dap.configurations.typescript = {
{
type = "pwa-node",
request = "attach",
name = "Attach",
processId = require 'dap.utils'.pick_process,
cwd = "${workspaceFolder}",
}
}
end,
}
One thing that I do different is the code is running in kubernetes, so I need to open a tunnel. However, with VSCode it works fine.
Found the problem. Will post later today the error and will add a PR to add documentation on it
Thanks for your awesome work with this tool!
For all those interested, basically the issues I had were two:
debugger_path
to the one installed with this pluginlocalRoot
and remoteRoot
are needed. Otherwise, the debugger does not know the request is going through that breakpoint. I use AstroNvim, with Lazy.nvim so my configuration in the end is like this:
-- file ~/.config/nvim/lua/user/plugins/dap.lua
local lazy_dir = vim.fn.stdpath("data") .. "/lazy"
return {
"mfussenegger/nvim-dap",
dependencies = {
{
"mxsdev/nvim-dap-vscode-js",
opts = {
debugger_path = string.format("%s/vscode-js-debug/", lazy_dir),
adapters = { "pwa-node" }
},
},
{ "theHamsta/nvim-dap-virtual-text", config = true },
{ "rcarriga/nvim-dap-ui", config = true },
{
"microsoft/vscode-js-debug",
build = "npm install --legacy-peer-deps && npx gulp vsDebugServerBundle && mv dist out"
}
},
config = function()
local dap = require "dap"
dap.configurations.typescript = {
{
type = "pwa-node",
request = "attach",
name = "Attach",
processId = require 'dap.utils'.pick_process,
skipFiles = { "<node_internals>/**", "node_modules/**" },
localRoot = vim.fn.getcwd(),
remoteRoot = "/usr/src/app"
}
}
end,
}
This has the caveat that it hard-codes the remoteRoot
to /usr/src/app
, but I'll try and figure out how to improve that later. Right now it works as expected so I'm happy
@citosid, did you really get it working ? Because I seem to get similar results as MijikHna mentioned in https://github.com/mxsdev/nvim-dap-vscode-js/issues/15#issuecomment-1484969854 🤔 (that is, typescript breakpoint is ignored, while the one in compiled js can be hit)
Maybe the difference lies in that you run it in kubernetes and through a tunnel. (I run app using docker compose with ports mapping, which could have a different behavior 🤔)
@skivol, I did. But I haven't used typescript in a few months. I'll try and set it up again and report back. Sorry I can't be more helpful
No problems :) Would be really grateful if you could check on it, but cannot ask you to do it, because playing with it takes quiet some time 😅
Maybe stopOnEntry
can help?
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch node cli app",
"type": "pwa-node",
"request": "launch",
"preLaunchTask": "tsc: build - tsconfig.json",
"cwd": "${workspaceFolder}",
"args": ["${workspaceFolder}/dist/index.js"],
"stopOnEntry": true
}
]
}
Thank you for the suggestion and your notes on the topic of configuring dap for usage in neovim 👍
Will need to take a closer look on it (completely forgot that one could check logs as well :) ).
At the moment reshuffled things a bit though to check if it (using "attach" variant atm) would work for debugging an app running on the host machine (instead of container) and it seems to play well for such setup.
vscode
can manage to debug containerized typescript app on the other hand... so technically it should be possible.
So once again thank you for the notes, went back to the usage of dapDebugServer
as you mentioned (and as also shown in https://github.com/mfussenegger/nvim-dap/wiki/Debug-Adapter-installation#javascript) and with the following configuration it works for the debugging of node typescript application running in docker container (that is, breakpoints are hit):
dap.configurations.typescript = {
{
type = 'pwa-node',
request = 'attach',
name = 'Docker: Attach',
localRoot = '${workspaceFolder}',
remoteRoot = '/usr/src/app',
cwd = '${workspaceFolder}',
},
}
provided that debug ports (9229) are mapped to the host machine and the app is launched with debug "on". Note though, that in my experience all localRoot
, remoteRoot
and cwd
properties are required.
I have currently the same problem but in my case i run a Nextjs application directly on my host machine.
I tried the lazyvim extra settings for nvim-dap.
{
"mfussenegger/nvim-dap",
optional = true,
dependencies = {
{
"williamboman/mason.nvim",
opts = function(_, opts)
opts.ensure_installed = opts.ensure_installed or {}
table.insert(opts.ensure_installed, "js-debug-adapter")
end,
},
},
opts = function()
local dap = require("dap")
if not dap.adapters["pwa-node"] then
require("dap").adapters["pwa-node"] = {
type = "server",
host = "localhost",
port = "${port}",
executable = {
command = "node",
-- 💀 Make sure to update this path to point to your installation
args = {
require("mason-registry").get_package("js-debug-adapter"):get_install_path()
.. "/js-debug/src/dapDebugServer.js",
"${port}",
},
},
}
end
for _, language in ipairs({ "typescript", "javascript", "typescriptreact", "javascriptreact" }) do
if not dap.configurations[language] then
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
end
end,
}
So once i start the app with NODE_OPTIONS='--inspect' next dev
and start dap inside of nvim, i can see that the debugger gets attached. But it wont hit any server side breakpoint. In VScode it works fine with this launch.json code:
{
"name": "Next.js: debug server-side",
"type": "node-terminal",
"request": "launch",
"command": "npm run dev"
},
I even tried to start the server with vscode and connect my dap debugger in nvim to it. "Debugger attached" but it still won't hit any breakpoint.
Maybe somebody have some clue whats going on here?...
Hey! First of all thx for your work.
For me for some reasons breakpoints do not work when i use this adapter(they work with node2 adapter but some other stuff do not)
I am able to connect to debugger and see remote process in DAP, but for some reason breakpoints are ignored.
Logs
Config
JFYI works with the same config in vscode