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

Make dap.test_class() and dap.test_nearest_method() callable from nvim-dap window #684

Open
johannww opened this issue Aug 23, 2024 · 0 comments

Comments

@johannww
Copy link

Problem Statement

There could be a way to call test_class() and test_nearest_method from the nvim-dap window when calling the "DapNew" command.

image

Currently, I achieve this with the following tweak in the "ftplugin/java.lua":

-- above this line is config definition, as suggested by install instructions
local jdtls = require('jdtls')
jdtls.start_or_attach(config)


-- enabling calling nearest method and test class
-- from nvim-dap window
local jdtls_dap = require('jdtls.dap')
jdtls_dap.setup_dap()

local dap = require('dap')

local old_dap_function = dap.adapters.java
dap.adapters.java = function(callback, configDap)
    if configDap.name == "Nearest Method" then
        jdtls.test_nearest_method()
    elseif configDap.name == "Test Class" then
        jdtls.test_class()
    else
        old_dap_function(callback, configDap)
    end
end

dap.configurations.java = {
    {
        type = 'java',
        request = 'launch',
        name = "Nearest Method",
    },
    {
        type = 'java',
        request = 'launch',
        name = "Test Class",
    }
}

Ideas or possible solutions

  • implementing a similar logic as in the tweaked debug adapter in start_debug_adapter()
  • Adding the dap.configurations in setup_dap
  • Perhaps, add another function to create the Nearest Method and Test Class configurations.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant