This repository was archived by the owner on Nov 30, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathrunner.lua
More file actions
75 lines (60 loc) · 1.75 KB
/
runner.lua
File metadata and controls
75 lines (60 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
local log = require('java-core.utils.log')
---@class java_core.DapRunner
---@field private server uv_tcp_t
local M = {}
---@return java_core.DapRunner
function M:new()
local o = {
server = nil,
}
setmetatable(o, self)
self.__index = self
return o
end
---Dap run with given config
---@param config java_core.DapLauncherConfig
---@param report java_test.JUnitTestReport
function M:run_by_config(config, report)
log.debug('running dap with config: ', config)
require('dap').run(config --[[@as Configuration]], {
before = function(conf)
return self:before(conf, report)
end,
after = function()
return self:after()
end,
})
end
---Runs before the dap run
---@private
---@param conf java_core.DapLauncherConfig
---@param report java_test.JUnitTestReport
---@return java_core.DapLauncherConfig
function M:before(conf, report)
log.debug('running "before" callback')
self.server = assert(vim.loop.new_tcp(), 'uv.new_tcp() must return handle')
self.server:bind('127.0.0.1', 0)
self.server:listen(128, function(err)
assert(not err, err)
local sock = assert(vim.loop.new_tcp(), 'uv.new_tcp must return handle')
self.server:accept(sock)
local success = sock:read_start(report:get_stream_reader(sock))
assert(success == 0, 'failed to listen to reader')
end)
-- replace the port number in the generated args
conf.args =
conf.args:gsub('-port ([0-9]+)', '-port ' .. self.server:getsockname().port)
return conf
end
---Runs aafter the dap run
---@private
function M:after()
vim.debug('running "after" callback')
if self.server then
self.server:shutdown()
self.server:close()
end
end
return M
---@class java_core.DapRunReport
---@field get_stream_reader fun(self: java_core.DapRunReport, conn: uv_tcp_t): fun(err: string|nil, buffer: string|nil)