Sayid ships an nREPL middleware (com.billpiel.sayid.nrepl-middleware/wrap-sayid)
that exposes its tracing engine over the wire. The bundled Emacs client talks to
Sayid exclusively through these ops, and any other editor or tool can do the same.
This document is the reference for that wire API.
With Leiningen, add Sayid as a plugin (it registers the middleware automatically):
{:user {:plugins [[mx.cider/sayid "0.3.0"]]}}
Or add the middleware explicitly when you start the server, e.g. with the
Clojure CLI / nrepl.server:
(nrepl.server/start-server
:handler (nrepl.server/default-handler #'com.billpiel.sayid.nrepl-middleware/wrap-sayid))
Send a normal nREPL message with an "op" key naming one of the ops below, plus
whatever parameters that op takes. Every op terminates the request with a
:status of "done", so a synchronous client can block until it arrives.
Ops fall into two shapes:
:status "done" (no value).:value, then :status "done".Response values are already decoded - Sayid encodes them into plain bencode-friendly data (nested lists, strings and numbers) before they go on the wire, so by the time your nREPL client hands you a value it is ordinary data. Do not run it through a reader. A few encoding rules are worth knowing:
:foo -> "foo"),1 / nil,If an op throws, the response carries :status #{"error" "done"} along with
:err (a stack trace) and :ex (the exception class), the same convention
cider-nrepl uses, so the failure surfaces instead of hanging the client.
Several ops resolve "the thing at the cursor" server-side. They take the buffer
source (the whole file as a string) plus a 1-based line and column, and
Sayid parses the source to find the symbol there. This keeps editors from having
to reimplement Clojure-aware symbol resolution.
sayid-trace-fn-at-pointApply a trace action to the function whose symbol is at the cursor.
| param | meaning |
|---|---|
action | one of add-outer, add-inner, enable, disable, remove |
file | path of the buffer's file |
line, column | 1-based cursor position |
source | the buffer's full text |
Replies with the resolved qualified symbol (e.g. "my.ns/my-fn"), or nil when
nothing resolves at that position.
sayid-trace-fnApply a trace action to an explicitly named function.
| param | meaning |
|---|---|
action | one of add-outer, add-inner, enable, disable, remove |
fn-ns | the function's namespace |
fn-name | the function's name |
add-outer records calls to the function; add-inner additionally records every
expression evaluated inside it. enable/disable flip an existing trace on and
off; remove tears it down. Replies with :status "done".
sayid-trace-nsApply a trace action to a whole namespace.
| param | meaning |
|---|---|
action | one of enable, disable, remove |
ns | the namespace name |
Replies with :status "done".
sayid-all-tracesApply a trace action to every trace at once.
| param | meaning |
|---|---|
action | one of enable, disable, remove |
Replies with :status "done".
sayid-trace-ns-in-fileTrace the namespace declared in file. Param: file. Replies :status "done".
sayid-trace-ns-by-patternTrace every loaded namespace whose name matches a pattern.
| param | meaning |
|---|---|
ns-pattern | a namespace pattern, where * is a wildcard |
ref-ns | a namespace to resolve the pattern relative to |
Replies with :status "done".
sayid-trace-all-ns-in-dirRecursively trace every namespace found under dir. Param: dir. Replies
:status "done".
sayid-get-workspaceRender the current workspace with the active view. Takes no params. Replies with
the rendered tree as a [text text-properties query-args] triple, where text
is the printable output, text-properties describes per-span coloring/metadata,
and query-args is the printed query that produced it.
sayid-queryRun a query against the workspace. Param: query (a printed Clojure query
form). Replies with the same [text properties query-args] triple as
sayid-get-workspace.
sayid-query-form-at-pointQuery the workspace for the calls that best match the cursor context. Params:
file, line. Replies with a [text properties] pair.
sayid-query-by-idQuery for a recorded call by id, optionally with a modifier.
| param | meaning |
|---|---|
trace-id | the id of the recorded call |
mod | a modifier string, e.g. "a" (ancestors), "d" (descendants), optionally with a depth |
Replies with a [text properties query-args] triple.
sayid-query-by-fnLike the above, but selects by function name. Params: fn-name, mod. Replies
with a [text properties query-args] triple.
These operate on a single node in the rendered output, identified by trace-id
(and path for nested values).
sayid-gen-instance-exprGenerate an expression that reproduces a recorded call, def-ing its arguments to
$s/* vars along the way. Param: trace-id. Replies with the expression string
(e.g. "(my.ns/my-fn $s/a $s/b)").
sayid-def-valueDef the value at path within the call trace-id to $s/*. Params: trace-id,
path. Replies with a confirmation value.
sayid-pprint-valuePretty-print the value at path within the call trace-id. Params: trace-id,
path. Replies with the pretty-printed text.
sayid-set-viewSelect a named view for subsequent rendering. Param: view-name. Replies
:status "done".
sayid-toggle-viewToggle between the default and the verbose view. Takes no params. Replies with the new state.
sayid-get-viewsList the registered view names. Takes no params. Replies with the view names.
sayid-clear-logClear the recorded calls but keep the traces in place. Takes no params. Replies
:status "done".
sayid-reset-workspaceRemove all traces and clear the recorded calls. Takes no params. Replies
:status "done".
sayid-versionReplies with the Sayid version string (e.g. "0.3.0").
sayid-get-trace-countReplies with the number of traces in the workspace.
sayid-get-enabled-trace-countReplies with the number of currently enabled traces.
sayid-get-meta-at-pointResolve the symbol at the cursor and report its metadata. Params: source,
file, line.
sayid-find-all-ns-rootsReplies with the distinct source roots of the loaded namespaces (e.g.
["src" "test"]), handy for offering a directory to scan.
sayid-show-tracedRender the list of what's currently traced. Optional param: ns (limit to one
namespace). Replies with the rendered tree.
Can you improve this documentation?Edit on GitHub
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |