@@ -188,6 +188,87 @@ vim.lsp.config("rust_analyzer", {
188188 end ,
189189})
190190
191+ vim .lsp .config (" copilot" , {
192+ cmd = {
193+ " copilot-language-server" ,
194+ " --stdio" ,
195+ },
196+ root_markers = { " .git" },
197+ init_options = {
198+ editorInfo = {
199+ name = " Neovim" ,
200+ version = tostring (vim .version ()),
201+ },
202+ editorPluginInfo = {
203+ name = " Neovim" ,
204+ version = tostring (vim .version ()),
205+ },
206+ },
207+ settings = {
208+ telemetry = {
209+ telemetryLevel = " all" ,
210+ },
211+ },
212+ on_attach = function (client , bufnr )
213+ vim .api .nvim_buf_create_user_command (bufnr , " LspCopilotSignIn" , function ()
214+ client :request (
215+ --- @diagnostic disable-next-line : param-type-mismatch
216+ " signIn" ,
217+ vim .empty_dict (),
218+ function (err , result )
219+ if err then
220+ vim .notify (err .message , vim .log .levels .ERROR )
221+ return
222+ end
223+ if result .command then
224+ local code = result .userCode
225+ local command = result .command
226+ vim .fn .setreg (" +" , code )
227+ vim .fn .setreg (" *" , code )
228+ local continue = vim .fn .confirm (
229+ " Copied your one-time code to clipboard.\n " .. " Open the browser to complete the sign-in process?" ,
230+ " &Yes\n &No"
231+ )
232+ if continue == 1 then
233+ client :exec_cmd (command , { bufnr = bufnr }, function (cmd_err , cmd_result )
234+ if cmd_err then
235+ vim .notify (err .message , vim .log .levels .ERROR )
236+ return
237+ end
238+ if cmd_result .status == " OK" then
239+ vim .notify (" Signed in as " .. cmd_result .user .. " ." )
240+ end
241+ end )
242+ end
243+ end
244+
245+ if result .status == " PromptUserDeviceFlow" then
246+ vim .notify (" Enter your one-time code " .. result .userCode .. " in " .. result .verificationUri )
247+ elseif result .status == " AlreadySignedIn" then
248+ vim .notify (" Already signed in as " .. result .user .. " ." )
249+ end
250+ end
251+ )
252+ end , { desc = " Sign in Copilot with GitHub" })
253+ vim .api .nvim_buf_create_user_command (bufnr , " LspCopilotSignOut" , function ()
254+ client :request (
255+ --- @diagnostic disable-next-line : param-type-mismatch
256+ " signOut" ,
257+ vim .empty_dict (),
258+ function (err , result )
259+ if err then
260+ vim .notify (err .message , vim .log .levels .ERROR )
261+ return
262+ end
263+ if result .status == " NotSignedIn" then
264+ vim .notify (" Not signed in." )
265+ end
266+ end
267+ )
268+ end , { desc = " Sign out Copilot with GitHub" })
269+ end ,
270+ })
271+
191272vim .lsp .enable ({
192273 " gopls" ,
193274 " typos-lsp" ,
@@ -198,4 +279,5 @@ vim.lsp.enable({
198279 " harper" ,
199280 " fish" ,
200281 " rust_analyzer" ,
282+ -- "copilot",
201283})
0 commit comments