Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure cider-jack-in fails gracefully when commands are not found #1733

Merged
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
* Signal an error sooner if the user misconfigured `cider-known-endpoints`.
* `cider-inspect-read-and-inspect` is obsolete. Use `cider-inspect-expression` instead.
* Extremely long overlays are truncated and `cider-inspect-last-result` is recommended.
* Signal `user-error` instead of `error` on jack-in if a project type is not supported.
* Users with `boot.sh` instead of `boot` should customize `cider-boot-command` instead of relying on automatic detection.

### Bugs fixed

Expand All @@ -32,6 +34,7 @@
* [#1561](https://github.com/clojure-emacs/cider/issues/1561): Use an appropriate font-lock-face for variables, macros and functions in
the ns-browser.
* [#1708](https://github.com/clojure-emacs/cider/issues/1708): Fix `cider-popup-buffer-display` when another frame is used for the error buffer.
* [#1733](https://github.com/clojure-emacs/cider/pull/1733): Better error handling when no boot command is found in exec-path.

## 0.12.0 (2016-04-16)

Expand Down
54 changes: 29 additions & 25 deletions cider.el
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,7 @@ version from the CIDER package or library.")
:group 'cider)

(defcustom cider-boot-command
(or (executable-find "boot")
(executable-find "boot.sh"))
"boot"
"The command used to execute Boot."
:type 'string
:group 'cider
Expand Down Expand Up @@ -210,29 +209,30 @@ Sub-match 1 must be the project path.")
(interactive)
(message "CIDER %s" (cider--version)))

(defun cider-command-present-p (project-type)
"Check if the command matching PROJECT-TYPE is present."
(pcase project-type
("lein" 'cider--lein-present-p)
("boot" 'cider--boot-present-p)
("gradle" 'cider--gradle-present-p)
(_ (error "Unsupported project type `%s'" project-type))))

(defun cider-jack-in-command (project-type)
"Determine the command `cider-jack-in' needs to invoke for the PROJECT-TYPE."
(pcase project-type
("lein" cider-lein-command)
("boot" cider-boot-command)
("gradle" cider-gradle-command)
(_ (error "Unsupported project type `%s'" project-type))))
(_ (user-error "Unsupported project type `%s'" project-type))))

(defun cider-jack-in-resolve-command (project-type)
"Determine the resolved file path to `cider-jack-in-command' if it can be
found for the PROJECT-TYPE"
(pcase project-type
("lein" (cider--lein-resolve-command))
("boot" (cider--boot-resolve-command))
("gradle" (cider--gradle-resolve-command))
(_ (user-error "Unsupported project type `%s'" project-type))))

(defun cider-jack-in-params (project-type)
"Determine the commands params for `cider-jack-in' for the PROJECT-TYPE."
(pcase project-type
("lein" cider-lein-parameters)
("boot" cider-boot-parameters)
("gradle" cider-gradle-parameters)
(_ (error "Unsupported project type `%s'" project-type))))
(_ (user-error "Unsupported project type `%s'" project-type))))

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kill this blank line.


;;; Jack-in dependencies injection
Expand Down Expand Up @@ -472,30 +472,33 @@ If CLJS-TOO is non-nil, also start a ClojureScript REPL session with its
own buffer."
(interactive "P")
(setq cider-current-clojure-buffer (current-buffer))
(let ((project-type (cider-project-type)))
(if (funcall (cider-command-present-p project-type))
(let* ((project-type (cider-project-type))
(command (cider-jack-in-command project-type))
(command-resolved (cider-jack-in-resolve-command project-type))
(command-params (cider-jack-in-params project-type)))
(if command-resolved
(let* ((project (when prompt-project
(read-directory-name "Project: ")))
(project-dir (clojure-project-dir
(or project (cider-current-dir))))
(params (if prompt-project
(read-string (format "nREPL server command: %s "
(cider-jack-in-params project-type))
(cider-jack-in-params project-type))
(cider-jack-in-params project-type)))
command-params)
command-params)
command-params))
(params (if cider-inject-dependencies-at-jack-in
(cider-inject-jack-in-dependencies params project-type)
params))

(cmd (format "%s %s" (cider-jack-in-command project-type) params)))
(cmd (format "%s %s" command-resolved params)))
(when-let ((repl-buff (cider-find-reusable-repl-buffer nil project-dir)))
(let ((nrepl-create-client-buffer-function #'cider-repl-create)
(nrepl-use-this-as-repl-buffer repl-buff))
(nrepl-start-server-process
project-dir cmd
(when cljs-too #'cider-create-sibling-cljs-repl)))))
(message "The %s executable (specified by `cider-lein-command' or `cider-boot-command') isn't on your `exec-path'"
(cider-jack-in-command project-type)))))
command))))

;;;###autoload
(defun cider-jack-in-clojurescript (&optional prompt-project)
Expand Down Expand Up @@ -657,25 +660,26 @@ choose."
(car choices))
(t cider-default-repl-command))))


;; TODO: Implement a check for `cider-lein-command' over tramp
(defun cider--lein-present-p ()
"Check if `cider-lein-command' is on the `exec-path'.
(defun cider--lein-resolve-command ()
"Find `cider-lein-command' on `exec-path' if possible, or return `nil'.

In case `default-directory' is non-local we assume the command is available."
(or (file-remote-p default-directory)
(executable-find cider-lein-command)
(executable-find (concat cider-lein-command ".bat"))))

(defun cider--boot-present-p ()
"Check if `cider-boot-command' is on the `exec-path'.
(defun cider--boot-resolve-command ()
"Find `cider-boot-command' on `exec-path' if possible, or return `nil'.

In case `default-directory' is non-local we assume the command is available."
(or (file-remote-p default-directory)
(executable-find cider-boot-command)
(executable-find (concat cider-boot-command ".exe"))))

(defun cider--gradle-present-p ()
"Check if `cider-gradle-command' is on the `exec-path'.
(defun cider--gradle-resolve-command ()
"Find `cider-gradle-command' on `exec-path' if possible, or return `nil'.

In case `default-directory' is non-local we assume the command is available."
(or (file-remote-p default-directory)
Expand Down