Skip to content

Commit c2a11d1

Browse files
committed
Wait for jdtls ServiceReady to call the custom method after #711
1 parent a9b5fc8 commit c2a11d1

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

lua/jdtls/setup.lua

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,38 @@ local URI_SCHEME_PATTERN = '^([a-zA-Z]+[a-zA-Z0-9+-.]*)://.*'
99
local get_clients = vim.lsp.get_clients or vim.lsp.get_active_clients
1010

1111

12-
local status_callback = function(_, result)
12+
M._service_ready = false
13+
M._service_ready_co = {}
14+
15+
function M.service_ready_handler(_, msg)
16+
if "ServiceReady" == msg.type then
17+
M._service_ready = true
18+
for _, co in ipairs(M._co) do
19+
coroutine.resume(co)
20+
end
21+
M._service_ready_co = {}
22+
end
23+
end
24+
25+
---@param cb function
26+
function M.wait_service_ready(cb)
27+
if M._service_ready then
28+
return cb()
29+
end
30+
local pco = coroutine.running()
31+
local co = coroutine.create(function()
32+
local resp = cb()
33+
coroutine.resume(pco, resp)
34+
return resp
35+
end)
36+
table.insert(M._service_ready_co, co)
37+
return coroutine.yield()
38+
end
39+
40+
local status_callback = function(err, result)
1341
api.nvim_command(string.format(':echohl Function | echo "%s" | echohl None',
1442
string.sub(result.message, 1, vim.v.echospace)))
43+
M.service_ready_handler(err, result)
1544
end
1645

1746

0 commit comments

Comments
 (0)