Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions src/executors/ClingExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,24 @@ export default abstract class ClingExecutor extends NonInteractiveCodeExecutor {

// Run code without a main block (cling only)
return new Promise<void>((resolve, reject) => {
const childArgs = [...args.split(" "), ...codeBlockContent.split("\n")];
const child = child_process.spawn(this.settings.clingPath, childArgs, {env: process.env, shell: this.usesShell});
const childArgs = args.split(" ").filter(arg => arg.length > 0);
if (!childArgs.includes("--nologo")) {
childArgs.push("--nologo");
}

let cmd = this.settings.clingPath;
if (this.settings.wslMode) {
childArgs.unshift("-e", cmd);
cmd = "wsl";
}

const child = child_process.spawn(cmd, childArgs, {env: process.env, shell: this.usesShell});
// Set resolve callback to resolve the promise in the child_process.on('close', ...) listener from super.handleChildOutput
this.resolveRun = resolve;
this.handleChildOutput(child, outputter, this.tempFileId);

child.stdin.write(codeBlockContent);
child.stdin.end();
});
}

Expand Down
3 changes: 2 additions & 1 deletion src/executors/CppExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export default class CppExecutor extends ClingExecutor {
}

override run(codeBlockContent: string, outputter: Outputter, cmd: string, cmdArgs: string, ext: string) {
return super.run(codeBlockContent, outputter, cmd, `-std=${this.settings.clingStd} ${cmdArgs}`, "cpp");
const args = this.settings.clingStd ? `-std=${this.settings.clingStd} ${cmdArgs}` : cmdArgs;
return super.run(codeBlockContent, outputter, cmd, args, "cpp");
}
}
2 changes: 1 addition & 1 deletion src/executors/LatexExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export default class LaTeXExecutor extends NonInteractiveCodeExecutor {
private async compileAndRerun(compilerPath: string, args: string, exec: ExecutionContext): Promise<string> {
for (let attempt = 0; attempt <= MAX_COMPILER_RERUNS; attempt++) {
const isLastAttempt = attempt == MAX_COMPILER_RERUNS;
const result = await this.runChildProcess(compilerPath, args.split(' '), 'o.pdf', exec, { skipWriteFileLink: true, outFileArg: "", doDetectRerun: !isLastAttempt });
const result = await this.runChildProcess(compilerPath, args.split(' ').filter(arg => arg.length > 0), 'o.pdf', exec, { skipWriteFileLink: true, outFileArg: "", doDetectRerun: !isLastAttempt });
const hasRequestedRerun = result === undefined;
if (!hasRequestedRerun) return result;
}
Expand Down
5 changes: 1 addition & 4 deletions src/executors/NodeJSExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ export default class NodeJSExecutor extends ReplExecutor {
process: ChildProcessWithoutNullStreams

constructor(settings: ExecutorSettings, file: string) {
const args = settings.nodeArgs ? settings.nodeArgs.split(" ") : [];

args.unshift(`-e`, `require("repl").start({prompt: "", preview: false, ignoreUndefined: true}).on("exit", ()=>process.exit())`);

const args = settings.nodeArgs ? settings.nodeArgs.split(" ").filter(arg => arg.length > 0) : [];
super(settings, settings.nodePath, args, file, "js");
}

Expand Down
2 changes: 1 addition & 1 deletion src/executors/NonInteractiveCodeExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default class NonInteractiveCodeExecutor extends Executor {
const tempFileName = this.getTempFile(ext);

fs.promises.writeFile(tempFileName, codeBlockContent).then(() => {
const args = cmdArgs ? cmdArgs.split(" ") : [];
const args = cmdArgs ? cmdArgs.split(" ").filter(arg => arg.length > 0) : [];

if (this.isWSLEnabled()) {
args.unshift("-e", cmd);
Expand Down
2 changes: 1 addition & 1 deletion src/executors/PowerShellOnWindowsExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default class PowerShellOnWindowsExecutor extends NonInteractiveCodeExecu
const tempFileName = this.getTempFile(ext);

fs.promises.writeFile(tempFileName, codeBlockContent, this.settings.powershellEncoding).then(() => {
const args = cmdArgs ? cmdArgs.split(" ") : [];
const args = cmdArgs ? cmdArgs.split(" ").filter(arg => arg.length > 0) : [];

if (this.settings.wslMode) {
args.unshift("-e", cmd);
Expand Down
2 changes: 1 addition & 1 deletion src/executors/RExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default class RExecutor extends ReplExecutor {

constructor(settings: ExecutorSettings, file: string) {
//use empty array for empty string, instead of [""]
const args = settings.RArgs ? settings.RArgs.split(" ") : [];
const args = settings.RArgs ? settings.RArgs.split(" ").filter(arg => arg.length > 0) : [];

let conArgName = `notebook_connection_${Math.random().toString(16).substring(2)}`;

Expand Down
2 changes: 1 addition & 1 deletion src/executors/python/PythonExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default class PythonExecutor extends ReplExecutor {

constructor(settings: ExecutorSettings, file: string) {

const args = settings.pythonArgs ? settings.pythonArgs.split(" ") : [];
const args = settings.pythonArgs ? settings.pythonArgs.split(" ").filter(arg => arg.length > 0) : [];

args.unshift("-i");

Expand Down
3 changes: 1 addition & 2 deletions src/transforms/windowsPathToWsl.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { join } from "path/posix";
import { sep } from "path";

export default (windowsPath: string) => {
const driveLetter = windowsPath[0].toLowerCase();
const posixyPath = windowsPath.replace(/^[^:]*:/, "") //remove drive letter
.split(sep).join("/"); //force / as separator
.replace(/\\/g, "/"); //force / as separator

return join("/mnt/", driveLetter, posixyPath);
}