unrepl
unrepl copied to clipboard
On `:print-limits` session action and REPL state
There are two common scenarios in which a client might want to edit print limits (a.k.a. modify REPL state):
- At init time, provided the client lets its user tweak certain aspects of the REPL connection.
- As a one-off operation, where the client only needs to modify the REPL state for one loop (eval/print).
In any of those circumstances, the client might want to edit just one, or several, state variables.
Current implementation's pain-points:
- one-off operations entail possible callback-hell on the client side, there are at least two annidated callbacks to be executed that need to carry results from the initial operation. Example
-> send command to edit print limits to MAX_VALUE
-> callback (carry the default print-limit values):
send some action (i.e. "request docstring for symbol") that expects long lines not to be elided
-> callback (carry the default print-limit values):
revert print limits to default.
- There is no way to edit just one state variable. If a client wants to only edit
*print-level*
, it has to call the:print-limits
action with all the other bindings. Furthermore, the client has no way to know what are those values the first time.
Proposal:
Improve api to handle REPL state variables by:
- Adding initial state to
:unrepl/hello
. - Replacing
:print-limits
action for a more flexible version of it that can change a subset of variables at a time. Maybe also rename it to something more generic, in case more variables are added in the future.
--
Also, an idea I would like to bounce here: what about adding a function that handles one-offs state modifications internally, something like:
{:some/session-action (binding [*print-limit* Long/MAX_VALUE]
(foo/bar :unrepl/param :a-param))}
This would mean improving (ensure-ns)
to recursively search for fully qualified 'function' symbols and requiring them, and to have another variable in the REPL's state that tracks reverting the binding.
--
If accepted, I could code the result of this conversation.
Not addressing all points but:
:print-limits Set print limits (pass nil to leave a limit unchanged). Returns a map of param names to original values.
So you can know the current values and you can also set only some values
Right I missed that, although I think that isn't enough.. with that approach, you can't set values to nil ever. A bit worse than that, in the current print-limits setup, both *print-level*
and *print-length*
are nil by default, so if you change them once, you will not be able to reset them to default.
This is my current solution to address temporary print limits binding: https://github.com/Unrepl/unrepl.el/commit/6391f992cd3d9f46cffb74ab84f4c0ef34c2585f, I'm not in love with it, but it does the trick and it might be good enough for the problem.
Setting both to a high value (e.g. Long/MAX_VALUE
but smaller big values would be good too) is a workaround for nil
.
The value you observe for *print-level*
at the repl are not the values used at print times. Is this a bug?
huh, I thought It was weird that *print-level* was nil
.. that's what comes from executing the :print-limits
session actions, so it's basically the bak#
backup. Seems like a bug.
This is what I get back from a first update:
[:eval {:unrepl.print/nesting-depth nil, :unrepl.print/coll-length nil, :unrepl.print/string-length 80} 1]
From slack:
- Currently it's not possible to edit settings (dynamic bindings) from one connection to another
- Because of this, the only way to change settings in "user" connection is to send action commands through it, which is a big NO-NO.
- One set of settings REPL wide is not enough, one per every print context (eval, log, ex, ...) is awkward.
Currently it's not possible to edit settings (dynamic bindings) from one connection to another
We just ran into this, as we assumed all :action
can/should be sent to an aux repl. A clarifaction in the spec would be helpful, I guess.