svaante / dape

Debug Adapter Protocol for Emacs
GNU General Public License v3.0
448 stars 25 forks source link

Add "attach to already running Node process" js config #80

Closed sethidden closed 5 months ago

sethidden commented 5 months ago

Pre-defined configurations existing before this commit are meant to launch a program and simultaneously debug it.

When I debug Node, I prefer to debug a little differently. I launch Node somewhere else (e.g. in a terminal emulator), like node --inspect [program] or node --inspect-brk [program]. Or even simpler: node --inspect-brk -e "const x = 5; console.log(x);". I do it this way because the apps i launch are complex and running the start the project command launches multiple Node processes. So I just add --inspect to the ones I'd like to debug at the time, rather than trying to hack some crazy elaborate "run and inspect" setup.

Then I attach to the already running process using my preferred DAP client (dape, vscode, chrome devtools etc.)

In this case, you'd need to run M-x dape js-debug-node-attach

Because in Node --inspect by default starts debugging on port 9229, the default for the new debug configuration is also 9229.

However, if you prefer to use a different port, you can just do M-x dape and write js-debug-node-attach :port 9030 in the minibuffer.

svaante commented 5 months ago

Hey nice and clean.

How are your fsf status (see readme Contribute)?

Both of your PRs is less then 15 lines combined which makes your contributions not an legally significant contribution.

But if you want to continue with your contributions I suggest that you apply.

If not please https://github.com/svaante/dape/pull/5#issuecomment-1872517008 then I will merge this PR

svaante commented 5 months ago

@sethidden Would you mind fixing the merge conflicts, note that the mode has moved into the the let statment so it's need to be added as.

      (js-debug-node-attach
           modes (js-mode js-ts-mode typescript-mode typescript-ts-mode)
           ,@js-debug
           :type "pwa-node"
       :request "attach"
       :port 9229)
sethidden commented 5 months ago

Sure, I'll rebase in 4-5 days when I'm back

svaante commented 5 months ago

No problems enjoy your vacation :)

sethidden commented 5 months ago

Hey, I'm back a bit early so I pushed the changes that you mentioned. I added the modes as well but I'm not sure if it's applicable in this case.

The "attach" configuration relies on the fact that the Node process was started somewhere else - it's not started from the current file, which means it's not really related to the current major mode. Because of that, I was wondering if it'd make sense to not include modes.

Anyways, this is pretty philosophical, guess we'll live either way. If the modes are just used for narrowing down the debug configs that'll be recommended when typing into (dape) minibuffer prompt, it doesn't matter that much.