refactor!: go from promises to co-routines by s1n7ax · Pull Request #30 · nvim-java/nvim-java · GitHub
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
23 changes: 12 additions & 11 deletions lua/java.lua
34 changes: 23 additions & 11 deletions lua/java/dap/api.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
local JavaDap = require('java.dap')

local log = require('java.utils.log')
local notify = require('java-core.utils.notify')
local get_error_handler = require('java.handlers.error')
local jdtls = require('java.jdtls')
local jdtls = require('java.utils.jdtls')
local async = require('java-core.utils.async').sync

local M = {}

Expand All @@ -19,24 +19,36 @@ function M.setup_dap_on_lsp_attach()
})
end

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

return async(function()
return JavaDap:new(jdtls()):execute_current_test_class({ noDebug = true })
end)
.catch(get_error_handler('failed to run the current test class'))
.run()
end

function M.debug_current_test_class()
return JavaDap:new(jdtls()):execute_current_test_class({})
log.info('debug current test class')

return async(function()
return JavaDap:new(jdtls()):execute_current_test_class({})
end)
.catch(get_error_handler('failed to debug the current test class'))
.run()
end

---Configures the dap
function M.config_dap()
return JavaDap:new(jdtls())
:config_dap()
:catch(get_error_handler('failed to configure dap'))
log.info('configuring dap')

return async(function()
JavaDap:new(jdtls()):config_dap()
end)
.catch(get_error_handler('dap configuration failed'))
.run()
end

---@private
---@param ev any
function M.on_jdtls_attach(ev)
local client = vim.lsp.get_client_by_id(ev.data.client_id)

Expand Down
38 changes: 14 additions & 24 deletions lua/java/dap/init.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
local log = require('java.utils.log')
local get_error_handler = require('java.handlers.error')
local async = require('java-core.utils.async').sync

local Promise = require('java-core.utils.promise')
local JavaCoreDap = require('java-core.dap')
local JavaCoreTestApi = require('java-core.api.test')

Expand Down Expand Up @@ -34,36 +33,27 @@ end
---Run the current test class
---@param config JavaCoreDapLauncherConfigOverridable
function M:execute_current_test_class(config)
log.info('running the current class')
log.debug('running the current class')

local buffer = vim.api.nvim_get_current_buf()

return self.test_api
:run_class_by_buffer(buffer, config)
:catch(get_error_handler('failed to run current test class'))
return self.test_api:run_class_by_buffer(buffer, config)
end

function M:config_dap()
return Promise.resolve()
:thenCall(function()
log.debug('set dap adapter callback function')
log.debug('set dap adapter callback function')

-- setting java adapter
require('dap').adapters.java = function(callback)
self.dap
:get_dap_adapter()
:thenCall(callback)
:catch(get_error_handler('failed to set DAP adapter'))
end
require('dap').adapters.java = function(callback)
async(function()
local adapter = self.dap:get_dap_adapter()
callback(adapter --[[@as Adapter]])
end).run()
end

-- setting java config
return self.dap:get_dap_config()
end)
:thenCall(function(dap_config)
log.debug('set dap config: ', dap_config)
require('dap').configurations.java = dap_config
end)
:catch(get_error_handler('failed to set DAP configuration'))
local dap_config = self.dap:get_dap_config()

log.debug('set dap config: ', dap_config)
require('dap').configurations.java = dap_config
end

return M
5 changes: 1 addition & 4 deletions lua/java/handlers/error.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,8 @@ end

---Returns a error handler
---@param msg string messages to show in the error
---@param ...? any values for place holders in the message
---@return fun(err: any) # function that log and notify the error
local function get_error_handler(msg, ...)
msg = string.format(msg, ...)

local function get_error_handler(msg)
return function(err)
local trace = debug.traceback()

Expand Down
File renamed without changes.
File renamed without changes.
50 changes: 26 additions & 24 deletions lua/java/lspconfig.lua → lua/java/utils/lspconfig.lua
File renamed without changes.