Skip to content

Commit 388133c

Browse files
vspinubbatsov
authored andcommitted
Better connection types retrival
- new function `cider-project-connections-types` - `cider-connection-type-for-buffer` returns "multi" in cljc an cljx
1 parent b185f75 commit 388133c

File tree

5 files changed

+25
-10
lines changed

5 files changed

+25
-10
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
* [#1991](https://github.com/clojure-emacs/cider/issues/1832): Make it possible to disable the prompt to open a ClojureScript in a browser on connect via `cider-offer-to-open-cljs-app-in-browser`.
3030
* [#1995](https://github.com/clojure-emacs/cider/pull/1995): Add new customization variable `cider-doc-auto-select-buffer` to control cider-doc popup buffer auto selection.
3131
* Ensure that `cider-switch-to-repl-buffer` picks the most recent repl buffer if multiple connections are available.
32+
* Add new function `cider-project-connections-types`.
3233

3334
### Changes
3435

@@ -43,6 +44,7 @@
4344

4445
### Bugs Fixed
4546

47+
* [#2040](https://github.com/clojure-emacs/cider/issues/2040): Fix fontification of conditional expressions in cljc files.
4648
* [#2018](https://github.com/clojure-emacs/cider/issues/2018): Don't delete wrong overlays during code evaluation.
4749
* [#1699](https://github.com/clojure-emacs/cider/issues/1699): Fix "Method code too large!" error that occurred during instrumentation for debugging.
4850
* [#1987](https://github.com/clojure-emacs/cider/issues/1987): Fix: Update faces when disabling a theme

cider-client.el

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ Also close associated REPL and server buffers."
137137

138138

139139
;;; Current connection logic
140-
(defvar-local cider-repl-type "clj"
140+
(defvar-local cider-repl-type nil
141141
"The type of this REPL buffer, usually either \"clj\" or \"cljs\".")
142142

143143
(defun cider-find-connection-buffer-for-project-directory (&optional project-directory all-connections)
@@ -178,6 +178,23 @@ connections are returned, instead of just the most recent."
178178
cider-connections
179179
(car cider-connections)))))
180180

181+
(defun cider-connection-type-for-buffer ()
182+
"Return the matching connection type (clj or cljs) for the current buffer.
183+
In cljc and cljx buffers return \"multi\". This function infers connection
184+
type based on the major mode. See `cider-project-connections-types' for a
185+
list of types of actual connections within a project."
186+
(cond
187+
((derived-mode-p 'clojurescript-mode) "cljs")
188+
((derived-mode-p 'clojurec-mode) "multi")
189+
((derived-mode-p 'clojurex-mode) "multi")
190+
((derived-mode-p 'clojure-mode) "clj")
191+
(cider-repl-type)))
192+
193+
(defun cider-project-connections-types ()
194+
"Return a list of types of connections within current project."
195+
(let ((connections (cider-find-connection-buffer-for-project-directory nil :all-connections)))
196+
(seq-uniq (seq-map #'cider--connection-type connections))))
197+
181198
(defun cider-read-connection (prompt)
182199
"Completing read for connections using PROMPT."
183200
(get-buffer (completing-read prompt (mapcar #'buffer-name (cider-connections)))))
@@ -221,14 +238,6 @@ such a link cannot be established automatically."
221238
(cider-ensure-connected)
222239
(kill-local-variable 'cider-connections))
223240

224-
(defun cider-connection-type-for-buffer ()
225-
"Return the matching connection type (clj or cljs) for the current buffer."
226-
(cond
227-
((derived-mode-p 'clojurescript-mode) "cljs")
228-
((derived-mode-p 'clojure-mode) "clj")
229-
(cider-repl-type)
230-
(t "clj")))
231-
232241
(defun cider-toggle-request-dispatch ()
233242
"Toggle the value of `cider-request-dispatch' between static and dynamic.
234243

cider-repl.el

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,8 @@ ENDPOINT is a plist as returned by `nrepl-connect'."
247247
(rename-buffer buff-name)))
248248
(with-current-buffer (get-buffer-create buff-name)
249249
(unless (derived-mode-p 'cider-repl-mode)
250-
(cider-repl-mode))
250+
(cider-repl-mode)
251+
(setq cider-repl-type "clj"))
251252
(setq nrepl-err-handler #'cider-default-err-handler)
252253
(cider-repl-reset-markers)
253254
(add-hook 'nrepl-response-handler-functions #'cider-repl--state-handler nil 'local)

cider.el

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,7 @@ should be the regular Clojure REPL started by the server process filter."
546546
;; original Clojure REPL. Our solution is to bump the original REPL back
547547
;; up the list, so it takes priority on Clojure requests.
548548
(cider-make-connection-default client-buffer)
549+
(setq cider-repl-type "cljs")
549550
(pcase (assoc cljs-repl-form cider--cljs-repl-types)
550551
(`(,_ ,name ,info)
551552
(message "Starting a %s REPL%s" name (or info "")))

test/cider-tests.el

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,12 @@
4343
(let ((b1 (current-buffer)))
4444
(setq-local nrepl-endpoint '("localhost" 4005))
4545
(setq-local nrepl-project-dir "proj")
46+
(setq-local cider-repl-type "clj")
4647
(with-temp-buffer
4748
(rename-buffer "*cider-repl test2*")
4849
(let ((b2 (current-buffer)))
4950
(setq-local nrepl-endpoint '("123.123.123.123" 4006))
51+
(setq-local cider-repl-type "clj")
5052
(let ((cider-connections (list b1 b2)))
5153
(cider-connection-browser)
5254
(with-current-buffer "*cider-connections*"

0 commit comments

Comments
 (0)