Skip to content

Commit b5368b2

Browse files
authored
feat: extract debug & run APIs for current test class (nvim-java#14)
1 parent 8695b99 commit b5368b2

File tree

4 files changed

+24
-23
lines changed

4 files changed

+24
-23
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ require('java').dap.config_dap()
4646
require('java').test.run_current_test_class()
4747
```
4848

49+
- `debug_current_test_class` - Debug the test class in the active buffer
50+
51+
```lua
52+
require('java').test.debug_current_test_class()
53+
```
54+
4955
## How to Use
5056

5157
### Install the plugin

lua/java.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ M.dap.config_dap = java_dap.config_dap
2525
----------------------------------------------------------------------
2626
M.test = {}
2727
M.test.run_current_test_class = java_dap.run_current_test_class
28+
M.test.debug_current_test_class = java_dap.debug_current_test_class
2829

2930
----------------------------------------------------------------------
3031
-- Manipulate --

lua/java/dap/dapp.lua

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
local log = require('java-core.utils.log')
2+
local get_error_handler = require('java.handlers.error')
23

34
local Promise = require('java-core.utils.promise')
45
local JavaCoreDap = require('java-core.dap')
@@ -30,22 +31,19 @@ function M:new(args)
3031
return o
3132
end
3233

33-
function M:run_current_test_class()
34+
---Run the current test class
35+
---@param config? JavaTestLauncherConfigOverridable
36+
function M:execute_current_test_class(config)
3437
log.info('running the current class')
3538

3639
local buffer = vim.api.nvim_get_current_buf()
3740

38-
self.test_helper
41+
return self.test_helper
3942
:get_test_class_by_buffer(buffer)
4043
:thenCall(function(classes)
41-
self.test_helper:run_test(classes)
42-
end)
43-
:catch(function(err)
44-
local msg = 'failed to run the current class'
45-
46-
log.error(msg, err)
47-
error(msg .. err)
44+
return self.test_helper:run_test(classes, config)
4845
end)
46+
:catch(get_error_handler('failed to run current test class'))
4947
end
5048

5149
function M:config_dap()
@@ -55,28 +53,20 @@ function M:config_dap()
5553

5654
-- setting java adapter
5755
require('dap').adapters.java = function(callback)
58-
self.dap_helper:get_dap_adapter():thenCall(callback):catch(function(err)
59-
local msg = 'faild to set DAP adapter'
60-
61-
error(msg, err)
62-
log.error(msg, err)
63-
end)
56+
self.dap_helper
57+
:get_dap_adapter()
58+
:thenCall(callback)
59+
:catch(get_error_handler('failed to set DAP adapter'))
6460
end
6561

6662
-- setting java config
6763
return self.dap_helper:get_dap_config()
6864
end)
6965
:thenCall(function(dap_config)
7066
log.debug('set dap config: ', dap_config)
71-
7267
require('dap').configurations.java = dap_config
7368
end)
74-
:catch(function(err)
75-
local msg = 'faild to set DAP configuration'
76-
77-
log.error(msg, err)
78-
error(msg .. err)
79-
end)
69+
:catch(get_error_handler('failed to set DAP configuration'))
8070
end
8171

8272
return M

lua/java/dap/init.lua

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ end
2020

2121
---Runs the current test class
2222
function M.run_current_test_class()
23-
return JavaDap:new(jdtls()):run_current_test_class()
23+
return JavaDap:new(jdtls()):execute_current_test_class({ noDebug = true })
24+
end
25+
26+
function M.debug_current_test_class()
27+
return JavaDap:new(jdtls()):execute_current_test_class()
2428
end
2529

2630
---Configures the dap

0 commit comments

Comments
 (0)