diff options
| author | Nate Sesti <sestinj@gmail.com> | 2023-07-02 20:15:36 -0700 | 
|---|---|---|
| committer | Nate Sesti <sestinj@gmail.com> | 2023-07-02 20:15:36 -0700 | 
| commit | 38d0c1ad7955b43c1765ac8faea723028a90201e (patch) | |
| tree | c2682170eb8f8a81fd494fce7bb8a435dcfa9829 /extension/src/activation | |
| parent | 894a197892fc4e3a6a5af7d47b7702ea895e20b7 (diff) | |
| parent | c41314b095648e6b3bcecc84a20354574db8379d (diff) | |
| download | sncontinue-38d0c1ad7955b43c1765ac8faea723028a90201e.tar.gz sncontinue-38d0c1ad7955b43c1765ac8faea723028a90201e.tar.bz2 sncontinue-38d0c1ad7955b43c1765ac8faea723028a90201e.zip  | |
Merge branch 'main' into explicit-context
Diffstat (limited to 'extension/src/activation')
| -rw-r--r-- | extension/src/activation/environmentSetup.ts | 87 | 
1 files changed, 52 insertions, 35 deletions
diff --git a/extension/src/activation/environmentSetup.ts b/extension/src/activation/environmentSetup.ts index d4c81d2e..4e6be9b3 100644 --- a/extension/src/activation/environmentSetup.ts +++ b/extension/src/activation/environmentSetup.ts @@ -9,6 +9,7 @@ import { getContinueServerUrl } from "../bridge";  import fetch from "node-fetch";  import * as vscode from "vscode";  import fkill from "fkill"; +import { sendTelemetryEvent, TelemetryEvent } from "../telemetry";  const MAX_RETRIES = 5;  async function retryThenFail( @@ -17,13 +18,16 @@ async function retryThenFail(  ): Promise<any> {    try {      return await fn(); -  } catch (e) { +  } catch (e: any) {      if (retries > 0) {        return await retryThenFail(fn, retries - 1);      }      vscode.window.showErrorMessage(        "Failed to set up Continue extension. Please email nate@continue.dev and we'll get this fixed ASAP!"      ); +    sendTelemetryEvent(TelemetryEvent.ExtensionSetupError, { +      error: e.message, +    });      throw e;    }  } @@ -47,6 +51,12 @@ async function runCommand(cmd: string): Promise<[string, string | undefined]> {      stdout = "";    } +  if (stderr) { +    sendTelemetryEvent(TelemetryEvent.ExtensionSetupError, { +      error: stderr, +    }); +  } +    return [stdout, stderr];  } @@ -71,9 +81,11 @@ async function getPythonPipCommands() {      }    } +  let pipCmd = pythonCmd.endsWith("3") ? "pip3" : "pip"; +    const version = stdout.split(" ")[1];    const [major, minor] = version.split("."); -  if (parseInt(major) !== 3 || parseInt(minor) < 7) { +  if (parseInt(major) !== 3 || parseInt(minor) < 8) {      // Need to check specific versions      const checkPython3VersionExists = async (minorVersion: number) => {        const [stdout, stderr] = await runCommand( @@ -82,24 +94,27 @@ async function getPythonPipCommands() {        return typeof stderr === "undefined" || stderr === "";      }; -    const validVersions = [7, 8, 9, 10, 11, 12]; +    const VALID_VERSIONS = [8, 9, 10, 11, 12];      let versionExists = false; -    for (const minorVersion of validVersions) { +    for (const minorVersion of VALID_VERSIONS) {        if (await checkPython3VersionExists(minorVersion)) {          versionExists = true; -        break; +        pythonCmd = `python3.${minorVersion}`; +        pipCmd = `pip3.${minorVersion}`;        }      }      if (!versionExists) {        vscode.window.showErrorMessage( -        "Continue requires Python3 version 3.7 or greater. Please update your Python3 installation, reload VS Code, and try again." +        "Continue requires Python3 version 3.8 or greater. Please update your Python3 installation, reload VS Code, and try again."        ); -      throw new Error("Python3 is not installed."); +      throw new Error("Python3.8 or greater is not installed.");      } +  } else { +    pythonCmd = `python${major}.${minor}`; +    pipCmd = `pip${major}.${minor}`;    } -  const pipCmd = pythonCmd.endsWith("3") ? "pip3" : "pip";    return [pythonCmd, pipCmd];  } @@ -283,34 +298,33 @@ export async function startContinuePythonServer() {      return;    } -  if (await checkServerRunning(serverUrl)) { -    // Kill the server if it is running an old version -    if (fs.existsSync(serverVersionPath())) { -      const serverVersion = fs.readFileSync(serverVersionPath(), "utf8"); -      if (serverVersion === getExtensionVersion()) { -        return; +  return await retryThenFail(async () => { +    if (await checkServerRunning(serverUrl)) { +      // Kill the server if it is running an old version +      if (fs.existsSync(serverVersionPath())) { +        const serverVersion = fs.readFileSync(serverVersionPath(), "utf8"); +        if (serverVersion === getExtensionVersion()) { +          return; +        }        } +      console.log("Killing old server..."); +      await fkill(":65432");      } -    console.log("Killing old server..."); -    await fkill(":65432"); -  } -  // Do this after above check so we don't have to waste time setting up the env -  await setupPythonEnv(); +    // Do this after above check so we don't have to waste time setting up the env +    await setupPythonEnv(); -  let activateCmd = ". env/bin/activate"; -  let pythonCmd = "python3"; -  if (process.platform == "win32") { -    activateCmd = ".\\env\\Scripts\\activate"; -    pythonCmd = "python"; -  } +    const [pythonCmd] = await getPythonPipCommands(); +    const activateCmd = +      process.platform == "win32" +        ? ".\\env\\Scripts\\activate" +        : ". env/bin/activate"; -  let command = `cd "${path.join( -    getExtensionUri().fsPath, -    "scripts" -  )}" && ${activateCmd} && cd .. && ${pythonCmd} -m scripts.run_continue_server`; +    const command = `cd "${path.join( +      getExtensionUri().fsPath, +      "scripts" +    )}" && ${activateCmd} && cd .. && ${pythonCmd} -m scripts.run_continue_server`; -  return await retryThenFail(async () => {      console.log("Starting Continue python server...");      return new Promise(async (resolve, reject) => { @@ -318,22 +332,25 @@ export async function startContinuePythonServer() {          const child = spawn(command, {            shell: true,          }); -        child.stdout.on("data", (data: any) => { -          console.log(`stdout: ${data}`); -        });          child.stderr.on("data", (data: any) => { +          console.log(`stdout: ${data}`);            if (              data.includes("Uvicorn running on") || // Successfully started the server              data.includes("address already in use") // The server is already running (probably a simultaneously opened VS Code window)            ) {              console.log("Successfully started Continue python server");              resolve(null); -          } else { -            console.log(`stderr: ${data}`); +          } else if (data.includes("ERROR") || data.includes("Traceback")) { +            sendTelemetryEvent(TelemetryEvent.ExtensionSetupError, { +              error: data, +            });            }          });          child.on("error", (error: any) => {            console.log(`error: ${error.message}`); +          sendTelemetryEvent(TelemetryEvent.ExtensionSetupError, { +            error: error.message, +          });          });          // Write the current version of vscode to a file called server_version.txt  | 
