vim-test icon indicating copy to clipboard operation
vim-test copied to clipboard

Question: How to configure so nvim-dap is used ?

Open DanielCardonaRojas opened this issue 2 years ago • 4 comments

I would like to debug when I write unit tests. Is there some documentation on this ?

DanielCardonaRojas avatar Sep 13 '21 21:09 DanielCardonaRojas

@DanielCardonaRojas In which language? Java?

GiuseppeMP avatar Oct 09 '22 15:10 GiuseppeMP

@codeinabox Hello, I need some help/thoughts about how to make this in (Java/Maven), I have requirements in mind:

  1. The test command needs to start a remote debug server, to wait connection in java, must use suspend=y for ex: mvn test -Dmaven.surefire.debug=true will stop waiting the attach using default port 5005 and timeout 3 minutes.
  2. Something external of the vim-test (can by nvim-dap or anything else) must attach in the correctly port.
  3. If nothing attached to the port, the command will be stucked for 3 minutes and raise an error (that's normal).

Obs: it's ok to modify the port and timeout:

mvn -Dmaven.surefire.debug="-agentlib:jdwp=transport=dt_socket,server=y,suspend=y, timeout={timeout},address=*:{port}" test

port : number timeout : number milliseconds.

About maventest, may I add a a:type like :DebugTestFile or :DebugTestNearest?

Or, to use an autocommand in filetype java to create something like:

command! -nargs=* -bar DebugTestNearest call test#run('debug_nearest', split(<q-args>))

command! -nargs=* -bar DebugTestFile call test#run('debug_file', split(<q-args>))


Propose

If the type is debug_file or debug_nearest, the test with maven can use the commands mentioned before, but a configuration of nvim-dap, viminspector or anything else to attach to it still needed.


nvim-dap

For java, it's pretty simple:

-- nvim dap - java configs
local dap = require("dap")

-- java
dap.configurations.java = {
  {
    type = 'java';
    request = 'attach';
    name = "Debug (Attach) - Remote";
    hostName = "127.0.0.1";
    port = 5005;
  },
}

["<F5>"] = { dap.continue, 'Debug continue or attach' }

Notes that port used in nvim-dap must match the port used in the remote debug protocol in the maven command in vim-test.

In summary, it's not a "full integration with nvim-dap", it's a simple use of the remote debug protocol interface.

In this approach, the user must trigger dap.continue after :DebugTestFile or DebugTestNearest.

I don't feel right, vim-test to call dap.continue, it's like a sort of coupling of plugins, and the attach can be triggered by any other plugin or external debugger interface, not just nvim-dap.

I will raise a draft PR with the minimal implementation.

GiuseppeMP avatar Oct 09 '22 18:10 GiuseppeMP

@codeinabox @DanielCardonaRojas #744

GiuseppeMP avatar Jul 26 '23 02:07 GiuseppeMP

As per my comment in the PR, I think it's best to pass the debug option using TestFile -Dmaven.surefire.debug=true instead of introducing new commands.

codeinabox avatar Jul 26 '23 16:07 codeinabox