Skip to content

Commit 535ef61

Browse files
authored
refactor: Consolidate copilot server executable path logic (#334)
1 parent 900aecc commit 535ef61

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

copilot.el

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,7 @@ find indentation offset."
139139
:type 'directory
140140
:group 'copilot)
141141

142-
(defconst copilot--server-executable
143-
(if (eq system-type 'windows-nt)
144-
(f-join copilot-install-dir "node_modules" "copilot-node-server"
145-
"copilot" "dist" "agent.js")
146-
(f-join copilot-install-dir "lib" "node_modules" "copilot-node-server"
147-
"copilot" "dist" "agent.js"))
142+
(defvar copilot--server-executable nil
148143
"The dist directory containing agent.js file.")
149144

150145
(defcustom copilot-version "1.27.0"
@@ -299,7 +294,7 @@ SUCCESS-FN is the CALLBACK."
299294
:process (make-process :name "copilot agent"
300295
:command (append
301296
(list copilot-node-executable
302-
copilot--server-executable)
297+
(copilot-server-executable))
303298
copilot-server-args)
304299
:coding 'utf-8-emacs-unix
305300
:connection-type 'pipe
@@ -1036,6 +1031,26 @@ in `post-command-hook'."
10361031
(match-string 1))))))
10371032
possible-paths)))
10381033

1034+
(defun copilot-server-executable ()
1035+
"Return the location of the agent.js file."
1036+
(if copilot--server-executable
1037+
copilot--server-executable
1038+
(setq copilot--server-executable
1039+
(let ((possible-paths
1040+
(list
1041+
(when (eq system-type 'windows-nt)
1042+
(f-join copilot-install-dir "node_modules"
1043+
"copilot-node-server" "copilot" "dist" "agent.js"))
1044+
(f-join copilot-install-dir "lib" "node_modules"
1045+
"copilot-node-server" "copilot" "dist" "agent.js")
1046+
(f-join copilot-install-dir "lib64" "node_modules"
1047+
"copilot-node-server" "copilot" "dist" "agent.js"))))
1048+
(seq-some
1049+
(lambda (path)
1050+
(when (and path (file-exists-p path))
1051+
path))
1052+
possible-paths)))))
1053+
10391054
;; XXX: This function is modified from `lsp-mode'; see `lsp-async-start-process'
10401055
;; function for more information.
10411056
(defun copilot-async-start-process (callback error-callback &rest command)

0 commit comments

Comments
 (0)