Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there any way that I can debug javascript through the LSP4 IJ plug-in #684

Open
PassingByThs opened this issue Dec 11, 2024 · 13 comments
Assignees
Labels
dap Debugging Adapter Protocol
Milestone

Comments

@PassingByThs
Copy link

I am using the IntelliJ Idea Community version, which does not support debugging javascript. Is there any way that I can debug javascript through the LSP4 IJ plug-in? Will the LSP4 IJ plug-in have the ability to support debug javascript or other files in the future? Thanks

@angelozerr
Copy link
Contributor

angelozerr commented Dec 11, 2024

To debug JavaScript, it requires that LSP4IJ must implement and support DAP https://microsoft.github.io/debug-adapter-protocol/

Once this support will be implemented, we could use https://github.com/microsoft/vscode-js-debug

A nice article explains that with neovim which supports DAP https://www.darricheng.com/posts/setting-up-nodejs-debugging-in-neovim/

To implement DAP for IJ we could port DAP support from LSP4E https://github.com/eclipse-lsp4e/lsp4e/tree/main/org.eclipse.lsp4e.debug in IJ

@SCWells72 do you think you could be interested to implement DAP? I have implemented a DAP debugger for a language server (LSP server side), but never implement it for LSP client side.

@angelozerr angelozerr added the dap Debugging Adapter Protocol label Dec 11, 2024
@SCWells72
Copy link
Contributor

SCWells72 commented Dec 11, 2024

@angelozerr, I'll be happy to take a look and see what might be involved. I've implemented a custom debugger using the JB plugin SDK, and it's no small amount of work. I'll need to understand DAP and then try to map its concepts to the IDE's custom debugger SDK to understand just how much work this actually is...

@angelozerr
Copy link
Contributor

That's a fantastic news! I suggest really that you use https://github.com/eclipse-lsp4e/lsp4e/tree/main/org.eclipse.lsp4e.debug and translate code from Eclipse API to IJ API. We did that for LSP support when we start (quickly) the project and to benefit from fixed issues from LSP4E.

@angelozerr
Copy link
Contributor

And if you have any questions, I could perhaps help you since I have implemented a DAP debugger on language server side.

@SCWells72
Copy link
Contributor

@angelozerr, I perused the DAP specification today and it's pretty much what I expected based on our discussion the other day. However, also as discussed, it looks...BIG! I'm not sure it's something I'd be able to take on anytime soon. I certainly think I could split duties with someone else where, for example, I implemented the IDE extension points for a custom debugger against an existing DAP client that someone else has provided. I think it will also be critical to prioritize the various features and determine what constitutes a minimally viable product for a DAP integration and what can/should be added in subsequent iterations (which seems to follow the LSP4IJ model anyway).

I'm happy to spend some time chatting through how that might work and what division of responsibilities would make sense, but I definitely can't commit to taking something this large on myself with all of my other obligations right now.

@angelozerr
Copy link
Contributor

angelozerr commented Jan 3, 2025

@PassingByThs @SCWells72 after spending a lot of time to translate DAP support from LSP4E (DAP support for Eclipse) in IntelliJ I have an uggly POC and debugging (JavaScript only , not TypeScript) starts working:

Image

My goal now is to create a PR with a clean and generic code. Debugging TypeScript, manage evaludation,etc will be done in the future. My goal is to provide a basic DAP support that we will improve step by step.

@angelozerr
Copy link
Contributor

@PassingByThs if you want to test the dap support please install nightly-builds.

and read https://github.com/redhat-developer/lsp4ij/blob/main/docs/dap/user-defined-dap/vscode-js-debug.md

It is a basic dap support which is not perfect, please report issues and give us feedback.

@PassingByThs
Copy link
Author

Excellent work!🎉🎉🎉 It worked well with javascript. There is no errors I have found.

But it can not debug typescript directly unless compiled to javascript, which seems conflict as mentiond below.
Image

@angelozerr
Copy link
Contributor

Excellent work!🎉🎉🎉 It worked well with javascript. There is no errors I have found.

That's excellent! Thanks for your feedback!

But it can not debug typescript directly unless compiled to javascript, which seems conflict as mentiond below.

It is possible since this debugger is used inside vscode and LSP4E uses it https://github.com/eclipse-wildwebdeveloper/wildwebdeveloper/blob/master/org.eclipse.wildwebdeveloper/src/org/eclipse/wildwebdeveloper/debug/node/VSCodeJSDebugDelegate.java.

I added a TODO at https://github.com/redhat-developer/lsp4ij/blob/main/docs/dap/user-defined-dap/vscode-js-debug.md#configure-the-typescript-file-to-rundebug

It is just a matter with Launch DAP parameters I think. I need to investigate more how to configure that.

To understand how to do that we need:

The first thing I will try it is to use this following config:

{
  "type": "pwa-node",
  "request": "launch",
  "program": "${file}",
  "cwd": "${workspaceFolder}",
  "sourceMap": true,
  "outFiles": ["${workspaceFolder}/out/**/*.js"]
}

Image

When you read doc at https://code.visualstudio.com/docs/typescript/typescript-debugging

It uses

preLaunchTask": "tsc: build - tsconfig.json",

but it is specific to vscode, perhaps we could do the same thing with the before task (I don't know if it is working).

Please try it and give me feedback.

@PassingByThs
Copy link
Author

PassingByThs commented Jan 24, 2025

DAP parameters content disappeared when opened again.

Image

Image

@angelozerr
Copy link
Contributor

angelozerr commented Jan 24, 2025

DAP parameters content disappeared when opened again.

Image

Image

Indeed I have noticed this problem. I am fixing and providing run / debug with contextual menu

@angelozerr
Copy link
Contributor

@PassingByThs after spending a lot of times to debug vscode to understand how it configure VSCode Debug JS, I can debug TypeScript!

Image

There are some bugs that I need to fix it, I will ping you when I will push my work.

@angelozerr angelozerr added this to the 0.10.0 milestone Jan 25, 2025
@angelozerr angelozerr self-assigned this Jan 25, 2025
@angelozerr angelozerr moved this to In Progress in Java Tooling Jan 25, 2025
@angelozerr
Copy link
Contributor

@PassingByThs please install again nightly-builds and read https://github.com/redhat-developer/lsp4ij/blob/main/docs/dap/user-defined-dap/vscode-js-debug.md#configure-the-typescript-file-to-rundebug

I have fixed your below issues.

You should (I hope) have the capability to debug TypeScript files, please report issues and give us feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dap Debugging Adapter Protocol
Projects
Status: In Progress
Development

No branches or pull requests

3 participants