Skip to content

Commit

Permalink
refactor: Consolidate copilot server executable path logic
Browse files Browse the repository at this point in the history
  • Loading branch information
LemonBreezes committed Aug 15, 2024
1 parent 3af3a5f commit 203b474
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions copilot.el
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,6 @@ find indentation offset."
:type 'directory
:group 'copilot)

(defconst copilot--server-executable
(if (eq system-type 'windows-nt)
(f-join copilot-install-dir "node_modules" "copilot-node-server"
"copilot" "dist" "agent.js")
(f-join copilot-install-dir "lib" "node_modules" "copilot-node-server"
"copilot" "dist" "agent.js"))
"The dist directory containing agent.js file.")

(defcustom copilot-version "1.27.0"
"Copilot version.
Expand Down Expand Up @@ -299,7 +291,7 @@ SUCCESS-FN is the CALLBACK."
:process (make-process :name "copilot agent"
:command (append
(list copilot-node-executable
copilot--server-executable)
(copilot-server-executable))
copilot-server-args)
:coding 'utf-8-emacs-unix
:connection-type 'pipe
Expand Down Expand Up @@ -1036,6 +1028,26 @@ in `post-command-hook'."
(match-string 1))))))
possible-paths)))

(defun copilot-server-executable ()
"Return the location of the agent.js file."
(if copilot--server-executable
copilot--server-executable
(setq copilot--server-executable
(let ((possible-paths
(list
(when (eq system-type 'windows-nt)
(f-join copilot-install-dir "node_modules"
"copilot-node-server" "copilot" "dist" "agent.js"))
(f-join copilot-install-dir "lib" "node_modules"
"copilot-node-server" "copilot" "dist" "agent.js")
(f-join copilot-install-dir "lib64" "node_modules"
"copilot-node-server" "copilot" "dist" "agent.js"))))
(seq-some
(lambda (path)
(when (and path (file-exists-p path))
path))
possible-paths)))))

;; XXX: This function is modified from `lsp-mode'; see `lsp-async-start-process'
;; function for more information.
(defun copilot-async-start-process (callback error-callback &rest command)
Expand Down

0 comments on commit 203b474

Please sign in to comment.