Skip to content

[inspect] Add support for diff mode and sort-maps #3828

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 2 commits into from
Jun 30, 2025
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
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@
### New features

- [#3359](https://github.com/clojure-emacs/cider/pull/3359): Add customizable default connection params
- [#3828](https://github.com/clojure-emacs/cider/issues/3828): Inspector: diff mode.
- [#3828](https://github.com/clojure-emacs/cider/issues/3828): Inspector: sorting maps by keys.

### Changes

- Bump the injected `cider-nrepl` to [0.56.0](https://github.com/clojure-emacs/cider-nrepl/blob/master/CHANGELOG.md#0560-2025-05-29).
- Bump the injected `cider-nrepl` to [0.57.0](https://github.com/clojure-emacs/cider-nrepl/blob/master/CHANGELOG.md#0570-2025-06-29).
- [cider-nrepl#941](https://github.com/clojure-emacs/cider-nrepl/pull/941): Stop vendoring Fipp dependency.
- [cider-nrepl#943](https://github.com/clojure-emacs/cider-nrepl/pull/943): Reduce debugger instrumentation bytecode footprint.
- [orchard#342](https://github.com/clojure-emacs/orchard/pull/342): Inspector: add hexdump view mode.
- [orchard#349](https://github.com/clojure-emacs/orchard/pull/349): Inspector: add ability to sort maps by key.
- [orchard#350](https://github.com/clojure-emacs/orchard/pull/350): Inspector: add diff mode and `orchard.inspect/diff`.
- [#3816](https://github.com/clojure-emacs/cider/issues/3816): **(Breaking)** Remove enrich-classpath support from cider-jack-in.
- [#3817](https://github.com/clojure-emacs/cider/issues/3817): Enable `cider-download-java-sources` by default.

Expand Down
50 changes: 44 additions & 6 deletions cider-inspector.el
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,16 @@ The max depth can be also changed interactively within the inspector."
:type 'boolean
:package-version '(cider . "1.18.0"))

(defcustom cider-inspector-sort-maps nil
"When true, sort inspected maps by keys."
:type 'boolean
:package-version '(cider . "1.19.0"))

(defcustom cider-inspector-only-diff nil
"When true and inspecting a diff result, only display values that differ."
:type 'boolean
:package-version '(cider . "1.19.0"))

(defcustom cider-inspector-skip-uninteresting t
"Controls whether to skip over uninteresting values in the inspector.
Only applies to navigation with `cider-inspector-prev-inspectable-object'
Expand Down Expand Up @@ -147,6 +157,8 @@ Can be turned to nil once the user sees and acknowledges the feature."
(define-key map [(shift tab)] #'cider-inspector-previous-inspectable-object)
(define-key map "p" #'cider-inspector-previous-inspectable-object)
(define-key map "P" #'cider-inspector-toggle-pretty-print)
(define-key map "S" #'cider-inspector-toggle-sort-maps)
(define-key map "D" #'cider-inspector-toggle-only-diff)
(define-key map (kbd "C-c C-p") #'cider-inspector-print-current-value)
(define-key map ":" #'cider-inspect-expr-from-inspector)
(define-key map "f" #'forward-char)
Expand Down Expand Up @@ -185,6 +197,16 @@ Can be turned to nil once the user sees and acknowledges the feature."
(setq-local sesman-system 'CIDER)
(visual-line-mode 1))

(defun cider-inspector--highlight-diff-tags ()
"Apply face to #± using overlays.
We use overlays here because font-locking doesn't seem to work for this."
(save-excursion
(goto-char (point-min))
(while (search-forward "#±" nil t)
(let ((overlay (make-overlay (match-beginning 0) (match-end 0))))
(overlay-put overlay 'face 'font-lock-warning-face)
(overlay-put overlay 'priority 100)))))

;;;###autoload
(defun cider-inspect-last-sexp ()
"Inspect the result of the the expression preceding point."
Expand Down Expand Up @@ -354,9 +376,23 @@ MAX-NESTED-DEPTH is the new value."
(defun cider-inspector-toggle-pretty-print ()
"Toggle the pretty printing of values in the inspector."
(interactive)
(let ((result (cider-nrepl-send-sync-request `("op" "inspect-toggle-pretty-print"))))
(when (nrepl-dict-get result "value")
(cider-inspector--render-value result))))
(customize-set-variable 'cider-inspector-pretty-print (not cider-inspector-pretty-print))
(cider-inspector--refresh-with-opts
"pretty-print" (if cider-inspector-pretty-print "true" "false")))

(defun cider-inspector-toggle-sort-maps ()
"Toggle the sorting of maps in the inspector."
(interactive)
(customize-set-variable 'cider-inspector-sort-maps (not cider-inspector-sort-maps))
(cider-inspector--refresh-with-opts
"sort-maps" (if cider-inspector-sort-maps "true" "false")))

(defun cider-inspector-toggle-only-diff ()
"Toggle the display of only differing values when inspecting diff results."
(interactive)
(customize-set-variable 'cider-inspector-only-diff (not cider-inspector-only-diff))
(cider-inspector--refresh-with-opts
"only-diff" (if cider-inspector-only-diff "true" "false")))

(defun cider-inspector-toggle-view-mode ()
"Toggle the view mode of the inspector between normal and object view mode."
Expand Down Expand Up @@ -454,8 +490,9 @@ MAX-COLL-SIZE if non nil."
`("max-nested-depth" ,cider-inspector-max-nested-depth))
,@(when cider-inspector-display-analytics-hint
`("display-analytics-hint" "true"))
,@(when cider-inspector-pretty-print
`("pretty-print" "true"))))
"pretty-print" ,(if cider-inspector-pretty-print "true" "false")
"sort-maps" ,(if cider-inspector-sort-maps "true" "false")
"only-diff" ,(if cider-inspector-only-diff "true" "false")))
(cider-nrepl-send-sync-request)))

(declare-function cider-set-buffer-ns "cider-mode")
Expand Down Expand Up @@ -522,7 +559,8 @@ from stack), `:next-inspectable' (move point to next inspectable object)."
"Render ELEMENTS."
(setq cider-inspector-looking-at-java-p nil)
(dolist (el elements)
(cider-inspector-render-el* el)))
(cider-inspector-render-el* el))
(cider-inspector--highlight-diff-tags))

(defconst cider--inspector-java-headers
;; NOTE "--- Static fields:" "--- Instance fields:" are for objects,
Expand Down
2 changes: 1 addition & 1 deletion cider.el
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ the artifact.")

Used when `cider-jack-in-auto-inject-clojure' is set to `latest'.")

(defconst cider-required-middleware-version "0.56.0"
(defconst cider-required-middleware-version "0.57.0"
"The CIDER nREPL version that's known to work properly with CIDER.")

(defcustom cider-injected-middleware-version cider-required-middleware-version
Expand Down
2 changes: 1 addition & 1 deletion dev/docker-sample-project/project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
:dependencies [[org.clojure/clojure "1.11.1"]
[clj-http "3.12.3"]]
:source-paths ["src"]
:plugins [[cider/cider-nrepl "0.56.0"]])
:plugins [[cider/cider-nrepl "0.57.0"]])
2 changes: 1 addition & 1 deletion dev/tramp-sample-project/project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
:dependencies [[org.clojure/clojure "1.11.1"]
[clj-http "3.12.3"]]
:source-paths ["src"]
:plugins [[cider/cider-nrepl "0.56.0"]
:plugins [[cider/cider-nrepl "0.57.0"]
[refactor-nrepl "3.9.0"]])
10 changes: 5 additions & 5 deletions doc/modules/ROOT/pages/basics/middleware_setup.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ Use the convenient plugin for defaults, either in your project's

[source,clojure]
----
:plugins [[cider/cider-nrepl "0.56.0"]]
:plugins [[cider/cider-nrepl "0.57.0"]]
----

A minimal `profiles.clj` for CIDER would be:

[source,clojure]
----
{:repl {:plugins [[cider/cider-nrepl "0.56.0"]]}}
{:repl {:plugins [[cider/cider-nrepl "0.57.0"]]}}
----

WARNING: Be careful not to place this in the `:user` profile, as this way CIDER's
Expand All @@ -43,11 +43,11 @@ run `cider-connect` or `cider-connect-cljs`.

[source,clojure]
----
:cider-clj {:extra-deps {cider/cider-nrepl {:mvn/version "0.56.0"}}
:cider-clj {:extra-deps {cider/cider-nrepl {:mvn/version "0.57.0"}}
:main-opts ["-m" "nrepl.cmdline" "--middleware" "[cider.nrepl/cider-middleware]"]}

:cider-cljs {:extra-deps {org.clojure/clojurescript {:mvn/version "1.10.339"}
cider/cider-nrepl {:mvn/version "0.56.0"}
cider/cider-nrepl {:mvn/version "0.57.0"}
cider/piggieback {:mvn/version "0.6.0"}}
:main-opts ["-m" "nrepl.cmdline" "--middleware"
"[cider.nrepl/cider-middleware,cider.piggieback/wrap-cljs-repl]"]}
Expand All @@ -66,7 +66,7 @@ NOTE: Make sure you're using https://github.com/clojurephant/clojurephant[Clojur
----
dependencies {
devImplementation 'nrepl:nrepl:1.3.1'
devImplementation 'cider:cider-nrepl:0.56.0'
devImplementation 'cider:cider-nrepl:0.57.0'
}

tasks.named('clojureRepl') {
Expand Down
6 changes: 3 additions & 3 deletions doc/modules/ROOT/pages/basics/up_and_running.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ simple - CIDER passes the extra dependencies and nREPL configuration to
your build tool in the command it runs to start the nREPL server. Here's how
this looks for `tools.deps`:

$ clojure -Sdeps '{:deps {nrepl {:mvn/version "1.3.1"} cider/cider-nrepl {:mvn/version "0.56.0"}}}' -m nrepl.cmdline --middleware '["cider.nrepl/cider-middleware"]'
$ clojure -Sdeps '{:deps {nrepl {:mvn/version "1.3.1"} cider/cider-nrepl {:mvn/version "0.57.0"}}}' -m nrepl.cmdline --middleware '["cider.nrepl/cider-middleware"]'

TIP: If you don't want `cider-jack-in` to inject dependencies automatically, set
`cider-inject-dependencies-at-jack-in` to `nil`. Note that you'll have to setup
Expand Down Expand Up @@ -332,7 +332,7 @@ It is also possible for plain `clj`, although the command is somewhat longer:

[source,sh]
----
$ clj -Sdeps '{:deps {cider/cider-nrepl {:mvn/version "0.56.0"}}}' -m nrepl.cmdline --middleware "[cider.nrepl/cider-middleware]"
$ clj -Sdeps '{:deps {cider/cider-nrepl {:mvn/version "0.57.0"}}}' -m nrepl.cmdline --middleware "[cider.nrepl/cider-middleware]"
----

Alternatively, you can start nREPL either manually or using the facilities
Expand Down Expand Up @@ -466,7 +466,7 @@ The command tunnels as well the remote port 12345 to local machine on port 12345
----
ssh -t -L 12345:localhost:12345 MY_REMOTE_SERVER \
devcontainer exec --workspace-folder /home/me/my-clj-code \
"clojure -Sdeps '{:deps {nrepl/nrepl {:mvn/version \"1.3.1\"} cider/cider-nrepl {:mvn/version \"0.56.0\"}}}' -m nrepl.cmdline -p 12345 -b 0.0.0.0 --middleware '[\"cider.nrepl/cider-middleware\"]' "
"clojure -Sdeps '{:deps {nrepl/nrepl {:mvn/version \"1.3.1\"} cider/cider-nrepl {:mvn/version \"0.57.0\"}}}' -m nrepl.cmdline -p 12345 -b 0.0.0.0 --middleware '[\"cider.nrepl/cider-middleware\"]' "
----

For this to work, we need as well to configure `devcontainer.json` with a snippet that exposes port `12345` from the container to the (remote) host:
Expand Down
2 changes: 1 addition & 1 deletion doc/modules/ROOT/pages/cljs/shadow-cljs.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ And connect to it with `cider-connect`.
...For that to work, `shadow-cljs.edn` contents like the following are assumed:

```clj
:dependencies [[cider/cider-nrepl "0.56.0"] ;; mandatory (unless it's inherited from deps.edn or otherwise present in the classpath of shadow-cljs's JVM process)
:dependencies [[cider/cider-nrepl "0.57.0"] ;; mandatory (unless it's inherited from deps.edn or otherwise present in the classpath of shadow-cljs's JVM process)
[refactor-nrepl/refactor-nrepl "3.9.0"]] ;; refactor-nrepl is optional

:nrepl {:middleware [cider.nrepl/cider-middleware ;; it's advisable to explicitly add this middleware. It's automatically added by shadow-cljs (if available in the classpath), unless `:nrepl {:cider false}`
Expand Down
2 changes: 1 addition & 1 deletion doc/modules/ROOT/pages/cljs/up_and_running.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ or in `build.gradle`:
----
dependencies {
devImplementation 'nrepl:nrepl:1.3.1'
devImplementation 'cider:cider-nrepl:0.56.0'
devImplementation 'cider:cider-nrepl:0.57.0'
devImplementation 'cider:cider-piggieback:0.5.3'
}

Expand Down
8 changes: 8 additions & 0 deletions doc/modules/ROOT/pages/debugging/inspector.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ You'll have access to additional keybindings in the inspector buffer
| `cider-inspector-toggle-pretty-print`
| Toggle the pretty printing of values in the inspector. You can set the `cider-inspector-pretty-print` customization option to `t`, if you always want values to be be pretty printed.

| kbd:[S]
| `cider-inspector-toggle-sort-maps`
| Toggle the sorting of maps by key in the inspector. You can set the `cider-inspector-sort-maps` customization option to `t` if you always want maps to be displayed sorted.

| kbd:[D]
| `cider-inspector-toggle-only-diff`
| When inspecting a diff result, toggle only displaying the differing values. You can set the `cider-inspector-only-diff` customization option to `t` if you always want to only show the diff instead of all values.

| kbd:[d]
| `cider-inspector-def-current-val`
| Defines a var in the REPL namespace with current inspector value. If you tend to always choose the same name(s), you may want to set the `cider-inspector-preferred-var-names` customization option.
Expand Down
Loading