Fork me on GitHub
#joyride
<
2022-05-25
>
pez13:05:01

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. 😃

pez14:05:36

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...

pez14:05:16

Huddle off for now. I'll be a bit afk now and then. Holler if you wanna huddle. 😃

alpox16:05:26

I have some promises experience. May find some time for huddling around 19:00 UTC if you still want to by then

pez17:05:25

Thanks for the offer! I want, but can't be online until about 21-22 CET.

alpox17:05:25

That should work for me as well :-) you can ping me when you are available and Ill try to jump in

pez19:05:51

I'm back in the twilight zone between REPLs.

pez21:05:06

Thanks for that session, @U6JS7B99S! Super fun and very important feedback on the API.

alpox21:05:10

Thanks as well for the fun session. Always happy to help.

alpox21:05:17

@U0ETXRFEW 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.

🙏 1
pez07:05:26

Does this look right to you, @U6JS7B99S?

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,
  };
}

👍 1
alpox07:05:25

Yes, this looks fine to me

🙏 1