From 601d236064f09c2c9ca74061bd0850c5905152ce Mon Sep 17 00:00:00 2001 From: s1n7ax Date: Wed, 15 Nov 2023 22:47:26 +0530 Subject: [PATCH 1/2] feat: extract debug & run APIs for current test class --- README.md | 6 ++++++ lua/java.lua | 2 ++ lua/java/dap/dapp.lua | 34 ++++++++++++---------------------- lua/java/dap/init.lua | 6 +++++- 4 files changed, 25 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 739f9a6..94b23ce 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/lua/java.lua b/lua/java.lua index 2871684..c5be22c 100644 --- a/lua/java.lua +++ b/lua/java.lua @@ -25,6 +25,8 @@ 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 +M.test.hello = java_dap.debug_current_test_class ---------------------------------------------------------------------- -- Manipulate -- diff --git a/lua/java/dap/dapp.lua b/lua/java/dap/dapp.lua index 5cd30b7..4e08674 100644 --- a/lua/java/dap/dapp.lua +++ b/lua/java/dap/dapp.lua @@ -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') @@ -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() @@ -55,12 +53,10 @@ 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 @@ -68,15 +64,9 @@ function M:config_dap() 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 diff --git a/lua/java/dap/init.lua b/lua/java/dap/init.lua index 06daf68..94ba0e5 100644 --- a/lua/java/dap/init.lua +++ b/lua/java/dap/init.lua @@ -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 From bbe2881c583ed86ec881c9cb7fc160baa12a2177 Mon Sep 17 00:00:00 2001 From: s1n7ax Date: Wed, 15 Nov 2023 22:56:46 +0530 Subject: [PATCH 2/2] chore: code clean up --- lua/java.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/lua/java.lua b/lua/java.lua index c5be22c..43ac7a7 100644 --- a/lua/java.lua +++ b/lua/java.lua @@ -26,7 +26,6 @@ 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 -M.test.hello = java_dap.debug_current_test_class ---------------------------------------------------------------------- -- Manipulate --