Skip to content

Commit e4d02ca

Browse files
authored
fix: delay copilot login check and avoid raising error (#4709)
There appears to be some issues with being too eager to check for the login. The server may not have been properly initialized, which results in an error being raised by lsp-copilot--authenticated-as. That seems to wreck havoc in the call stack and leave lsp in a weird state -- there is a copilot server running, there seems to be a client that can be restarted... but there is no workspace registered ... This change give some time for the server to spin up and avoids raising an error if the authentication request did not work.
1 parent cf5b97d commit e4d02ca

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

clients/lsp-copilot.el

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@
4343
:type 'boolean
4444
:group 'lsp-copilot)
4545

46+
(defcustom lsp-copilot-auth-check-delay 5
47+
"How much time to wait before checking if the server is properly authenticated.
48+
49+
Set this value to nil if you do not with for the check to be made."
50+
:type '(choice (const :tag "Do not check" nil)
51+
(integer :tag "Seconds" 5)))
52+
4653
(defcustom lsp-copilot-langserver-command-args '("--stdio")
4754
"Command to start copilot-langserver."
4855
:type '(repeat string)
@@ -188,8 +195,16 @@ automatically, browse to %s." user-code verification-uri))
188195
(let ((caps (lsp--workspace-server-capabilities workspace)))
189196
(lsp:set-server-capabilities-inline-completion-provider? caps t))
190197

191-
(unless (lsp-copilot--authenticated-as)
192-
(lsp-copilot-login)))
198+
199+
(when lsp-copilot-auth-check-delay
200+
(run-at-time lsp-copilot-auth-check-delay
201+
nil
202+
(lambda ()
203+
(condition-case err
204+
(unless (lsp-copilot--authenticated-as)
205+
(lsp-copilot-login))
206+
(t (lsp--error "Could not authenticate with copilot: %s" (error-message-string err)))))))
207+
t)
193208

194209
;; Server installed by emacs
195210
(lsp-register-client

0 commit comments

Comments
 (0)