From f7922ef9e14aea9109876ad5a3063fd04759efd6 Mon Sep 17 00:00:00 2001 From: plondon Date: Sat, 23 Oct 2021 14:23:57 -0400 Subject: [PATCH] Try spawnSync again --- backend/api.js | 105 ++++++++++++++++++++++++++-------------------- langs/elixir.yaml | 8 +++- 2 files changed, 65 insertions(+), 48 deletions(-) diff --git a/backend/api.js b/backend/api.js index 5ff736a..7c0ec8c 100644 --- a/backend/api.js +++ b/backend/api.js @@ -1,4 +1,4 @@ -import { spawn } from "child_process"; +import { spawn, spawnSync } from "child_process"; import path from "path"; import process from "process"; @@ -323,54 +323,67 @@ export class Session { } await this.writeCode(code); const termArgs = this.privilegedPty(cmdline); - const term = { - pty: spawn(termArgs[0], termArgs.slice(1)), - live: true, - }; - this.term = term; + const result = spawnSync(termArgs[0], termArgs.slice(1), { + encoding: "utf-8", + }); - this.term.pty.stdout.on("data", (data) => { - // Capture term in closure so that we don't keep sending output - // from the old pty even after it's been killed (see ghci). - if (term.live) { - const output = data.toString("utf8"); + if (result.stderr) { + this.send({ + event: "serviceLog", + service: "pty", + output: data.stderr, + }); + return; + } - this.send({ - event: "terminalOutput", - expectedOutput, - output, - }); - } - }); - this.term.pty.stderr.on("data", (data) => { - if (term.live) { - this.send({ - event: "serviceLog", - service: "pty", - output: data.toString("utf8"), - }); - } - }); - this.term.pty.on("close", (code, signal) => { - if (term.live) { - this.send({ - event: "serviceFailed", - service: "terminal", - error: `Exited with status ${signal || code}`, - expectedOutput, - code: signal || code, - }); - } - }); - this.term.pty.on("error", (err) => { - if (term.live) { - this.send({ - event: "serviceFailed", - service: "terminal", - error: `${err}`, - }); - } + this.send({ + event: "terminalOutput", + expectedOutput, + output: result.stdout, }); + + // this.term.pty.stdout.on("data", (data) => { + // // Capture term in closure so that we don't keep sending output + // // from the old pty even after it's been killed (see ghci). + // if (term.live) { + // const output = data.toString("utf8"); + + // this.send({ + // event: "terminalOutput", + // expectedOutput, + // output, + // }); + // } + // }); + // this.term.pty.stderr.on("data", (data) => { + // if (term.live) { + // this.send({ + // event: "serviceLog", + // service: "pty", + // output: data.toString("utf8"), + // }); + // } + // }); + // this.term.pty.on("close", (code, signal) => { + // if (term.live) { + // this.send({ + // event: "serviceFailed", + // service: "terminal", + // error: `Exited with status ${signal || code}`, + // expectedOutput, + // code: signal || code, + // }); + // } + // }); + // this.term.pty.on("error", (err) => { + // if (term.live) { + // this.send({ + // event: "serviceFailed", + // service: "terminal", + // error: `${err}`, + // }); + // } + // }); } catch (err) { logError(err); this.sendError(err); diff --git a/langs/elixir.yaml b/langs/elixir.yaml index 6ddbb8b..75e36f8 100644 --- a/langs/elixir.yaml +++ b/langs/elixir.yaml @@ -17,6 +17,12 @@ install: unzip -d "${pkg}/opt/elixir-ls" elixir-ls.zip ln -s /opt/elixir-ls/language_server.sh "${pkg}/usr/local/bin/elixir-ls" +repl: | + iex +input: | + DELAY: 1 + 123 * 234 + main: "main.exs" template: | IO.puts("Hello, world!") @@ -43,5 +49,3 @@ lsp: skip: - lsp - - repl - - runrepl