From cf0455c7a253490a635a331222fa8997dabaa394 Mon Sep 17 00:00:00 2001 From: vemv Date: Mon, 7 Aug 2023 12:48:39 +0200 Subject: [PATCH 1/2] Make the `track-state` middleware invokeable directly Related: https://github.com/clojure-emacs/cider/issues/3393 --- CHANGELOG.md | 9 ++++ doc/modules/ROOT/pages/nrepl-api/ops.adoc | 60 +++++++++++----------- maint/cider/nrepl/impl/docs.clj | 8 ++- src/cider/nrepl.clj | 10 ++-- src/cider/nrepl/middleware/track_state.clj | 10 +++- 5 files changed, 59 insertions(+), 38 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d2bc479..f6d0f51c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,15 @@ ## master (unreleased) +### New features + +* Make the `track-state` middleware invokeable directly, by requesting the new `"cider/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. diff --git a/doc/modules/ROOT/pages/nrepl-api/ops.adoc b/doc/modules/ROOT/pages/nrepl-api/ops.adoc index a8d9190b..6c303614 100644 --- a/doc/modules/ROOT/pages/nrepl-api/ops.adoc +++ b/doc/modules/ROOT/pages/nrepl-api/ops.adoc @@ -1255,20 +1255,6 @@ Returns:: -=== `track-state-middleware` - - - -Required parameters:: -{blank} - -Optional parameters:: -{blank} - -Returns:: -{blank} - - === `undef` Undefine a symbol @@ -1302,7 +1288,7 @@ Returns:: -=== `log-add-appender` +=== `cider/log-add-appender` Add an appender to a log framework. @@ -1324,7 +1310,7 @@ Returns:: -=== `log-add-consumer` +=== `cider/log-add-consumer` Add a consumer to an appender of a log framework. @@ -1343,7 +1329,7 @@ Returns:: -=== `log-analyze-stacktrace` +=== `cider/log-analyze-stacktrace` Analyze the stacktrace of a log event. @@ -1361,7 +1347,7 @@ Returns:: -=== `log-clear-appender` +=== `cider/log-clear-appender` Clear all events of a log appender. @@ -1379,7 +1365,7 @@ Returns:: -=== `log-exceptions` +=== `cider/log-exceptions` Return the exceptions and their frequencies for the given framework and appender. @@ -1397,7 +1383,7 @@ Returns:: -=== `log-format-event` +=== `cider/log-format-event` Format a log event. @@ -1422,7 +1408,7 @@ Returns:: -=== `log-frameworks` +=== `cider/log-frameworks` Return the available log frameworks. @@ -1438,7 +1424,7 @@ Returns:: -=== `log-inspect-event` +=== `cider/log-inspect-event` Inspect a log event. @@ -1457,7 +1443,7 @@ Returns:: -=== `log-levels` +=== `cider/log-levels` Return the log levels and their frequencies for the given framework and appender. @@ -1475,7 +1461,7 @@ Returns:: -=== `log-loggers` +=== `cider/log-loggers` Return the loggers and their frequencies for the given framework and appender. @@ -1493,7 +1479,7 @@ Returns:: -=== `log-remove-appender` +=== `cider/log-remove-appender` Remove an appender from a log framework. @@ -1511,7 +1497,7 @@ Returns:: -=== `log-remove-consumer` +=== `cider/log-remove-consumer` Remove a consumer from the appender of a log framework. @@ -1530,7 +1516,7 @@ Returns:: -=== `log-search` +=== `cider/log-search` Search the log events of an appender. @@ -1550,7 +1536,7 @@ Returns:: -=== `log-threads` +=== `cider/log-threads` Return the threads and their frequencies for the given framework and appender. @@ -1568,7 +1554,7 @@ Returns:: -=== `log-update-appender` +=== `cider/log-update-appender` Update the appender of a log framework. @@ -1589,7 +1575,7 @@ Returns:: -=== `log-update-consumer` +=== `cider/log-update-consumer` Update the consumer of a log appender. @@ -1607,3 +1593,17 @@ Returns:: * `:status` done * `:cider/log-update-consumer` The consumer that was updated. + + +=== `cider/state` + + + +Required parameters:: +{blank} + +Optional parameters:: +{blank} + +Returns:: +{blank} diff --git a/maint/cider/nrepl/impl/docs.clj b/maint/cider/nrepl/impl/docs.clj index 70cc5238..a9632058 100644 --- a/maint/cider/nrepl/impl/docs.clj +++ b/maint/cider/nrepl/impl/docs.clj @@ -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 @@ -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)) diff --git a/src/cider/nrepl.clj b/src/cider/nrepl.clj index 93c3db7c..7b7b1318 100644 --- a/src/cider/nrepl.clj +++ b/src/cider/nrepl.clj @@ -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/state\" op." :requires #{#'session} :expects ops-that-can-eval - :handles {"track-state-middleware" ;; <- not handled !? - {}}})) + :handles {"cider/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." diff --git a/src/cider/nrepl/middleware/track_state.clj b/src/cider/nrepl/middleware/track_state.clj index e3f91a26..f9df55e3 100644 --- a/src/cider/nrepl/middleware/track_state.clj +++ b/src/cider/nrepl/middleware/track_state.clj @@ -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/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))) From 5721ea208b931bfea9b6389c3686db0c10dfd61c Mon Sep 17 00:00:00 2001 From: vemv Date: Wed, 9 Aug 2023 11:02:42 +0200 Subject: [PATCH 2/2] Name it `get-state` instead --- CHANGELOG.md | 2 +- doc/modules/ROOT/pages/nrepl-api/ops.adoc | 28 +++++++++++----------- src/cider/nrepl.clj | 4 ++-- src/cider/nrepl/middleware/track_state.clj | 2 +- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f6d0f51c..0ae1c520 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ ### New features -* Make the `track-state` middleware invokeable directly, by requesting the new `"cider/state"` op. +* 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. diff --git a/doc/modules/ROOT/pages/nrepl-api/ops.adoc b/doc/modules/ROOT/pages/nrepl-api/ops.adoc index 6c303614..6256eddb 100644 --- a/doc/modules/ROOT/pages/nrepl-api/ops.adoc +++ b/doc/modules/ROOT/pages/nrepl-api/ops.adoc @@ -1288,6 +1288,20 @@ Returns:: +=== `cider/get-state` + + + +Required parameters:: +{blank} + +Optional parameters:: +{blank} + +Returns:: +{blank} + + === `cider/log-add-appender` Add an appender to a log framework. @@ -1593,17 +1607,3 @@ Returns:: * `:status` done * `:cider/log-update-consumer` The consumer that was updated. - - -=== `cider/state` - - - -Required parameters:: -{blank} - -Optional parameters:: -{blank} - -Returns:: -{blank} diff --git a/src/cider/nrepl.clj b/src/cider/nrepl.clj index 7b7b1318..b6a83e78 100644 --- a/src/cider/nrepl.clj +++ b/src/cider/nrepl.clj @@ -661,10 +661,10 @@ stack frame of the most recent exception. This op is deprecated, please use the ops-that-can-eval (cljs/expects-piggieback {: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/state\" op." +You can also request to compute the info directly by requesting the \"cider/get-state\" op." :requires #{#'session} :expects ops-that-can-eval - :handles {"cider/state" {}} + :handles {"cider/get-state" {}} :returns {"repl-type" "`:clj` or `:cljs`." "changed-namespaces" "A map of namespaces to `{:aliases ,,, :interns ,,,}`"}})) diff --git a/src/cider/nrepl/middleware/track_state.clj b/src/cider/nrepl/middleware/track_state.clj index f9df55e3..d83f4d90 100644 --- a/src/cider/nrepl/middleware/track_state.clj +++ b/src/cider/nrepl/middleware/track_state.clj @@ -334,7 +334,7 @@ (defn handle-tracker [handler {:keys [op session] :as msg}] (cond - (= "cider/state" op) + (= "cider/get-state" op) (send ns-cache update-in [session] update-and-send-cache msg) (ops-that-can-eval op)