@@ -3,6 +3,7 @@ local util = require("copilot.util")
3
3
local logger = require (" copilot.logger" )
4
4
local lsp = require (" copilot.lsp" )
5
5
local utils = require (" copilot.client.utils" )
6
+ local client_config = require (" copilot.client.config" )
6
7
7
8
local is_disabled = false
8
9
@@ -107,6 +108,7 @@ function M.use_client(callback)
107
108
return
108
109
end
109
110
111
+ client_config .add_callback (callback )
110
112
local client_id , err = vim .lsp .start (M .config )
111
113
112
114
if not client_id then
@@ -115,40 +117,11 @@ function M.use_client(callback)
115
117
end
116
118
117
119
store_client_id (client_id )
118
-
119
- client = M .get () --[[ @as table]]
120
- end
121
-
122
- if client .initialized then
120
+ elseif not client .initialized then
121
+ client_config .add_callback (callback )
122
+ else
123
123
callback (client )
124
- return
125
124
end
126
-
127
- logger .error (" client is not initialized yet" )
128
- -- Following code is commented out for now because:
129
- -- 1) I am hoping it is not needed anymore and
130
- -- 2) It causes issues with testing >_<
131
- --
132
- -- local timer, err, _ = vim.uv.new_timer()
133
- --
134
- -- if not timer then
135
- -- logger.error(string.format("error creating timer: %s", err))
136
- -- return
137
- -- end
138
- --
139
- -- timer:start(
140
- -- 0,
141
- -- 100,
142
- -- vim.schedule_wrap(function()
143
- -- if client.initialized and not timer:is_closing() then
144
- -- timer:stop()
145
- -- timer:close()
146
- -- callback(client)
147
- -- else
148
- -- logger.error("client not initialized yet")
149
- -- end
150
- -- end)
151
- -- )
152
125
end
153
126
154
127
function M .setup ()
0 commit comments