Skip to content

Commit

Permalink
Make the track-state middleware invokeable directly (#799)
Browse files Browse the repository at this point in the history
  • Loading branch information
vemv authored Aug 9, 2023
1 parent 233bbec commit 6b0823e
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 38 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

## master (unreleased)

### New features

* Make the `track-state` middleware invokeable directly, by requesting the new `"cider/get-state"` op.
* This makes it possible to access `:changed-namespaces` info on demand, which can be necessary for:
* non-Piggieback based clojurescript repls
* re-computing the ns info responding to external (non-nREPL triggered) events.

### Changes

* [#796](https://github.com/clojure-emacs/cider-nrepl/issues/796): `fn-refs` and `fn-deps` middleware: add new `:file-url` field.
* these are absolute and prefixed by `file:` or `file:jar:`, whenever possible.
* `fn-refs` and `fn-deps` middleware: sort the results by file, line and column.
Expand Down
60 changes: 30 additions & 30 deletions doc/modules/ROOT/pages/nrepl-api/ops.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -1255,20 +1255,6 @@ Returns::



=== `track-state-middleware`



Required parameters::
{blank}

Optional parameters::
{blank}

Returns::
{blank}


=== `undef`

Undefine a symbol
Expand Down Expand Up @@ -1302,7 +1288,21 @@ Returns::



=== `log-add-appender`
=== `cider/get-state`



Required parameters::
{blank}

Optional parameters::
{blank}

Returns::
{blank}


=== `cider/log-add-appender`

Add an appender to a log framework.

Expand All @@ -1324,7 +1324,7 @@ Returns::



=== `log-add-consumer`
=== `cider/log-add-consumer`

Add a consumer to an appender of a log framework.

Expand All @@ -1343,7 +1343,7 @@ Returns::



=== `log-analyze-stacktrace`
=== `cider/log-analyze-stacktrace`

Analyze the stacktrace of a log event.

Expand All @@ -1361,7 +1361,7 @@ Returns::



=== `log-clear-appender`
=== `cider/log-clear-appender`

Clear all events of a log appender.

Expand All @@ -1379,7 +1379,7 @@ Returns::



=== `log-exceptions`
=== `cider/log-exceptions`

Return the exceptions and their frequencies for the given framework and appender.

Expand All @@ -1397,7 +1397,7 @@ Returns::



=== `log-format-event`
=== `cider/log-format-event`

Format a log event.

Expand All @@ -1422,7 +1422,7 @@ Returns::



=== `log-frameworks`
=== `cider/log-frameworks`

Return the available log frameworks.

Expand All @@ -1438,7 +1438,7 @@ Returns::



=== `log-inspect-event`
=== `cider/log-inspect-event`

Inspect a log event.

Expand All @@ -1457,7 +1457,7 @@ Returns::



=== `log-levels`
=== `cider/log-levels`

Return the log levels and their frequencies for the given framework and appender.

Expand All @@ -1475,7 +1475,7 @@ Returns::



=== `log-loggers`
=== `cider/log-loggers`

Return the loggers and their frequencies for the given framework and appender.

Expand All @@ -1493,7 +1493,7 @@ Returns::



=== `log-remove-appender`
=== `cider/log-remove-appender`

Remove an appender from a log framework.

Expand All @@ -1511,7 +1511,7 @@ Returns::



=== `log-remove-consumer`
=== `cider/log-remove-consumer`

Remove a consumer from the appender of a log framework.

Expand All @@ -1530,7 +1530,7 @@ Returns::



=== `log-search`
=== `cider/log-search`

Search the log events of an appender.

Expand All @@ -1550,7 +1550,7 @@ Returns::



=== `log-threads`
=== `cider/log-threads`

Return the threads and their frequencies for the given framework and appender.

Expand All @@ -1568,7 +1568,7 @@ Returns::



=== `log-update-appender`
=== `cider/log-update-appender`

Update the appender of a log framework.

Expand All @@ -1589,7 +1589,7 @@ Returns::



=== `log-update-consumer`
=== `cider/log-update-consumer`

Update the consumer of a log appender.

Expand Down
8 changes: 7 additions & 1 deletion maint/cider/nrepl/impl/docs.clj
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ use in e.g. wiki pages, github, etc."
(format "* `%s` %s\n" (pr-str k) (adoc-escape v))))
"{blank}"))

(defn op-name [op]
(let [op-ns (namespace op)
op-name (name op)]
(cond->> op-name
op-ns (str op-ns "/"))))

(defn- describe-adoc
"Given a message containing the response to a verbose :describe message,
generates a asciidoc string conveying the information therein, suitable for
Expand All @@ -105,7 +111,7 @@ use in e.g. wiki pages, github, etc."
(:version-string version/version)
")#\n\n== Operations"
(for [[op {:keys [doc optional requires returns]}] (sort (relevant-ops ops))]
(str "\n\n=== `" (name op) "`\n\n"
(str "\n\n=== `" (op-name op) "`\n\n"
(adoc-escape doc) "\n\n"
"Required parameters::\n"
(message-slot-adoc (sort requires))
Expand Down
10 changes: 5 additions & 5 deletions src/cider/nrepl.clj
Original file line number Diff line number Diff line change
Expand Up @@ -660,13 +660,13 @@ stack frame of the most recent exception. This op is deprecated, please use the
(def-wrapper wrap-tracker cider.nrepl.middleware.track-state/handle-tracker
ops-that-can-eval
(cljs/expects-piggieback
{:doc "Enhances the `eval` op by notifying the client of the current REPL
state. Currently, only the REPL type (Clojure or ClojureScript) is
informed."
{:doc "Under its normal operation mode, enhances the `eval` op by notifying the client of the current REPL state.
You can also request to compute the info directly by requesting the \"cider/get-state\" op."
:requires #{#'session}
:expects ops-that-can-eval
:handles {"track-state-middleware" ;; <- not handled !?
{}}}))
:handles {"cider/get-state" {}}
:returns {"repl-type" "`:clj` or `:cljs`."
"changed-namespaces" "A map of namespaces to `{:aliases ,,, :interns ,,,}`"}}))

(def-wrapper wrap-undef cider.nrepl.middleware.undef/handle-undef
{:doc "Middleware to undefine a symbol in a namespace."
Expand Down
10 changes: 8 additions & 2 deletions src/cider/nrepl/middleware/track_state.clj
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,13 @@
#{"eval" "load-file" "refresh" "refresh-all" "refresh-clear"
"toggle-trace-var" "toggle-trace-ns" "undef"})

(defn handle-tracker [handler msg]
(if (ops-that-can-eval (:op msg))
(defn handle-tracker [handler {:keys [op session] :as msg}]
(cond
(= "cider/get-state" op)
(send ns-cache update-in [session] update-and-send-cache msg)

(ops-that-can-eval op)
(handler (assoc msg :transport (make-transport msg)))

:else
(handler msg)))

0 comments on commit 6b0823e

Please sign in to comment.