summaryrefslogtreecommitdiff
path: root/extension/src/activation
diff options
context:
space:
mode:
authorNate Sesti <sestinj@gmail.com>2023-06-26 16:39:07 -0700
committerNate Sesti <sestinj@gmail.com>2023-06-26 16:39:07 -0700
commitf3c6533d4054de5a71c8867c2b76fc8b0747447c (patch)
tree8e53ce9533aa42ee5d0a31504aa07be691d87157 /extension/src/activation
parentf403bbe26b8864ff5367eab08afe4a01fdde8e72 (diff)
parent292d4d10ce28d720d61f97918c490b0d9cdae9e7 (diff)
downloadsncontinue-f3c6533d4054de5a71c8867c2b76fc8b0747447c.tar.gz
sncontinue-f3c6533d4054de5a71c8867c2b76fc8b0747447c.tar.bz2
sncontinue-f3c6533d4054de5a71c8867c2b76fc8b0747447c.zip
Merge branch 'main' into styled-code
Diffstat (limited to 'extension/src/activation')
-rw-r--r--extension/src/activation/activate.ts52
-rw-r--r--extension/src/activation/environmentSetup.ts175
2 files changed, 116 insertions, 111 deletions
diff --git a/extension/src/activation/activate.ts b/extension/src/activation/activate.ts
index 32726c86..0c92f095 100644
--- a/extension/src/activation/activate.ts
+++ b/extension/src/activation/activate.ts
@@ -2,30 +2,31 @@ import * as vscode from "vscode";
import { registerAllCommands } from "../commands";
import { registerAllCodeLensProviders } from "../lang-server/codeLens";
import { sendTelemetryEvent, TelemetryEvent } from "../telemetry";
-import { getExtensionUri } from "../util/vscode";
-import * as path from "path";
// import { openCapturedTerminal } from "../terminal/terminalEmulator";
import IdeProtocolClient from "../continueIdeClient";
import { getContinueServerUrl } from "../bridge";
-import { setupDebugPanel, ContinueGUIWebviewViewProvider } from "../debugPanel";
import { CapturedTerminal } from "../terminal/terminalEmulator";
+import { setupDebugPanel, ContinueGUIWebviewViewProvider } from "../debugPanel";
+import { startContinuePythonServer } from "./environmentSetup";
+// import { CapturedTerminal } from "../terminal/terminalEmulator";
export let extensionContext: vscode.ExtensionContext | undefined = undefined;
export let ideProtocolClient: IdeProtocolClient;
-export function activateExtension(
+export async function activateExtension(
context: vscode.ExtensionContext,
showTutorial: boolean
) {
- sendTelemetryEvent(TelemetryEvent.ExtensionActivated);
+ extensionContext = context;
+ sendTelemetryEvent(TelemetryEvent.ExtensionActivated);
registerAllCodeLensProviders(context);
registerAllCommands(context);
// vscode.window.registerWebviewViewProvider("continue.continueGUIView", setupDebugPanel);
-
- let serverUrl = getContinueServerUrl();
+ await startContinuePythonServer();
+ const serverUrl = getContinueServerUrl();
ideProtocolClient = new IdeProtocolClient(
`${serverUrl.replace("http", "ws")}/ide/ws`,
@@ -49,41 +50,8 @@ export function activateExtension(
})();
// All opened terminals should be replaced by our own terminal
- vscode.window.onDidOpenTerminal((terminal) => {
- if (terminal.name === "Continue") {
- return;
- }
- const options = terminal.creationOptions;
- const capturedTerminal = new CapturedTerminal({
- ...options,
- name: "Continue",
- });
- terminal.dispose();
- if (!ideProtocolClient.continueTerminal) {
- ideProtocolClient.continueTerminal = capturedTerminal;
- }
- });
+ // vscode.window.onDidOpenTerminal((terminal) => {});
// If any terminals are open to start, replace them
- vscode.window.terminals.forEach((terminal) => {
- if (terminal.name === "Continue") {
- return;
- }
- const options = terminal.creationOptions;
- const capturedTerminal = new CapturedTerminal(
- {
- ...options,
- name: "Continue",
- },
- (commandOutput: string) => {
- ideProtocolClient.sendCommandOutput(commandOutput);
- }
- );
- terminal.dispose();
- if (!ideProtocolClient.continueTerminal) {
- ideProtocolClient.continueTerminal = capturedTerminal;
- }
- });
-
- extensionContext = context;
+ // vscode.window.terminals.forEach((terminal) => {}
}
diff --git a/extension/src/activation/environmentSetup.ts b/extension/src/activation/environmentSetup.ts
index 593b727e..25b6f643 100644
--- a/extension/src/activation/environmentSetup.ts
+++ b/extension/src/activation/environmentSetup.ts
@@ -7,6 +7,25 @@ import * as fs from "fs";
import rebuild from "@electron/rebuild";
import { getContinueServerUrl } from "../bridge";
import fetch from "node-fetch";
+import * as vscode from "vscode";
+
+const MAX_RETRIES = 5;
+async function retryThenFail(
+ fn: () => Promise<any>,
+ retries: number = MAX_RETRIES
+): Promise<any> {
+ try {
+ return await fn();
+ } catch (e) {
+ 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!"
+ );
+ throw e;
+ }
+}
async function runCommand(cmd: string): Promise<[string, string | undefined]> {
console.log("Running command: ", cmd);
@@ -77,55 +96,71 @@ function checkEnvExists() {
);
}
+function checkRequirementsInstalled() {
+ return fs.existsSync(
+ path.join(getExtensionUri().fsPath, "scripts", ".continue_env_installed")
+ );
+}
+
async function setupPythonEnv() {
console.log("Setting up python env for Continue extension...");
- if (checkEnvExists()) return;
-
- // Assemble the command to create the env
const [pythonCmd, pipCmd] = await getPythonPipCommands();
const [activateCmd, pipUpgradeCmd] = getActivateUpgradeCommands(
pythonCmd,
pipCmd
);
- const createEnvCommand = [
- `cd ${path.join(getExtensionUri().fsPath, "scripts")}`,
- `${pythonCmd} -m venv env`,
- ].join("; ");
- // Repeat until it is successfully created (sometimes it fails to generate the bin, need to try again)
- while (true) {
- const [, stderr] = await runCommand(createEnvCommand);
- if (stderr) {
- throw new Error(stderr);
- }
- if (checkEnvExists()) {
- break;
- } else {
- // Remove the env and try again
- const removeCommand = `rm -rf ${path.join(
- getExtensionUri().fsPath,
- "scripts",
- "env"
- )}`;
- await runCommand(removeCommand);
+ if (checkEnvExists()) {
+ console.log("Python env already exists, skipping...");
+ } else {
+ // Assemble the command to create the env
+ const createEnvCommand = [
+ `cd ${path.join(getExtensionUri().fsPath, "scripts")}`,
+ `${pythonCmd} -m venv env`,
+ ].join("; ");
+
+ // Repeat until it is successfully created (sometimes it fails to generate the bin, need to try again)
+ while (true) {
+ const [, stderr] = await runCommand(createEnvCommand);
+ if (stderr) {
+ throw new Error(stderr);
+ }
+ if (checkEnvExists()) {
+ break;
+ } else {
+ // Remove the env and try again
+ const removeCommand = `rm -rf ${path.join(
+ getExtensionUri().fsPath,
+ "scripts",
+ "env"
+ )}`;
+ await runCommand(removeCommand);
+ }
}
+ console.log(
+ "Successfully set up python env at ",
+ getExtensionUri().fsPath + "/scripts/env"
+ );
}
- console.log(
- "Successfully set up python env at ",
- getExtensionUri().fsPath + "/scripts/env"
- );
- const installRequirementsCommand = [
- `cd ${path.join(getExtensionUri().fsPath, "scripts")}`,
- activateCmd,
- pipUpgradeCmd,
- `${pipCmd} install -r requirements.txt`,
- ].join(" && ");
- const [, stderr] = await runCommand(installRequirementsCommand);
- if (stderr) {
- throw new Error(stderr);
- }
+ await retryThenFail(async () => {
+ if (checkRequirementsInstalled()) {
+ console.log("Python requirements already installed, skipping...");
+ } else {
+ const installRequirementsCommand = [
+ `cd ${path.join(getExtensionUri().fsPath, "scripts")}`,
+ activateCmd,
+ pipUpgradeCmd,
+ `${pipCmd} install -r requirements.txt`,
+ "touch .continue_env_installed",
+ ].join(" ; ");
+ const [, stderr] = await runCommand(installRequirementsCommand);
+ if (stderr) {
+ throw new Error(stderr);
+ }
+ }
+ });
}
function readEnvFile(path: string) {
@@ -180,15 +215,11 @@ export async function startContinuePythonServer() {
await setupPythonEnv();
// Check vscode settings
- let serverUrl = getContinueServerUrl();
+ const serverUrl = getContinueServerUrl();
if (serverUrl !== "http://localhost:8000") {
return;
}
- console.log("Starting Continue python server...");
-
- if (await checkServerRunning(serverUrl)) return;
-
let activateCmd = ". env/bin/activate";
let pythonCmd = "python3";
if (process.platform == "win32") {
@@ -199,35 +230,41 @@ export async function startContinuePythonServer() {
let command = `cd ${path.join(
getExtensionUri().fsPath,
"scripts"
- )} && ${activateCmd} && cd .. && ${pythonCmd} -m scripts.run_continue_server`;
+ )} ; ${activateCmd} ; cd .. ; ${pythonCmd} -m scripts.run_continue_server`;
+
+ return await retryThenFail(async () => {
+ console.log("Starting Continue python server...");
+
+ if (await checkServerRunning(serverUrl)) return;
- return new Promise(async (resolve, reject) => {
- try {
- const child = spawn(command, {
- shell: true,
- });
- child.stdout.on("data", (data: any) => {
- console.log(`stdout: ${data}`);
- });
- child.stderr.on("data", (data: any) => {
- console.log(`stderr: ${data}`);
- if (data.includes("Uvicorn running on")) {
- console.log("Successfully started Continue python server");
+ return new Promise(async (resolve, reject) => {
+ try {
+ const child = spawn(command, {
+ shell: true,
+ });
+ child.stdout.on("data", (data: any) => {
+ console.log(`stdout: ${data}`);
+ });
+ child.stderr.on("data", (data: any) => {
+ console.log(`stderr: ${data}`);
+ if (data.includes("Uvicorn running on")) {
+ console.log("Successfully started Continue python server");
+ resolve(null);
+ }
+ });
+ child.on("error", (error: any) => {
+ console.log(`error: ${error.message}`);
+ });
+ } catch (e) {
+ console.log("Failed to start Continue python server", e);
+ // If failed, check if it's because the server is already running (might have happened just after we checked above)
+ if (await checkServerRunning(serverUrl)) {
resolve(null);
+ } else {
+ reject();
}
- });
- child.on("error", (error: any) => {
- console.log(`error: ${error.message}`);
- });
- } catch (e) {
- console.log("Failed to start Continue python server", e);
- // If failed, check if it's because the server is already running (might have happened just after we checked above)
- if (await checkServerRunning(serverUrl)) {
- resolve(null);
- } else {
- reject();
}
- }
+ });
});
}
@@ -255,10 +292,10 @@ export async function downloadPython3() {
throw new Error("python3 not found");
} else if (os === "linux") {
command =
- "sudo apt update && upgrade && sudo apt install python3 python3-pip";
+ "sudo apt update ; upgrade ; sudo apt install python3 python3-pip";
} else if (os === "win32") {
command =
- "wget -O python_installer.exe https://www.python.org/ftp/python/3.11.3/python-3.11.3-amd64.exe && python_installer.exe /quiet InstallAllUsers=1 PrependPath=1 Include_test=0";
+ "wget -O python_installer.exe https://www.python.org/ftp/python/3.11.3/python-3.11.3-amd64.exe ; python_installer.exe /quiet InstallAllUsers=1 PrependPath=1 Include_test=0";
pythonCmd = "python";
}