@@ -9,9 +9,38 @@ local URI_SCHEME_PATTERN = '^([a-zA-Z]+[a-zA-Z0-9+-.]*)://.*'
9
9
local get_clients = vim .lsp .get_clients or vim .lsp .get_active_clients
10
10
11
11
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 )
13
41
api .nvim_command (string.format (' :echohl Function | echo "%s" | echohl None' ,
14
42
string.sub (result .message , 1 , vim .v .echospace )))
43
+ M .service_ready_handler (err , result )
15
44
end
16
45
17
46
0 commit comments