Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ require('java').dap.config_dap()
require('java').test.run_current_test_class()
```

- `debug_current_test_class` - Debug the test class in the active buffer

```lua
require('java').test.debug_current_test_class()
```

## How to Use

### Install the plugin
Expand Down
1 change: 1 addition & 0 deletions lua/java.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ M.dap.config_dap = java_dap.config_dap
----------------------------------------------------------------------
M.test = {}
M.test.run_current_test_class = java_dap.run_current_test_class
M.test.debug_current_test_class = java_dap.debug_current_test_class

----------------------------------------------------------------------
-- Manipulate --
Expand Down
34 changes: 12 additions & 22 deletions lua/java/dap/dapp.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
local log = require('java-core.utils.log')
local get_error_handler = require('java.handlers.error')

local Promise = require('java-core.utils.promise')
local JavaCoreDap = require('java-core.dap')
Expand Down Expand Up @@ -30,22 +31,19 @@ function M:new(args)
return o
end

function M:run_current_test_class()
---Run the current test class
---@param config? JavaTestLauncherConfigOverridable
function M:execute_current_test_class(config)
log.info('running the current class')

local buffer = vim.api.nvim_get_current_buf()

self.test_helper
return self.test_helper
:get_test_class_by_buffer(buffer)
:thenCall(function(classes)
self.test_helper:run_test(classes)
end)
:catch(function(err)
local msg = 'failed to run the current class'

log.error(msg, err)
error(msg .. err)
return self.test_helper:run_test(classes, config)
end)
:catch(get_error_handler('failed to run current test class'))
end

function M:config_dap()
Expand All @@ -55,28 +53,20 @@ function M:config_dap()

-- setting java adapter
require('dap').adapters.java = function(callback)
self.dap_helper:get_dap_adapter():thenCall(callback):catch(function(err)
local msg = 'faild to set DAP adapter'

error(msg, err)
log.error(msg, err)
end)
self.dap_helper
:get_dap_adapter()
:thenCall(callback)
:catch(get_error_handler('failed to set DAP adapter'))
end

-- setting java config
return self.dap_helper:get_dap_config()
end)
:thenCall(function(dap_config)
log.debug('set dap config: ', dap_config)

require('dap').configurations.java = dap_config
end)
:catch(function(err)
local msg = 'faild to set DAP configuration'

log.error(msg, err)
error(msg .. err)
end)
:catch(get_error_handler('failed to set DAP configuration'))
end

return M
6 changes: 5 additions & 1 deletion lua/java/dap/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ end

---Runs the current test class
function M.run_current_test_class()
return JavaDap:new(jdtls()):run_current_test_class()
return JavaDap:new(jdtls()):execute_current_test_class({ noDebug = true })
end

function M.debug_current_test_class()
return JavaDap:new(jdtls()):execute_current_test_class()
end

---Configures the dap
Expand Down