3838
3939--- @param force ? boolean
4040function M .buf_attach (force )
41- if lsp .binary .initialization_failed then
41+ if lsp .initialization_failed () then
42+ logger .error (" copilot-language-server failed to initialize" )
4243 M .startup_error = " initialization of copilot-language-server failed"
4344 return
4445 end
@@ -48,10 +49,7 @@ function M.buf_attach(force)
4849 return
4950 end
5051
51- local bufnr = vim .api .nvim_get_current_buf ()
52- local bufname = vim .api .nvim_buf_get_name (bufnr )
53-
54- if not (force or (config .should_attach (bufnr , bufname ) and util .should_attach ())) then
52+ if not (force or util .should_attach ()) then
5553 logger .debug (" not attaching to buffer based on force and should_attach criteria" )
5654 return
5755 end
@@ -64,6 +62,7 @@ function M.buf_attach(force)
6462 -- In case it has changed, we update it
6563 M .config .root_dir = utils .get_root_dir (config .root_dir )
6664
65+ logger .trace (" attaching to buffer" )
6766 local ok , client_id_or_err = pcall (vim .lsp .start , M .config )
6867 if not ok then
6968 logger .error (string.format (" failed to start LSP client: %s" , client_id_or_err ))
@@ -75,6 +74,7 @@ function M.buf_attach(force)
7574 else
7675 logger .error (" LSP client failed to start (no client ID returned)" )
7776 end
77+ logger .trace (" buffer attached" )
7878end
7979
8080function M .buf_detach ()
@@ -83,7 +83,7 @@ function M.buf_detach()
8383 end
8484end
8585
86- --- @return nil | vim.lsp.Client
86+ --- @return vim.lsp.Client | nil
8787function M .get ()
8888 return vim .lsp .get_client_by_id (M .id )
8989end
9595--- @param callback fun ( client : table ): nil
9696function M .use_client (callback )
9797 if is_disabled then
98- logger .warn (" copilot is offline" )
98+ logger .notify (" copilot is offline" )
9999 return
100100 end
101101
102- local client = M .get () --[[ @as table ]]
102+ local client = M .get ()
103103
104104 if not client then
105105 if not M .config then
@@ -124,36 +124,37 @@ function M.use_client(callback)
124124 return
125125 end
126126
127- local timer , err , _ = vim .uv .new_timer ()
128-
129- if not timer then
130- logger .error (string.format (" error creating timer: %s" , err ))
131- return
132- end
133-
134- timer :start (
135- 0 ,
136- 100 ,
137- vim .schedule_wrap (function ()
138- if client .initialized and not timer :is_closing () then
139- timer :stop ()
140- timer :close ()
141- callback (client )
142- end
143- end )
144- )
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+ -- )
145152end
146153
147154function M .setup ()
155+ logger .trace (" setting up client" )
148156 local node_command = config .copilot_node_command
149-
150- -- TODO: merge the two types into an indirection
151- if config .server .type == " nodejs" then
152- lsp .nodejs .setup (node_command , config .server .custom_server_filepath )
153- elseif config .server .type == " binary" then
154- lsp .binary .setup (config .server .custom_server_filepath )
155- end
156-
157+ lsp .setup (config .server , node_command )
157158 M .config = require (" copilot.client.config" ).prepare_client_config (config .server_opts_overrides , M )
158159
159160 if not M .config then
0 commit comments