Looking at the REPL evaluation API of Calva here. I have it working. But there's a thing around how the promises resolve that I don't quite understand. Wonder if someone here might have some time to look at it with me so that I can get the docs right. Opening a huddle here a while and anyone can just join. 😃
Does this look right to you, @alpox?
type Result = {
result: string;
ns: string;
output: string;
errorOutput: string;
};
export async function evaluateCode(
sessionKey: 'clj' | 'cljs',
code: string,
output?: {
stdout: (m: string) => void;
stderr: (m: string) => void;
}
): Promise<Result> {
const session = replSession.getSession(sessionKey);
if (!session) {
throw new Error(`Can't retrieve REPL session for session key: ${sessionKey}.`);
}
const stdout = output
? output.stdout
: (m: string) => {
state.outputChannel().append(m);
};
const stderr = output
? output.stdout
: (m: string) => {
state.outputChannel().append(`Error: ${m}`);
};
const evaluation = session.eval(code, undefined, {
stdout: stdout,
stderr: stderr,
pprintOptions: printer.disabledPrettyPrinter,
});
return {
result: await evaluation.value,
ns: evaluation.ns,
output: evaluation.outPut,
errorOutput: evaluation.errorOutput,
};
}Yes, this looks fine to me
Spoke too early about having it working. I can right now only get it to work if I am connected to the Joyride REPL. Very strange. But it is also super hard to keep track of which REPL is supposed to do what in this dance...
Huddle off for now. I'll be a bit afk now and then. Holler if you wanna huddle. 😃
I have some promises experience. May find some time for huddling around 19:00 UTC if you still want to by then
Thanks for the offer! I want, but can't be online until about 21-22 CET.
That should work for me as well :-) you can ping me when you are available and Ill try to jump in
I'm back in the twilight zone between REPLs.
Thanks for that session, @alpox! Super fun and very important feedback on the API.
Thanks as well for the fun session. Always happy to help.
@pez I just took a peek again in the nrepl evaluation code (setHandler) - while for the reader its not directly obvious I don't see a possibility/case for it to go wrong, so its surely nothing to worry about.