diff options
author | Nate Sesti <sestinj@gmail.com> | 2023-08-11 23:45:57 -0700 |
---|---|---|
committer | Nate Sesti <sestinj@gmail.com> | 2023-08-11 23:45:57 -0700 |
commit | e1325c0153becb95b454810d9461efd7d3624a6a (patch) | |
tree | f00149d93cf082db2dbaf1d1f24ee0f5114ff615 /extension/src/activation/environmentSetup.ts | |
parent | 88599cfa69e51906d4eea807cfc920515bf50426 (diff) | |
download | sncontinue-e1325c0153becb95b454810d9461efd7d3624a6a.tar.gz sncontinue-e1325c0153becb95b454810d9461efd7d3624a6a.tar.bz2 sncontinue-e1325c0153becb95b454810d9461efd7d3624a6a.zip |
fix: :bug: a handful of bug fixes
keyboard interactions in textarea, multiple file highlighting, zombie process
Diffstat (limited to 'extension/src/activation/environmentSetup.ts')
-rw-r--r-- | extension/src/activation/environmentSetup.ts | 61 |
1 files changed, 39 insertions, 22 deletions
diff --git a/extension/src/activation/environmentSetup.ts b/extension/src/activation/environmentSetup.ts index 748a5984..3ff9137e 100644 --- a/extension/src/activation/environmentSetup.ts +++ b/extension/src/activation/environmentSetup.ts @@ -94,7 +94,7 @@ async function checkOrKillRunningServer(serverUrl: string): Promise<boolean> { if (serverRunning) { console.log("Killing server from old version of Continue"); try { - await fkill(":65432"); + await fkill(":65432", { force: true }); } catch (e: any) { if (!e.message.includes("Process doesn't exist")) { console.log("Failed to kill old server:", e); @@ -236,28 +236,45 @@ export async function startContinuePythonServer() { setTimeout(spawnChild, delay); }; try { - const child = spawn(destination, { + // NodeJS bug requires not using detached on Windows, otherwise windowsHide is ineffective + // Otherwise, detach is preferable + const windowsSettings = { windowsHide: true, - }); - child.stdout.on("data", (data: any) => { - // console.log(`stdout: ${data}`); - }); - child.stderr.on("data", (data: any) => { - console.log(`stderr: ${data}`); - }); - child.on("error", (err: any) => { - if (attempts < maxAttempts) { - retry(); - } else { - console.error("Failed to start subprocess.", err); - } - }); - child.on("exit", (code: any, signal: any) => { - console.log("Subprocess exited with code", code, signal); - }); - child.on("close", (code: any, signal: any) => { - console.log("Subprocess closed with code", code, signal); - }); + }; + const macLinuxSettings = { + detached: true, + stdio: "ignore", + }; + const settings: any = + os.platform() === "win32" ? windowsSettings : macLinuxSettings; + + // Spawn the server + const child = spawn(destination, settings); + + // Either unref to avoid zombie process, or listen to events because you can + if (os.platform() === "win32") { + child.stdout.on("data", (data: any) => { + // console.log(`stdout: ${data}`); + }); + child.stderr.on("data", (data: any) => { + console.log(`stderr: ${data}`); + }); + child.on("error", (err: any) => { + if (attempts < maxAttempts) { + retry(); + } else { + console.error("Failed to start subprocess.", err); + } + }); + child.on("exit", (code: any, signal: any) => { + console.log("Subprocess exited with code", code, signal); + }); + child.on("close", (code: any, signal: any) => { + console.log("Subprocess closed with code", code, signal); + }); + } else { + child.unref(); + } } catch (e: any) { console.log("Error starting server:", e); retry(); |