Towards a better interactive evaluator for developing extensions

I’ve pushed the state of modern gnome-shell debugging as far as I can go. looking-glass is a nice start, but the GUI is terrible for casual use (it’s modal, so you can’t switch between things). Worst, the context is erased after each eval.

I’d love to see a better REPL experience that functions similar to node js’s REPL. With lexical scope context continuing between evaluations and whatnot. This doesn’t seem to be possible with what’s exposed today.

Once upon a time, we could use jsrdbg to attach to gnome-shell, poke around, and set breakpoints. Does that method still work? Is anyone using it?

I think a (not-so-simple but) workable hack may be to present a readline-powered REPL, take each statement, and transpile it to modify function lol() {} to global.replContext.lol = function() { }, and also do the same for outer const / let statements (and just fudge the fact that consts aren’t reassignable). The babel language parses can tell which variables are pointing to an enclosed scope binding or point to the outter-most lexical scope. We could leverage this accordingly.

const minVal = 1;
function myHelper() {
  const maxVal = 10;
  [1,2,3,40].filter((v) => v < maxVal && v > minVal);
}

could be transpiled to

global.replCtx.minVal = 1;
global.replCtx.myHelper = () => {
  const maxVal = 10;
  [1,2,3,40].filter((v) => v < maxVal && v > global.replCtx.minVal);
}

When the session is done, we could just delete global.replCtx and let the garbage collector clean everything up.

there’d be some limitations to this hack, mostly things like running eval inside of a transpiled script would lead to surprise. Overall, this would be a nicer experience, though, I think. The client could just connect to dbus and run org.gnome.Shell.Eval (provided the debug-mode flag is enabled in looking-glass).

Thoughts? Terrible idea? Something better exist already?

Not exactly what you’re asking for, but you can get around the modality of looking glass by using something similar from a terminal: shell-lg (tools/shell-lg.sh · main · GNOME / gnome-shell · GitLab).

1 Like

This topic was automatically closed 45 days after the last reply. New replies are no longer allowed.