Skip to content

Commit 4f1f310

Browse files
authored
fix: sometimes dap is not configured correctly (#126)
- when other LSP is configured for java like none_ls, autocmd will fire and unregister since I have added once=true when registing the aucmd. So dap configure will never be called
1 parent b9ef7df commit 4f1f310

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

lua/java/api/dap.lua

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@ local M = {}
1212
function M.setup_dap_on_lsp_attach()
1313
log.info('add LspAttach event handlers to setup dap adapter & config')
1414

15-
vim.api.nvim_create_autocmd('LspAttach', {
16-
pattern = '*',
15+
M.even_id = vim.api.nvim_create_autocmd('LspAttach', {
1716
callback = M.on_jdtls_attach,
18-
once = true,
1917
group = vim.api.nvim_create_augroup('nvim-java-dap-config', {}),
2018
})
2119
end
@@ -35,10 +33,19 @@ end
3533
function M.on_jdtls_attach(ev)
3634
local client = vim.lsp.get_client_by_id(ev.data.client_id)
3735

38-
if client.name == 'jdtls' then
36+
if client == nil then
37+
return
38+
end
39+
40+
local server_name = client.name
41+
42+
if server_name == 'jdtls' then
3943
log.info('setup java dap config & adapter')
4044

4145
M.config_dap()
46+
47+
-- removing the event handler after configuring dap
48+
vim.api.nvim_del_autocmd(M.even_id)
4249
end
4350
end
4451

0 commit comments

Comments
 (0)