diff options
| author | Nate Sesti <sestinj@gmail.com> | 2023-08-02 21:27:35 -0700 | 
|---|---|---|
| committer | Nate Sesti <sestinj@gmail.com> | 2023-08-02 21:27:35 -0700 | 
| commit | 5c111f75717e542ec0be9b73b2ee1f1e495c629c (patch) | |
| tree | b2f6fc2441b4c42f4df3bd2322614bd4de2aead1 /extension | |
| parent | 0f0cbf6d65dffc71c9141a045aacaed0fb6466d6 (diff) | |
| download | sncontinue-5c111f75717e542ec0be9b73b2ee1f1e495c629c.tar.gz sncontinue-5c111f75717e542ec0be9b73b2ee1f1e495c629c.tar.bz2 sncontinue-5c111f75717e542ec0be9b73b2ee1f1e495c629c.zip  | |
cleaning environmentSetup
Diffstat (limited to 'extension')
| -rw-r--r-- | extension/src/activation/activate.ts | 47 | ||||
| -rw-r--r-- | extension/src/activation/environmentSetup.ts | 106 | ||||
| -rw-r--r-- | extension/src/bridge.ts | 2 | ||||
| -rw-r--r-- | extension/src/continueIdeClient.ts | 7 | ||||
| -rw-r--r-- | extension/src/debugPanel.ts | 2 | ||||
| -rw-r--r-- | extension/src/util/messenger.ts | 1 | 
6 files changed, 52 insertions, 113 deletions
diff --git a/extension/src/activation/activate.ts b/extension/src/activation/activate.ts index a47d5e97..7a2fdfc3 100644 --- a/extension/src/activation/activate.ts +++ b/extension/src/activation/activate.ts @@ -57,48 +57,21 @@ export async function activateExtension(context: vscode.ExtensionContext) {    // Start the server and display loader if taking > 2 seconds    const sessionIdPromise = (async () => {      await new Promise((resolve) => { -      let serverStarted = false; -        // Start the server and set serverStarted to true when done        startContinuePythonServer().then(() => { -        serverStarted = true;          resolve(null);        }); -      // Wait for 2 seconds -      setTimeout(() => { -        // If the server hasn't started after 2 seconds, show the notification -        if (!serverStarted) { -          vscode.window.withProgress( -            { -              location: vscode.ProgressLocation.Notification, -              title: -                "Starting Continue Server... (it may take a minute to download Python packages)", -              cancellable: false, -            }, -            async (progress, token) => { -              // Wait for the server to start -              while (!serverStarted) { -                await new Promise((innerResolve) => -                  setTimeout(innerResolve, 1000) -                ); -              } -              return Promise.resolve(); -            } -          ); - -          vscode.window -            .showInformationMessage( -              "Click here to view the server logs, or use the 'continue.viewLogs' VS Code command.", -              "View Logs" -            ) -            .then((selection) => { -              if (selection === "View Logs") { -                vscode.commands.executeCommand("continue.viewLogs"); -              } -            }); -        } -      }, 2000); +      vscode.window +        .showInformationMessage( +          "Click here to view the server logs, or use the 'continue.viewLogs' VS Code command.", +          "View Logs" +        ) +        .then((selection) => { +          if (selection === "View Logs") { +            vscode.commands.executeCommand("continue.viewLogs"); +          } +        });      });      console.log("Continue server started"); diff --git a/extension/src/activation/environmentSetup.ts b/extension/src/activation/environmentSetup.ts index b3482a92..fd83c8ca 100644 --- a/extension/src/activation/environmentSetup.ts +++ b/extension/src/activation/environmentSetup.ts @@ -11,7 +11,6 @@ import * as os from "os";  import fkill from "fkill";  async function runCommand(cmd: string): Promise<[string, string | undefined]> { -  console.log("Running command: ", cmd);    var stdout: any = "";    var stderr: any = "";    try { @@ -32,66 +31,10 @@ async function runCommand(cmd: string): Promise<[string, string | undefined]> {    return [stdout, stderr];  } -export async function getPythonPipCommands() { -  var [stdout, stderr] = await runCommand("python3 --version"); -  let pythonCmd = "python3"; -  if (stderr) { -    // If not, first see if python3 is aliased to python -    var [stdout, stderr] = await runCommand("python --version"); -    if ( -      (typeof stderr === "undefined" || stderr === "") && -      stdout.split(" ")[1][0] === "3" -    ) { -      // Python3 is aliased to python -      pythonCmd = "python"; -    } else { -      // Python doesn't exist at all -      vscode.window.showErrorMessage( -        "Continue requires Python3. Please install from https://www.python.org/downloads, reload VS Code, and try again." -      ); -      throw new Error("Python 3 is not installed."); -    } -  } - -  let pipCmd = pythonCmd.endsWith("3") ? "pip3" : "pip"; - -  const version = stdout.split(" ")[1]; -  const [major, minor] = version.split("."); -  if (parseInt(major) !== 3 || parseInt(minor) < 8) { -    // Need to check specific versions -    const checkPython3VersionExists = async (minorVersion: number) => { -      const [stdout, stderr] = await runCommand( -        `python3.${minorVersion} --version` -      ); -      return typeof stderr === "undefined" || stderr === ""; -    }; - -    const VALID_VERSIONS = [8, 9, 10, 11, 12]; -    let versionExists = false; - -    for (const minorVersion of VALID_VERSIONS) { -      if (await checkPython3VersionExists(minorVersion)) { -        versionExists = true; -        pythonCmd = `python3.${minorVersion}`; -        pipCmd = `pip3.${minorVersion}`; -      } -    } - -    if (!versionExists) { -      vscode.window.showErrorMessage( -        "Continue requires Python version 3.8 or greater. Please update your Python installation, reload VS Code, and try again." -      ); -      throw new Error("Python3.8 or greater is not installed."); -    } -  } - -  return [pythonCmd, pipCmd]; -} -  async function checkServerRunning(serverUrl: string): Promise<boolean> {    // Check if already running by calling /health    try { -    const response = await fetch(serverUrl + "/health"); +    const response = await fetch(`${serverUrl}/health`);      if (response.status === 200) {        console.log("Continue python server already running");        return true; @@ -165,12 +108,18 @@ async function checkOrKillRunningServer(serverUrl: string): Promise<boolean> {  export async function downloadFromS3(    bucket: string,    fileName: string, -  destination: string +  destination: string, +  region: string  ) { -  const s3Url = `https://${bucket}.s3.amazonaws.com/${fileName}`; -  const response = await fetch(s3Url); +  const s3Url = `https://${bucket}.s3.${region}.amazonaws.com/${fileName}`; +  const response = await fetch(s3Url, { +    method: "GET", +  });    if (!response.ok) { -    throw new Error(`HTTP error! status: ${response.status}`); +    const text = await response.text(); +    const errText = `Failed to download Continue server from S3: ${text}`; +    vscode.window.showErrorMessage(errText); +    throw new Error(errText);    }    const buffer = await response.buffer();    fs.writeFileSync(destination, buffer); @@ -189,21 +138,46 @@ export async function startContinuePythonServer() {    }    // Download the server executable +    const bucket = "continue-server-binaries"; -  const fileName = `extension/exe/${ +  const fileName =      os.platform() === "win32"        ? "windows/run.exe"        : os.platform() === "darwin"        ? "mac/run" -      : "linux/run" -  }`; +      : "linux/run"; +    const destination = path.join(      getExtensionUri().fsPath,      "server",      "exe",      "run"    ); -  await downloadFromS3(bucket, fileName, destination); + +  // First, check if the server is already downloaded +  let shouldDownload = true; +  if (fs.existsSync(destination)) { +    // Check if the server is the correct version +    const serverVersion = fs.readFileSync(serverVersionPath(), "utf8"); +    if (serverVersion === getExtensionVersion()) { +      // The current version is already up and running, no need to continue +      console.log("Continue server already downloaded"); +      shouldDownload = false; +    } +  } + +  if (shouldDownload) { +    vscode.window.withProgress( +      { +        location: vscode.ProgressLocation.Notification, +        title: "Installing Continue server...", +        cancellable: false, +      }, +      async () => { +        await downloadFromS3(bucket, fileName, destination, "us-west-1"); +      } +    ); +  }    // Get name of the corresponding executable for platform    if (os.platform() === "darwin") { diff --git a/extension/src/bridge.ts b/extension/src/bridge.ts index 0d665826..9c43ebc2 100644 --- a/extension/src/bridge.ts +++ b/extension/src/bridge.ts @@ -7,7 +7,7 @@ export function getContinueServerUrl() {      extensionContext &&      extensionContext.extensionMode === vscode.ExtensionMode.Development    ) { -    return "http://localhost:8001"; +    // return "http://localhost:8001";    }    return (      vscode.workspace.getConfiguration("continue").get<string>("serverUrl") || diff --git a/extension/src/continueIdeClient.ts b/extension/src/continueIdeClient.ts index 220edafa..1fa41383 100644 --- a/extension/src/continueIdeClient.ts +++ b/extension/src/continueIdeClient.ts @@ -15,10 +15,6 @@ import { FileEditWithFullContents } from "../schema/FileEditWithFullContents";  import fs = require("fs");  import { WebsocketMessenger } from "./util/messenger";  import { diffManager } from "./diffs"; -import path = require("path"); -import { registerAllCodeLensProviders } from "./lang-server/codeLens"; -import { registerAllCommands } from "./commands"; -import registerQuickFixProvider from "./lang-server/codeActions";  const os = require("os");  const continueVirtualDocumentScheme = "continue"; @@ -45,7 +41,6 @@ class IdeProtocolClient {      this.messenger = messenger;      const reconnect = () => { -      console.log("Trying to reconnect IDE protocol websocket...");        this.messenger = null;        // Exponential backoff to reconnect @@ -62,11 +57,9 @@ class IdeProtocolClient {        this._lastReloadTime = Math.min(2 * this._lastReloadTime, 5000);      };      messenger.onOpen(() => { -      console.log("IDE protocol websocket opened");        this._reconnectionTimeouts.forEach((to) => clearTimeout(to));      });      messenger.onClose(() => { -      console.log("IDE protocol websocket closed");        reconnect();      });      messenger.onError(() => { diff --git a/extension/src/debugPanel.ts b/extension/src/debugPanel.ts index 643563a2..66d22e24 100644 --- a/extension/src/debugPanel.ts +++ b/extension/src/debugPanel.ts @@ -181,7 +181,7 @@ export function setupDebugPanel(      switch (data.type) {        case "onLoad": {          let sessionId: string; -        console.log("Running onLoad"); +        console.log("Waiting for session id");          if (typeof sessionIdPromise === "string") {            sessionId = sessionIdPromise;          } else { diff --git a/extension/src/util/messenger.ts b/extension/src/util/messenger.ts index 32490a68..3044898e 100644 --- a/extension/src/util/messenger.ts +++ b/extension/src/util/messenger.ts @@ -39,7 +39,6 @@ export class WebsocketMessenger extends Messenger {      //   var WebSocket = require("ws");      // } -    console.log("Creating websocket at: ", this.serverUrl);      const newWebsocket = new WebSocket(this.serverUrl);      for (const listener of this.onOpenListeners) {        this.onOpen(listener);  | 
