-
-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathinit.lua
More file actions
112 lines (91 loc) · 2.8 KB
/
init.lua
File metadata and controls
112 lines (91 loc) · 2.8 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
local log = require('java.utils.log')
local buf_util = require('java.utils.buffer')
local win_util = require('java.utils.window')
local async = require('java-core.utils.async').sync
local notify = require('java-core.utils.notify')
local DapSetup = require('java-dap.api.setup')
local DapRunner = require('java-dap.api.runner')
local JavaCoreTestApi = require('java-core.api.test')
local profile_config = require('java.api.profile_config')
---@class JavaDap
---@field private client LspClient
---@field private dap JavaCoreDap
---@field private test_api java_core.TestApi
---@field private test_client java-core.TestClient
local M = {}
---@param args { client: LspClient }
---@return JavaDap
function M:new(args)
local o = {
client = args.client,
}
o.test_api = JavaCoreTestApi:new({
client = args.client,
runner = DapRunner(),
})
o.dap = DapSetup(args.client)
setmetatable(o, self)
self.__index = self
return o
end
---Run the current test class
---@param report java_test.JUnitTestReport
---@param config JavaCoreDapLauncherConfigOverridable
function M:execute_current_test_class(report, config)
log.debug('running the current class')
return self.test_api:run_class_by_buffer(
buf_util.get_curr_buf(),
report,
config
)
end
function M:execute_current_test_method(report, config)
log.debug('running the current method')
local method = self:find_current_test_method()
if not method then
notify.warn('cursor is not on a test method')
return
end
self.test_api:run_test({ method }, report, config)
end
function M:find_current_test_method()
log.debug('finding the current test method')
local cursor = win_util.get_cursor()
local methods = self.test_api:get_test_methods(buf_util.get_curr_uri())
for _, method in ipairs(methods) do
local line_start = method.range.start.line
local line_end = method.range['end'].line
if cursor.line >= line_start and cursor.line <= line_end then
return method
end
end
end
function M:config_dap()
log.debug('set dap adapter callback function')
local nvim_dap = require('dap')
nvim_dap.adapters.java = function(callback)
async(function()
local adapter = self.dap:get_dap_adapter()
callback(adapter --[[@as Adapter]])
end).run()
end
local dap_config = self.dap:get_dap_config()
for _, config in ipairs(dap_config) do
local profile = profile_config.get_active_profile(config.name)
if profile then
config.vmArgs = profile.vm_args
config.args = profile.prog_args
end
end
-- if dap is already running, need to terminate it to apply new config
if nvim_dap.session then
nvim_dap.terminate()
if vim.g.nvim_java_config.notifications.dap then
notify.warn('Terminating current dap session')
end
end
-- end
nvim_dap.configurations.java = nvim_dap.configurations.java or {}
vim.list_extend(nvim_dap.configurations.java, dap_config)
end
return M