diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d2bc479..0ae1c520 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/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. diff --git a/doc/modules/ROOT/pages/nrepl-api/ops.adoc b/doc/modules/ROOT/pages/nrepl-api/ops.adoc index a8d9190b..6256eddb 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,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. @@ -1324,7 +1324,7 @@ Returns:: -=== `log-add-consumer` +=== `cider/log-add-consumer` Add a consumer to an appender of a log framework. @@ -1343,7 +1343,7 @@ Returns:: -=== `log-analyze-stacktrace` +=== `cider/log-analyze-stacktrace` Analyze the stacktrace of a log event. @@ -1361,7 +1361,7 @@ Returns:: -=== `log-clear-appender` +=== `cider/log-clear-appender` Clear all events of a log appender. @@ -1379,7 +1379,7 @@ Returns:: -=== `log-exceptions` +=== `cider/log-exceptions` Return the exceptions and their frequencies for the given framework and appender. @@ -1397,7 +1397,7 @@ Returns:: -=== `log-format-event` +=== `cider/log-format-event` Format a log event. @@ -1422,7 +1422,7 @@ Returns:: -=== `log-frameworks` +=== `cider/log-frameworks` Return the available log frameworks. @@ -1438,7 +1438,7 @@ Returns:: -=== `log-inspect-event` +=== `cider/log-inspect-event` Inspect a log event. @@ -1457,7 +1457,7 @@ Returns:: -=== `log-levels` +=== `cider/log-levels` Return the log levels and their frequencies for the given framework and appender. @@ -1475,7 +1475,7 @@ Returns:: -=== `log-loggers` +=== `cider/log-loggers` Return the loggers and their frequencies for the given framework and appender. @@ -1493,7 +1493,7 @@ Returns:: -=== `log-remove-appender` +=== `cider/log-remove-appender` Remove an appender from a log framework. @@ -1511,7 +1511,7 @@ Returns:: -=== `log-remove-consumer` +=== `cider/log-remove-consumer` Remove a consumer from the appender of a log framework. @@ -1530,7 +1530,7 @@ Returns:: -=== `log-search` +=== `cider/log-search` Search the log events of an appender. @@ -1550,7 +1550,7 @@ Returns:: -=== `log-threads` +=== `cider/log-threads` Return the threads and their frequencies for the given framework and appender. @@ -1568,7 +1568,7 @@ Returns:: -=== `log-update-appender` +=== `cider/log-update-appender` Update the appender of a log framework. @@ -1589,7 +1589,7 @@ Returns:: -=== `log-update-consumer` +=== `cider/log-update-consumer` Update the consumer of a log appender. 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..b6a83e78 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/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." diff --git a/src/cider/nrepl/middleware/track_state.clj b/src/cider/nrepl/middleware/track_state.clj index e3f91a26..d83f4d90 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/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)))