Skip to content

Commit f11383b

Browse files
committed
Use namespaced middleware ops; tidy two request params
Three improvements found while auditing the middleware request/response shapes: - Use refactor-nrepl's namespaced op names (refactor/find-symbol, etc.) instead of the bare ones. refactor-nrepl registers every op under both forms, treats the namespaced one as canonical, and plans to drop the bare names; namespacing also avoids op-name collisions with other middleware. Prefixing is centralized in cljr--create-msg and cljr--op-supported-p (plus the one inline extract-definition request). Requires refactor-nrepl 3.13.0+; the injected version is now 3.14.0. - Send an explicit "false" for ignore-errors when cljr-ignore-analyzer-errors is nil, instead of a nil value that nREPL drops (leaving the middleware on its lenient default). The strict behavior the option documents now actually takes effect. - Drop the obsolete language-context param from the suggest-libspecs request; refactor-nrepl has read buffer-language-context / input-language-context since 3.7.0. Validated live against refactor-nrepl 3.14.0: op-support, version, rename, clean-ns and suggest-libspecs all work under the namespaced ops.
1 parent 9bdd019 commit f11383b

3 files changed

Lines changed: 29 additions & 10 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Unreleased
44

5+
- **(Breaking)** Use refactor-nrepl's namespaced op names (`refactor/find-symbol`, `refactor/clean-ns`, …) instead of the bare ones. refactor-nrepl treats the namespaced forms as canonical and plans to drop the bare names, and namespacing avoids op-name collisions with other middleware. This requires refactor-nrepl 3.13.0+ (the injected version is now 3.14.0).
6+
- `cljr-rename-symbol`, `cljr-find-usages`, `cljr-inline-symbol` and `cljr-change-function-signature` now send an explicit `ignore-errors` value that matches `cljr-ignore-analyzer-errors`, instead of a nil value that was dropped on the wire. With the default (nil) this means the strict behavior the option documents actually takes effect - a project with an unanalyzable namespace now surfaces a warning rather than silently skipping it.
7+
- `cljr-slash` no longer sends the obsolete `language-context` parameter to the `suggest-libspecs` op (superseded by `buffer-language-context`/`input-language-context` in refactor-nrepl 3.7.0).
8+
59
- The asynchronous refactorings (`cljr-rename-symbol`, `cljr-change-function-signature`, `cljr-rename-file-or-dir`) now show a mode-line spinner while the middleware is working, so it's clear the operation is still running. Uses CIDER's spinner, so it honors `cider-show-spinner` and friends.
610

711
- `cljr-rename-symbol` and `cljr-change-function-signature` now find their occurrences asynchronously. Locating every occurrence analyses the whole project, which on a cold cache or a large project could freeze Emacs for a long time; now the command returns immediately and the rename (or the change-signature edit buffer) happens once the search finishes, so Emacs stays responsive meanwhile. As a side effect they now also honor `cljr-middleware-ignored-paths`.

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ clj-refactor | refactor-nrepl | CIDER | Clojure | Java |
7474
2.4.0 | 2.4.0 | 0.17, 0.18 | 1.7+ | 8+ |
7575
2.5.0 | 2.5.0 | 0.24 | 1.8+ | 8+ |
7676
3.0.0+ | 3.0.0+ | 1.0 | 1.9+ | 11+ |
77-
4.0.0+ | 3.x | 1.11+ | 1.10+ | 8+ |
77+
4.0.0+ | 3.13.0+ | 1.11+ | 1.10+ | 8+ |
7878

7979
clj-refactor 4.0.0+ requires Emacs 28.1 or newer.
8080

‎clj-refactor.el‎

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -997,14 +997,28 @@ if the point is currently placed at the opening parentheses of an anonymous func
997997
v)
998998
v))))
999999

1000+
(defconst cljr--middleware-op-prefix "refactor/"
1001+
"Namespace prefix for refactor-nrepl's op names.
1002+
refactor-nrepl registers every op under both its bare name (e.g.
1003+
`clean-ns') and this namespaced form (e.g. `refactor/clean-ns'), and
1004+
treats the namespaced form as canonical - the bare names are slated for
1005+
removal in a future refactor-nrepl major release. We use the namespaced
1006+
form (available since refactor-nrepl 3.13.0) so op names can't collide
1007+
with those of other middleware.")
1008+
1009+
(defun cljr--middleware-op (op)
1010+
"Return refactor-nrepl op OP as its canonical namespaced name."
1011+
(concat cljr--middleware-op-prefix op))
1012+
10001013
(defun cljr--create-msg (op &rest kvs)
10011014
"Create a msg for the middleware for OP and optionally include the kv pairs KVS.
10021015
1003-
All config settings are included in the created msg."
1016+
OP is given as its bare refactor-nrepl name and is namespaced here (see
1017+
`cljr--middleware-op'). All config settings are included in the created msg."
10041018
(cl-assert (cl-evenp (length kvs)) nil "Can't create msg to send to the middleware.\
10051019
Received an uneven number of kv pairs: %s " kvs)
10061020
(apply #'list
1007-
"op" op
1021+
"op" (cljr--middleware-op op)
10081022

10091023
"prefix-rewriting"
10101024
(if cljr-favor-prefix-notation
@@ -1230,13 +1244,15 @@ See: https://github.com/clojure-emacs/clj-refactor.el/wiki/cljr-rename-file-or-d
12301244
(cljr-rename-file-or-dir (buffer-file-name) new-path))
12311245

12321246
(defun cljr--op-supported-p (op)
1233-
"Is the OP we require provided by the current middleware stack?"
1247+
"Is the refactor-nrepl OP (bare name) provided by the current middleware?
1248+
OP is namespaced (see `cljr--middleware-op') so this checks for the
1249+
canonical op, matching what `cljr--create-msg' actually sends."
12341250
;; Guard on the connection first: `cider-nrepl-op-supported-p' resolves the
12351251
;; REPL with the `ensure' flag and signals `No linked CIDER sessions' when
12361252
;; nothing is connected. We want a plain nil there, so the offline fallbacks
12371253
;; that gate on this predicate (`cljr-slash', `cljr-clean-ns', ...) can kick in.
12381254
(and (cider-connected-p)
1239-
(cider-nrepl-op-supported-p op)))
1255+
(cider-nrepl-op-supported-p (cljr--middleware-op op))))
12401256

12411257
(defun cljr--assert-middleware ()
12421258
(unless (featurep 'cider)
@@ -2229,7 +2245,6 @@ Results are cached per alias and language context (see
22292245
(thread-first "cljr-suggest-libspecs"
22302246
cljr--ensure-op-supported
22312247
(cljr--create-msg "lib-prefix" alias-ref
2232-
"language-context" buffer-context
22332248
"buffer-language-context" buffer-context
22342249
"input-language-context" (or point-context buffer-context)
22352250
"preferred-aliases" (let ((print-length nil) ;; prevent large lists from being serialized with `...`, which would cause issues
@@ -3030,7 +3045,7 @@ See: https://github.com/clojure-emacs/clj-refactor.el/wiki/cljr-promote-function
30303045
"name" symbol
30313046
"ignore-paths" cljr-middleware-ignored-paths
30323047
"ignore-errors"
3033-
(when cljr-ignore-analyzer-errors "true"))))
3048+
(if cljr-ignore-analyzer-errors "true" "false"))))
30343049
(with-current-buffer (cider-current-repl)
30353050
(setq cljr--occurrence-count 0)
30363051
(setq cljr--num-syms -1)
@@ -3874,15 +3889,15 @@ See: https://github.com/clojure-emacs/clj-refactor.el/wiki/cljr-inline-symbol"
38743889
(ns (or (nrepl-dict-get var-info "ns") (cider-current-ns)))
38753890
(symbol-name (or (nrepl-dict-get var-info "name") symbol))
38763891
(extract-definition-request (list
3877-
"op" "extract-definition"
3892+
"op" (cljr--middleware-op "extract-definition")
38783893
"ns" ns
38793894
"dir" dir
38803895
"file" filename
38813896
"line" line
38823897
"column" column
38833898
"name" symbol-name
38843899
"ignore-errors"
3885-
(when cljr-ignore-analyzer-errors "true")))
3900+
(if cljr-ignore-analyzer-errors "true" "false")))
38863901
(response (parseedn-read-str (cljr--call-middleware-sync
38873902
extract-definition-request "definition")))
38883903
(definition (gethash :definition response))
@@ -3914,7 +3929,7 @@ See: https://github.com/clojure-emacs/clj-refactor.el/wiki/cljr-inline-symbol"
39143929
;; We used to derive the version out of `(cljr--version)`,
39153930
;; but now prefer a fixed version to fully decouple things and prevent unforeseen behavior.
39163931
;; This suits better our current pace of development.
3917-
(defcustom cljr-injected-middleware-version "3.11.0"
3932+
(defcustom cljr-injected-middleware-version "3.14.0"
39183933
"The refactor-nrepl version to be injected.
39193934
39203935
You can customize this in order to try out new releases.

0 commit comments

Comments
 (0)