dansomething / coc-java-debug

An extension for coc.nvim to enable Java debugging via jdt.ls
https://www.npmjs.com/package/coc-java-debug
Eclipse Public License 2.0
100 stars 8 forks source link

Could not get debugger to work #3

Closed richi1807 closed 4 years ago

richi1807 commented 4 years ago

Hi there, I've been trying to get the debugger to work. But I keep running into errors. To me it looks like debug adaptor is sending requests with a wrong protocol. Logs below :-

Steps

  1. Load the project.
  2. Activate coc-debug-java plugin.
  3. Run :CocCommand java.debug.vimspector.start
  4. The splash screen opens up and says "Initializing debug adaptor" but never moves beyond it. Vim status bar (which i think shows JDT ls logs ) says "Request for initialization aborted: closing down".
  5. In the logs I see the error "Unable to start debug server"
  6. My vimspector settings :-

    { "adapters": { "java-debug-server": { "name": "vscode-java", "port": "4456" } }, "configurations": { "Java Attach": { "adapter": "java-debug-server", "configuration": { "request": "attach", "host": "127.0.0.1", "port": "4455" }, "breakpoints": { "exception": { "caught": "N", "uncaught": "N" } } } } }

dansomething commented 4 years ago

In the steps you listed I don't see that you have started the JVM process with remote debugging enabled. Can you confirm that it is running on port 4455 as listed in your .vimspector.json?

TL;DR I'd expect your .vimspector.json to be:

{
  "adapters": {
    "java-debug-server": {
      "name": "vscode-java",
      "port": "${AdapterPort}"
    }
  },
  "configurations": {
    "Java Attach": {
      "adapter": "java-debug-server",
      "configuration": {
        "request": "attach",
        "host": "127.0.0.1",
        "port": "4455"
      },
      "breakpoints": {
        "exception": {
          "caught": "N",
          "uncaught": "N"
        }
      }
    }
  }
}

I notice you have the port under "adapters.java-debug-server.port" as 4456. That will need to be the port of the Java debug server that is started by jdt.ls. It starts on a random port which it sends back to the caller (this plugin). You can see by the value running :messages in Vim after the language server debug service has started. It will be something like [coc.nvim] Java debug server started on port: 59054.

By default the coc-java-debug plugin expects the "adapter" port value in your vimspector to be "${AdapterPort}". See here. This way the value can be replaced dynamically at runtime when Vimspector is launched from this plugin. This prevents you from having to set it each time.

Additionally, You may use a different template name in your vimspector config if you like by changing the coc-java-debug plugin setting.

richi1807 commented 4 years ago

Hello, the plugin works fine with the ${Adaptor} settings you mentioned. I did start the debugging server from gradle by running gradle test --tests <test name> --debug-jvm.

At first I had put the same value in ${Adaptor} port as the value where the debugging server started by gradle was listening and I was getting an error with JWDP handshake. This was expected because the ${Adaptor} port is the JDT.ls's debug server's port, which probably uses a different protocol.

I have one suggestion, if you could add a note on how debug-server works, then it would offer people more clarity into the vimspector settings, specifically around ${Adaptor} port.

Great work by the way. i don't see any reason to go back to IntelliJ again :)