38
38
39
39
--- @param force ? boolean
40
40
function 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" )
42
43
M .startup_error = " initialization of copilot-language-server failed"
43
44
return
44
45
end
@@ -48,10 +49,7 @@ function M.buf_attach(force)
48
49
return
49
50
end
50
51
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
55
53
logger .debug (" not attaching to buffer based on force and should_attach criteria" )
56
54
return
57
55
end
@@ -64,6 +62,7 @@ function M.buf_attach(force)
64
62
-- In case it has changed, we update it
65
63
M .config .root_dir = utils .get_root_dir (config .root_dir )
66
64
65
+ logger .trace (" attaching to buffer" )
67
66
local ok , client_id_or_err = pcall (vim .lsp .start , M .config )
68
67
if not ok then
69
68
logger .error (string.format (" failed to start LSP client: %s" , client_id_or_err ))
@@ -75,6 +74,7 @@ function M.buf_attach(force)
75
74
else
76
75
logger .error (" LSP client failed to start (no client ID returned)" )
77
76
end
77
+ logger .trace (" buffer attached" )
78
78
end
79
79
80
80
function M .buf_detach ()
@@ -83,7 +83,7 @@ function M.buf_detach()
83
83
end
84
84
end
85
85
86
- --- @return nil | vim.lsp.Client
86
+ --- @return vim.lsp.Client | nil
87
87
function M .get ()
88
88
return vim .lsp .get_client_by_id (M .id )
89
89
end
95
95
--- @param callback fun ( client : table ): nil
96
96
function M .use_client (callback )
97
97
if is_disabled then
98
- logger .warn (" copilot is offline" )
98
+ logger .notify (" copilot is offline" )
99
99
return
100
100
end
101
101
102
- local client = M .get () --[[ @as table ]]
102
+ local client = M .get ()
103
103
104
104
if not client then
105
105
if not M .config then
@@ -124,36 +124,37 @@ function M.use_client(callback)
124
124
return
125
125
end
126
126
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
+ -- )
145
152
end
146
153
147
154
function M .setup ()
155
+ logger .trace (" setting up client" )
148
156
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 )
157
158
M .config = require (" copilot.client.config" ).prepare_client_config (config .server_opts_overrides , M )
158
159
159
160
if not M .config then
0 commit comments