Skip to content

Reify cider-cljs-pending separate from repl-type #3291

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

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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
### Changes

- Bump the injected nREPL version to 1.0.
- [#3291](https://github.com/clojure-emacs/cider/pull/3291): **Remove** the `'cljs-pending` `repl-type`. It is replaced by `cider-repl-cljs-upgrade-pending`.

### Bugs fixed

Expand Down
22 changes: 16 additions & 6 deletions cider-connection.el
Original file line number Diff line number Diff line change
Expand Up @@ -315,11 +315,11 @@ See `cider-connection-capabilities'."
(_ '()))
(when
(or
(member cider-repl-type '(cljs pending-cljs))
(eq cider-repl-type 'cljs)
;; This check is currently basically for nbb.
;; See `cider-sync-tooling-eval', but it is defined on a higher layer
(nrepl-dict-get
(nrepl-sync-request:eval "cljs.core/demunge" (current-buffer) (cider-current-ns) 'tooling)
(nrepl-sync-request:eval "cljs.core/demunge" (current-buffer) nil 'tooling)
"value"))
'(cljs))))))

Expand Down Expand Up @@ -762,10 +762,17 @@ Session name can be customized with `cider-session-name-template'."
(defvar-local cider-repl-type nil
"The type of this REPL buffer, usually either clj or cljs.")

(defvar-local cider-repl-cljs-upgrade-pending nil
"Is the cljs repl currently pending?")

(defun cider-repl-type (repl-buffer)
"Get REPL-BUFFER's type."
(buffer-local-value 'cider-repl-type repl-buffer))

(defun cider-cljs-pending-p (repl-buffer)
"Returns non nil when REPL-BUFFER is currently a pending cljs repl."
(buffer-local-value 'cider-repl-cljs-upgrade-pending repl-buffer))

(defun cider-repl-type-for-buffer (&optional buffer)
"Return the matching connection type (clj or cljs) for BUFFER.
BUFFER defaults to the `current-buffer'. In cljc buffers return
Expand Down Expand Up @@ -812,13 +819,13 @@ PARAMS is a plist as received by `cider-repl-create'."
(let* ((proj-dir (plist-get params :project-dir))
(host (plist-get params :host))
(port (plist-get params :port))
(cljsp (member (plist-get params :repl-type) '(cljs pending-cljs)))
(cljsp (member (plist-get params :repl-type) '(cljs)))
(scored-repls
(delq nil
(mapcar (lambda (b)
(let ((bparams (cider--gather-connect-params nil b)))
(when (eq cljsp (member (plist-get bparams :repl-type)
'(cljs pending-cljs)))
'(cljs)))
(cons (buffer-name b)
(+
(if (equal proj-dir (plist-get bparams :project-dir)) 8 0)
Expand Down Expand Up @@ -866,8 +873,9 @@ function with the repl buffer set as current."
mode-name nil
cider-session-name ses-name
nrepl-project-dir (plist-get params :project-dir)
;; REPLs start with clj and then "upgrade" to a different type
;; Cljs repls are pending until they are upgraded. See cider-repl--state-handler
cider-repl-type (plist-get params :repl-type)
cider-repl-cljs-upgrade-pending (plist-get params :cider-repl-cljs-upgrade-pending)
;; ran at the end of cider--connected-handler
cider-repl-init-function (plist-get params :repl-init-function)
cider-launch-params params)
Expand Down Expand Up @@ -985,7 +993,9 @@ throw an error if no linked session exists."
(sesman-ensure-session 'CIDER)
(sesman-current-session 'CIDER)))))))
(or (seq-filter (lambda (b)
(cider--match-repl-type type b))
(unless
(cider-cljs-pending-p b)
(cider--match-repl-type type b)))
repls)
(when ensure
(cider--no-repls-user-error type)))))
Expand Down
2 changes: 2 additions & 0 deletions cider-repl.el
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ This cache is stored in the connection buffer.")
(nrepl-dbind-response response (repl-type changed-namespaces)
(when (and repl-type cider-repl-auto-detect-type)
(cider-set-repl-type repl-type))
(when (eq (cider-maybe-intern repl-type) 'cljs)
Copy link
Member

Choose a reason for hiding this comment

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

Ah, if that's a string than the comparison should be (string= repl-type "cljs"). I just saw 'cljs was a symbol and I assumed that repl-type was a symbol as well.

(setq cider-repl-cljs-upgrade-pending nil))
(unless (nrepl-dict-empty-p changed-namespaces)
(setq cider-repl-ns-cache (nrepl-dict-merge cider-repl-ns-cache changed-namespaces))
(dolist (b (buffer-list))
Expand Down
6 changes: 4 additions & 2 deletions cider.el
Original file line number Diff line number Diff line change
Expand Up @@ -1258,7 +1258,8 @@ server buffer, in which case a new session for that server is created."
(cider--update-cljs-type)
(cider--update-cljs-init-function)
(plist-put :session-name ses-name)
(plist-put :repl-type 'pending-cljs)))))
(plist-put :repl-type 'cljs)
(plist-put :cider-repl-cljs-upgrade-pending t)))))

;;;###autoload
(defun cider-connect-clj (&optional params)
Expand Down Expand Up @@ -1292,7 +1293,8 @@ parameters regardless of their supplied or default values."
(cider--update-cljs-type)
(cider--update-cljs-init-function)
(plist-put :session-name nil)
(plist-put :repl-type 'pending-cljs))))
(plist-put :repl-type 'cljs)
(plist-put :cider-repl-cljs-upgrade-pending t))))

;;;###autoload
(defun cider-connect-clj&cljs (params &optional soft-cljs-start)
Expand Down