Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions copilot.el
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@

(require 'cl-lib)
(require 'compile)
(require 'files)
(require 'json)
(require 'jsonrpc)
(require 'subr-x)
Expand Down Expand Up @@ -154,7 +155,7 @@ find indentation offset."
"The name of the package to install copilot server.")

(defcustom copilot-install-dir (expand-file-name
(locate-user-emacs-file (f-join ".cache" "copilot")))
(f-join user-emacs-directory ".cache" "copilot"))
"Directory in which the servers will be installed."
:risky t
:type 'directory
Expand Down Expand Up @@ -316,14 +317,13 @@ Incremented after each change.")
((and (file-name-absolute-p copilot-server-executable)
(file-exists-p copilot-server-executable))
copilot-server-executable)
((executable-find copilot-server-executable t))
((executable-find copilot-server-executable))
(t
(let ((path (executable-find
(f-join copilot-install-dir
(cond ((eq system-type 'windows-nt) "")
(t "bin"))
copilot-server-executable)
t)))
copilot-server-executable))))
(unless (and path (file-exists-p path))
(error "The package %s is not installed. Unable to find %s"
copilot-server-package-name path))
Expand Down Expand Up @@ -360,7 +360,13 @@ Incremented after each change.")
(defun copilot-install-server ()
"Interactively install server."
(interactive)
(if-let* ((npm-binary (executable-find "npm")))
(if-let* ((shell-file-name (if (connection-local-p shell-file-name)
(default-toplevel-value 'shell-file-name)
shell-file-name))
(default-directory (if (file-remote-p default-directory)
"~/"
default-directory))
(npm-binary (executable-find "npm")))
(progn
(make-directory copilot-install-dir 'parents)
(copilot-async-start-process
Expand Down Expand Up @@ -462,10 +468,9 @@ SUCCESS-FN is the CALLBACK."

(defun copilot--start-server ()
"Start the copilot server process in local."
(cond
((not (file-exists-p (copilot-server-executable)))
(user-error "Server is not installed, please install via `M-x copilot-install-server`"))
(t
(let ((default-directory (if (file-remote-p default-directory)
"~/"
default-directory)))
(let ((installed-version (copilot-installed-version)))
(when (and copilot-version (not (equal installed-version copilot-version)))
(warn "This package has been tested for Copilot server version %s but version %s has been detected.
Expand All @@ -481,7 +486,7 @@ You can change the installed version with `M-x copilot-reinstall-server` or remo
`( :editorInfo (:name "Emacs" :version ,emacs-version)
:editorPluginInfo (:name "copilot.el" :version ,(or (copilot-installed-version) "unknown"))
,@(when copilot-network-proxy
`(:networkProxy ,copilot-network-proxy)))))))
`(:networkProxy ,copilot-network-proxy))))))

;;
;; login / logout
Expand Down