Try spawnSync again

This commit is contained in:
plondon 2021-10-23 14:23:57 -04:00
parent a76049cadd
commit f7922ef9e1
2 changed files with 65 additions and 48 deletions

View File

@ -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);

View File

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