diff options
Diffstat (limited to 'extension/src')
| -rw-r--r-- | extension/src/activation/activate.ts | 22 | ||||
| -rw-r--r-- | extension/src/activation/environmentSetup.ts | 46 | ||||
| -rw-r--r-- | extension/src/diffs.ts | 24 | 
3 files changed, 63 insertions, 29 deletions
| diff --git a/extension/src/activation/activate.ts b/extension/src/activation/activate.ts index 18650561..2c5ba58c 100644 --- a/extension/src/activation/activate.ts +++ b/extension/src/activation/activate.ts @@ -7,9 +7,16 @@ import IdeProtocolClient from "../continueIdeClient";  import { getContinueServerUrl } from "../bridge";  import { CapturedTerminal } from "../terminal/terminalEmulator";  import { setupDebugPanel, ContinueGUIWebviewViewProvider } from "../debugPanel"; -import { startContinuePythonServer } from "./environmentSetup"; +import { +  getExtensionVersion, +  startContinuePythonServer, +} from "./environmentSetup"; +import fetch from "node-fetch";  // import { CapturedTerminal } from "../terminal/terminalEmulator"; +const PACKAGE_JSON_RAW_GITHUB_URL = +  "https://raw.githubusercontent.com/continuedev/continue/main/extension/package.json"; +  export let extensionContext: vscode.ExtensionContext | undefined = undefined;  export let ideProtocolClient: IdeProtocolClient; @@ -20,6 +27,19 @@ export async function activateExtension(  ) {    extensionContext = context; +  // Before anything else, check whether this is an out-of-date version of the extension +  // Do so by grabbing the package.json off of the GitHub respository for now. +  fetch(PACKAGE_JSON_RAW_GITHUB_URL) +    .then(async (res) => res.json()) +    .then((packageJson) => { +      if (packageJson.version !== getExtensionVersion()) { +        vscode.window.showInformationMessage( +          `You are using an out-of-date version of the Continue extension. Please update to the latest version.` +        ); +      } +    }) +    .catch((e) => console.log("Error checking for extension updates: ", e)); +    await new Promise((resolve, reject) => {      vscode.window.withProgress(        { diff --git a/extension/src/activation/environmentSetup.ts b/extension/src/activation/environmentSetup.ts index 02118501..c277a539 100644 --- a/extension/src/activation/environmentSetup.ts +++ b/extension/src/activation/environmentSetup.ts @@ -22,7 +22,7 @@ async function retryThenFail(      if (retries > 0) {        return await retryThenFail(fn, retries - 1);      } -    vscode.window.showErrorMessage( +    vscode.window.showInformationMessage(        "Failed to set up Continue extension. Please email nate@continue.dev and we'll get this fixed ASAP!"      );      sendTelemetryEvent(TelemetryEvent.ExtensionSetupError, { @@ -156,10 +156,7 @@ async function checkRequirementsInstalled() {          activateCmd,          `${pipCmd} uninstall -y continuedev`,        ].join(" ; "); -      const [, stderr] = await runCommand(removeOldVersionCommand); -      if (stderr) { -        throw new Error(stderr); -      } +      await runCommand(removeOldVersionCommand);        return false;      }    } @@ -224,6 +221,9 @@ async function setupPythonEnv() {        // First, try to run the command to install python3-venv        let [stdout, stderr] = await runCommand(`${pythonCmd} --version`);        if (stderr) { +        await vscode.window.showErrorMessage( +          "Python3 is not installed. Please install from https://www.python.org/downloads, reload VS Code, and try again." +        );          throw new Error(stderr);        }        const version = stdout.split(" ")[1].split(".")[1]; @@ -351,7 +351,7 @@ function requirementsVersionPath(): string {    return path.join(serverPath(), "requirements_version.txt");  } -function getExtensionVersion() { +export function getExtensionVersion() {    const extension = vscode.extensions.getExtension("continue.continue");    return extension?.packageJSON.version || "";  } @@ -366,24 +366,26 @@ export async function startContinuePythonServer() {    setupServerPath();    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..."); -      try { -        await fkill(":65432"); -      } catch (e) { -        console.log( -          "Failed to kill old server, likely because it didn't exist:", -          e -        ); +    // Kill the server if it is running an old version +    if (fs.existsSync(serverVersionPath())) { +      const serverVersion = fs.readFileSync(serverVersionPath(), "utf8"); +      if ( +        serverVersion === getExtensionVersion() && +        (await checkServerRunning(serverUrl)) +      ) { +        // The current version is already up and running, no need to continue +        return;        }      } +    console.log("Killing old server..."); +    try { +      await fkill(":65432"); +    } catch (e) { +      console.log( +        "Failed to kill old server, likely because it didn't exist:", +        e +      ); +    }      // Do this after above check so we don't have to waste time setting up the env      await setupPythonEnv(); diff --git a/extension/src/diffs.ts b/extension/src/diffs.ts index b9ef8384..3ea6b4f8 100644 --- a/extension/src/diffs.ts +++ b/extension/src/diffs.ts @@ -132,11 +132,18 @@ class DiffManager {        console.log("No corresponding diffInfo found for newFilepath");        return;      } -    fs.writeFileSync( -      diffInfo.originalFilepath, -      fs.readFileSync(diffInfo.newFilepath) -    ); -    this.cleanUpDiff(diffInfo); + +    // Save the right-side file, then copy over to original +    vscode.workspace.textDocuments +      .find((doc) => doc.uri.fsPath === newFilepath) +      ?.save() +      .then(() => { +        fs.writeFileSync( +          diffInfo.originalFilepath, +          fs.readFileSync(diffInfo.newFilepath) +        ); +        this.cleanUpDiff(diffInfo); +      });    }    rejectDiff(newFilepath?: string) { @@ -157,7 +164,12 @@ class DiffManager {      // Stop the step at step_index in case it is still streaming      ideProtocolClient.deleteAtIndex(diffInfo.step_index); -    this.cleanUpDiff(diffInfo); +    vscode.workspace.textDocuments +      .find((doc) => doc.uri.fsPath === newFilepath) +      ?.save() +      .then(() => { +        this.cleanUpDiff(diffInfo); +      });    }  } | 
