Skip to content

Commit f8283e4

Browse files
authored
fix: Better compatible with jsonrpc (copilot-emacs#259)
1 parent 581cadd commit f8283e4

File tree

1 file changed

+28
-12
lines changed

1 file changed

+28
-12
lines changed

copilot.el

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,17 @@ indentation offset."
125125
(defvar copilot--opened-buffers nil
126126
"List of buffers that have been opened in Copilot.")
127127

128+
;;
129+
;; jsonrpc
130+
;;
131+
132+
(defun copilot--jsonrpc-version ()
133+
"Return the jsonrpc version."
134+
(let* ((desc (package-get-descriptor 'jsonrpc))
135+
(vlist (package-desc-version desc))
136+
(version (package-version-join vlist)))
137+
version))
138+
128139
;;
129140
;; agent
130141
;;
@@ -174,22 +185,27 @@ indentation offset."
174185
(call-process copilot-node-executable nil standard-output nil "--version"))
175186
(s-trim)
176187
(s-chop-prefix "v")
177-
(string-to-number))))
188+
(string-to-number)))
189+
(old-jsonrpc (version< (copilot--jsonrpc-version) "1.0.23")))
178190
(cond ((< node-version 18)
179191
(user-error "Node 18+ is required but found %s" node-version))
180192
(t
181193
(setq copilot--connection
182-
(make-instance 'jsonrpc-process-connection
183-
:name "copilot"
184-
:events-buffer-config `(:size ,copilot-log-max)
185-
:notification-dispatcher #'copilot--handle-notification
186-
:process (make-process :name "copilot agent"
187-
:command (list copilot-node-executable
188-
(concat copilot--base-dir "/dist/agent.js"))
189-
:coding 'utf-8-emacs-unix
190-
:connection-type 'pipe
191-
:stderr (get-buffer-create "*copilot stderr*")
192-
:noquery t)))
194+
(funcall #'make-instance
195+
'jsonrpc-process-connection
196+
:name "copilot"
197+
(if old-jsonrpc :events-buffer-scrollback-size
198+
:events-buffer-config)
199+
(if old-jsonrpc copilot-log-max
200+
`(:size ,copilot-log-max))
201+
:notification-dispatcher #'copilot--handle-notification
202+
:process (make-process :name "copilot agent"
203+
:command (list copilot-node-executable
204+
(concat copilot--base-dir "/dist/agent.js"))
205+
:coding 'utf-8-emacs-unix
206+
:connection-type 'pipe
207+
:stderr (get-buffer-create "*copilot stderr*")
208+
:noquery t)))
193209
(message "Copilot agent started.")
194210
(copilot--request 'initialize '(:capabilities (:workspace (:workspaceFolders t))))
195211
(copilot--async-request 'setEditorInfo

0 commit comments

Comments
 (0)