Skip to content

Commit 40e8494

Browse files
committed
Add dap configuration provider
Depends on mfussenegger/nvim-dap#1237
1 parent ad5ab1c commit 40e8494

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

lua/jdtls/dap.lua

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,10 @@ function M.setup_dap_main_class_configs(opts)
657657
print('nvim-dap is not available')
658658
return
659659
end
660+
if dap.providers and dap.providers.configs then
661+
-- If users call this manually disable the automatic discovery on dap.continue()
662+
dap.providers.configs["jdtls"] = nil
663+
end
660664
if opts.verbose then
661665
vim.notify('Fetching debug configurations')
662666
end
@@ -711,6 +715,32 @@ function M.setup_dap(opts)
711715
end
712716
end
713717
dap.adapters.java = start_debug_adapter
718+
719+
if dap.providers and dap.providers.configs then
720+
dap.providers.configs["jdtls"] = function (bufnr)
721+
if vim.bo[bufnr].filetype ~= "java" then
722+
return {}
723+
end
724+
local co = coroutine.running()
725+
local resumed = false
726+
vim.defer_fn(function()
727+
if not resumed then
728+
resumed = true
729+
coroutine.resume(co, {})
730+
vim.schedule(function()
731+
vim.notify("Discovering main classes took too long", vim.log.levels.INFO)
732+
end)
733+
end
734+
end, 2000)
735+
M.fetch_main_configs(nil, function(configs)
736+
if not resumed then
737+
resumed = true
738+
coroutine.resume(co, configs)
739+
end
740+
end)
741+
return coroutine.yield()
742+
end
743+
end
714744
end
715745
---@class JdtSetupDapOpts
716746
---@field config_overrides JdtDapConfig These will be used as default overrides for |jdtls.dap.test_class|, |jdtls.dap.test_nearest_method| and discovered main classes

lua/jdtls/setup.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ local function extract_data_dir(bufnr)
202202
end
203203

204204

205-
---@param client lsp.Client
205+
---@param client vim.lsp.Client
206206
---@param opts jdtls.start.opts
207207
local function add_commands(client, bufnr, opts)
208208
local function create_cmd(name, command, cmdopts)

0 commit comments

Comments
 (0)