Skip to content

Help needed: Can't find documentation to configure Java Attach to Process Debug #340

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

Closed
3 tasks done
me-heer opened this issue Jan 6, 2025 · 8 comments · Fixed by #342
Closed
3 tasks done

Help needed: Can't find documentation to configure Java Attach to Process Debug #340

me-heer opened this issue Jan 6, 2025 · 8 comments · Fixed by #342
Labels
bug Something isn't working

Comments

@me-heer
Copy link

me-heer commented Jan 6, 2025

Did you check docs and existing issues?

  • I have read all the plugin docs
  • I have searched the existing issues
  • I have searched the existing issues of plugins related to this issue

Neovim version (nvim -v)

NVIM v0.10.3

Operating system/version

MacOS 15.1.1

Describe the bug

I'm looking for an Attach to Process Configuration equivalent to the following VSCode Config:

"configurations": [
	{
		"type": "java",
		"name": "Debug Tomcat",
		"request": "attach",
		"hostName": "localhost",
		"port": "5005"
	},
]

But I can't find a way to configure it using nvim-java.

Here's my configuration (I have customized it starting from Kickstart): https://github.com/me-heer/nvim

Steps To Reproduce

  1. I have tried to add this: https://github.com/mfussenegger/nvim-dap/wiki/Java#configuration
  2. But executing :DapContinue does not show Attach to Process debug option

Expected Behavior

NA

@me-heer me-heer added the bug Something isn't working label Jan 6, 2025
@s1n7ax
Copy link
Member

s1n7ax commented Jan 7, 2025

This is automatically configured when you open a Java file. If you want custom configuration then you have to use dap APIs to do so. It's not in the scope of this project.

@s1n7ax
Copy link
Member

s1n7ax commented Jan 7, 2025

If what you are trying to say is that debug is not working out of the box, then i could look into it

@me-heer
Copy link
Author

me-heer commented Jan 7, 2025

If attach to process configuration is automatically configured, how do I invoke it?

:DapContinue only shows classes which have main method in them, and there's no debug configuration of attaching to a process

@TheLeoP
Copy link
Contributor

TheLeoP commented Jan 8, 2025

This is automatically configured when you open a Java file. If you want custom configuration then you have to use dap APIs to do so. It's not in the scope of this project.

The problem is that this plugin is overriding completely require'dap'.configurations.java on LspAttach, so it doens't matter if users are creating custom configurations, this plugin overrides them.

To fix this, instead of setting require'dap'.configurations.java directly

nvim_dap.configurations.java = dap_config

a better approach would be to

local dap = require'dap'
dap.configurations.java = dap.configurations.java or {} -- define the array of configurations only if not previously defined

-- do this in a for loop for each discovered configuration
table.insert(dap.configurations.java, {
-- some discovered configuration
})

@s1n7ax
Copy link
Member

s1n7ax commented Jan 8, 2025

I would happily accept this PR

@me-heer
Copy link
Author

me-heer commented Jan 10, 2025

Thanks for the help.

I have updated the plugin, and now my custom configuration (Attach to process) shows up in the :DapContinue options.

However, when I execute it, I get the following error:

Error executing vim.schedule lua callback: ...e/nvim/lazy/nvim-java-core/lua/java-core/utils/async.lua:41: unhandled error ...share/nvim/lazy
/nvim-java-dap/lua/java-dap/api/setup.lua:50: To enrich the config, mainClass should already be present
stack traceback:
        [C]: in function 'error'
        ...e/nvim/lazy/nvim-java-core/lua/java-core/utils/async.lua:41: in function 'callback'
        ...nvim-java-core/lua/java-core/ls/clients/jdtls-client.lua:72: in function 'handler'
        .../neovim/0.10.3/share/nvim/runtime/lua/vim/lsp/client.lua:687: in function ''
        vim/_editor.lua: in function <vim/_editor.lua:0>

I have gone through the Trobleshooting section and applied this: https://github.com/nvim-java/nvim-java/wiki/Troubleshooting#no_entry-to-enrich-the-config-xxx-should-already-be-present

My configuration for reference: https://github.com/me-heer/nvim/blob/master/init.lua#L1056-L1065

@TheLeoP
Copy link
Contributor

TheLeoP commented Jan 10, 2025

nvim-jdtls (the other java plugin for nvim from the same creator of nvim-dap) seems to discover the main clases during enrich_dap_config instead of before, like nvim-java (which is throwing an error because it expects those fields to be there). I don't know enough about how the java debug adapter works to help here, but nvim-jdtls has always worked for me, so I guess nvim-java-dap has to be modified to do the discovering of main classes later (?)

@me-heer
Copy link
Author

me-heer commented Jan 10, 2025

I don't know if this helps, but the directory I am opening has multiple Java projects in the subdirectories.

Also, I don't understand why there needs to be a main class (or class with a main method) altogether since I am going to use "Attach to Debug" in a Spring MVC project where there's no custom class with a main method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants