-
-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathinit.lua
More file actions
74 lines (60 loc) · 2.09 KB
/
init.lua
File metadata and controls
74 lines (60 loc) · 2.09 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
local M = {}
function M.setup()
local event = require('java-core.utils.event')
local project_config = require('java.api.profile_config')
local err = require('java-core.utils.errors')
local has_dap = pcall(require, 'dap')
if not has_dap then
err.throw([[
Please install https://github.com/mfussenegger/nvim-dap to enable debugging
or disable the java_debug_adapter.enable option in your config
]])
end
event.on_jdtls_attach({
callback = function()
project_config.setup()
M.config_dap()
end,
})
end
---Configure dap
function M.config_dap()
local get_error_handler = require('java-core.utils.error_handler')
local runner = require('async.runner')
return runner(function()
local lsp_utils = require('java-core.utils.lsp')
local nvim_dap = require('dap')
local profile_config = require('java.api.profile_config')
local DapSetup = require('java-dap.setup')
local client = lsp_utils.get_jdtls()
local dap = DapSetup(client)
----------------------------------------------------------------------
-- adapter --
----------------------------------------------------------------------
nvim_dap.adapters.java = function(callback)
runner(function()
local adapter = dap:get_dap_adapter()
callback(adapter --[[@as dap.Adapter]])
end).run()
end
----------------------------------------------------------------------
-- config --
----------------------------------------------------------------------
local dap_config = 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 nvim_dap.session then
nvim_dap.terminate()
end
nvim_dap.configurations.java = nvim_dap.configurations.java or {}
vim.list_extend(nvim_dap.configurations.java, dap_config)
end)
.catch(get_error_handler('dap configuration failed'))
.run()
end
return M