From 475abad54ebb205ed574eb3de2640a0d19844b93 Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Tue, 1 Aug 2023 01:22:46 -0700 Subject: start executables from vscode extension --- extension/src/activation/environmentSetup.ts | 55 +++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) (limited to 'extension/src/activation/environmentSetup.ts') diff --git a/extension/src/activation/environmentSetup.ts b/extension/src/activation/environmentSetup.ts index 50a2783a..5e2e3c0f 100644 --- a/extension/src/activation/environmentSetup.ts +++ b/extension/src/activation/environmentSetup.ts @@ -427,7 +427,60 @@ export async function startContinuePythonServer() { return; } - setupServerPath(); + console.log("Checking if server is old version"); + // 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: any) { + if (!e.message.includes("Process doesn't exist")) { + console.log("Failed to kill old server:", e); + } + } + + // Get name of the corresponding executable for platform + const exeDir = path.join(getExtensionUri().fsPath, "server", "exe"); + let exePath: string; + if (os.platform() === "win32") { + exePath = path.join(exeDir, "run-win.exe"); + } else if (os.platform() === "darwin") { + exePath = path.join(exeDir, "run-darwin"); + await runCommand(`xattr -dr com.apple.quarantine ${exePath}`); + } else { + exePath = path.join(exeDir, "run-linux"); + } + + // Run the executable + const child = spawn(exePath, { + shell: true, + }); + child.stderr.on("data", (data: any) => { + console.log(data.toString()); + }); + + child.on("error", (error: any) => { + console.log(`error: ${error.message}`); + }); + + child.on("close", (code: any) => { + console.log(`child process exited with code ${code}`); + }); + + child.stdout.on("data", (data: any) => { + console.log(`stdout: ${data.toString()}`); + }); + + return; return await retryThenFail(async () => { console.log("Checking if server is old version"); -- cgit v1.2.3-70-g09d2 From 2a9d057c5b173c01977e3ae5299f685b474b1eab Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Tue, 1 Aug 2023 16:29:10 -0700 Subject: fixes to main.yaml, build nodejs --- .github/workflows/main.yaml | 162 +++++++++++++++------------ extension/server/.gitignore | 3 +- extension/server/exe/run-darwin | Bin 16421088 -> 0 bytes extension/server/exe/run-linux | Bin 28788480 -> 0 bytes extension/server/exe/run-win.exe | Bin 15593484 -> 0 bytes extension/src/activation/environmentSetup.ts | 2 + 6 files changed, 95 insertions(+), 72 deletions(-) delete mode 100755 extension/server/exe/run-darwin delete mode 100644 extension/server/exe/run-linux delete mode 100644 extension/server/exe/run-win.exe (limited to 'extension/src/activation/environmentSetup.ts') diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 24835d78..f866bf78 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -41,74 +41,94 @@ jobs: uses: actions/upload-artifact@v3 with: name: ${{ runner.os }} Build - path: dist/run - - # publish: - # runs-on: ubuntu-latest - - # steps: - # - name: Checkout - # uses: actions/checkout@v2 - - # - name: Set up Python - # uses: actions/setup-python@v2 - # with: - # python-version: "3.8" - - # - name: Install Poetry - # run: | - # curl -sSL https://install.python-poetry.org | python3 - - - # - name: Install Python dependencies - # run: | - # cd continuedev - # poetry install - - # - name: Cache extension node_modules - # uses: actions/cache@v2 - # with: - # path: extension/node_modules - # key: ${{ runner.os }}-node-${{ hashFiles('extension/package-lock.json') }} - - # - name: Cache react-app node_modules - # uses: actions/cache@v2 - # with: - # path: extension/react-app/node_modules - # key: ${{ runner.os }}-node-${{ hashFiles('extension/react-app/package-lock.json') }} - - # - name: Set up Node.js - # uses: actions/setup-node@v2 - # with: - # node-version: "14" - - # - name: Install extension Dependencies - # run: | - # cd extension - # npm ci --legacy-peer-deps - - # - name: Install react-app Dependencies - # run: | - # cd extension/react-app - # npm ci --legacy-peer-deps - - # - name: Build and Publish - # run: | - # cd extension - # npm run full-package - - # - name: Commit changes - # run: | - # git config --local user.email "action@github.com" - # git config --local user.name "GitHub Action" - # git commit -am "Update package.json version [skip ci]" - - # - name: Push changes - # uses: ad-m/github-push-action@master - # with: - # github_token: ${{ secrets.GITHUB_TOKEN }} - - # - name: Upload .vsix artifact - # uses: actions/upload-artifact@v2 - # with: - # name: vsix-artifact - # path: extension/build/* + path: dist/* + + publish: + needs: pyinstaller + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Download Linux build + uses: actions/download-artifact@v2 + with: + name: Linux Build + path: extension/server/exe/run-linux + + - name: Download macOS build + uses: actions/download-artifact@v2 + with: + name: macOS Build + path: extension/server/exe/run-darwin + + - name: Download Windows build + uses: actions/download-artifact@v2 + with: + name: Windows Build + path: extension/server/exe/run-windows.exe + + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: "3.8" + + - name: Install Poetry + run: | + curl -sSL https://install.python-poetry.org | python3 - + + - name: Install Python dependencies + run: | + cd continuedev + poetry install + + - name: Cache extension node_modules + uses: actions/cache@v2 + with: + path: extension/node_modules + key: ${{ runner.os }}-node-${{ hashFiles('extension/package-lock.json') }} + + - name: Cache react-app node_modules + uses: actions/cache@v2 + with: + path: extension/react-app/node_modules + key: ${{ runner.os }}-node-${{ hashFiles('extension/react-app/package-lock.json') }} + + - name: Set up Node.js + uses: actions/setup-node@v2 + with: + node-version: "14" + + - name: Install extension Dependencies + run: | + cd extension + npm ci --legacy-peer-deps + + - name: Install react-app Dependencies + run: | + cd extension/react-app + npm ci --legacy-peer-deps + + - name: Build and Publish + run: | + cd extension + npm run full-package + + - name: Commit changes + run: | + git config --local user.email "action@github.com" + git config --local user.name "GitHub Action" + git commit -am "Update package.json version [skip ci]" + + - name: Push changes + uses: ad-m/github-push-action@master + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + branch: ${{ github.ref }} + + - name: Upload .vsix artifact + uses: actions/upload-artifact@v2 + with: + name: vsix-artifact + path: extension/build/* diff --git a/extension/server/.gitignore b/extension/server/.gitignore index 0b6e11dd..d501b5cd 100644 --- a/extension/server/.gitignore +++ b/extension/server/.gitignore @@ -1 +1,2 @@ -**.whl \ No newline at end of file +**.whl +exe/** \ No newline at end of file diff --git a/extension/server/exe/run-darwin b/extension/server/exe/run-darwin deleted file mode 100755 index 4d8323ef..00000000 Binary files a/extension/server/exe/run-darwin and /dev/null differ diff --git a/extension/server/exe/run-linux b/extension/server/exe/run-linux deleted file mode 100644 index 3efe5633..00000000 Binary files a/extension/server/exe/run-linux and /dev/null differ diff --git a/extension/server/exe/run-win.exe b/extension/server/exe/run-win.exe deleted file mode 100644 index 30466272..00000000 Binary files a/extension/server/exe/run-win.exe and /dev/null differ diff --git a/extension/src/activation/environmentSetup.ts b/extension/src/activation/environmentSetup.ts index 5e2e3c0f..a0d6a653 100644 --- a/extension/src/activation/environmentSetup.ts +++ b/extension/src/activation/environmentSetup.ts @@ -455,6 +455,8 @@ export async function startContinuePythonServer() { exePath = path.join(exeDir, "run-win.exe"); } else if (os.platform() === "darwin") { exePath = path.join(exeDir, "run-darwin"); + // Add permissions + await runCommand(`chmod +x ${exePath}`); await runCommand(`xattr -dr com.apple.quarantine ${exePath}`); } else { exePath = path.join(exeDir, "run-linux"); -- cgit v1.2.3-70-g09d2 From 10e5b827147541d0911ea66a00d7953d33801ea9 Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Tue, 1 Aug 2023 18:53:27 -0700 Subject: fix exe paths --- .github/workflows/main.yaml | 6 +++--- extension/src/activation/environmentSetup.ts | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'extension/src/activation/environmentSetup.ts') diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 872470d0..d9bba4cd 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -57,19 +57,19 @@ jobs: uses: actions/download-artifact@v2 with: name: Linux Build - path: extension/server/exe/run-linux + path: extension/server/exe/linux - name: Download macOS build uses: actions/download-artifact@v2 with: name: macOS Build - path: extension/server/exe/run-darwin + path: extension/server/exe/mac - name: Download Windows build uses: actions/download-artifact@v2 with: name: Windows Build - path: extension/server/exe/run-windows.exe + path: extension/server/exe/windows - name: Use Node.js 19.0.0 uses: actions/setup-node@v3 diff --git a/extension/src/activation/environmentSetup.ts b/extension/src/activation/environmentSetup.ts index a0d6a653..56d5a628 100644 --- a/extension/src/activation/environmentSetup.ts +++ b/extension/src/activation/environmentSetup.ts @@ -452,14 +452,14 @@ export async function startContinuePythonServer() { const exeDir = path.join(getExtensionUri().fsPath, "server", "exe"); let exePath: string; if (os.platform() === "win32") { - exePath = path.join(exeDir, "run-win.exe"); + exePath = path.join(exeDir, "windows", "run.exe"); } else if (os.platform() === "darwin") { - exePath = path.join(exeDir, "run-darwin"); + exePath = path.join(exeDir, "mac", "run"); // Add permissions await runCommand(`chmod +x ${exePath}`); await runCommand(`xattr -dr com.apple.quarantine ${exePath}`); } else { - exePath = path.join(exeDir, "run-linux"); + exePath = path.join(exeDir, "linux", "run"); } // Run the executable -- cgit v1.2.3-70-g09d2 From 0a7cd1d0820c5f496157b9f85200dbe911b6fc8a Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Tue, 1 Aug 2023 20:56:51 -0700 Subject: purge unecessary functions in envSetup (finally) --- .github/workflows/main.yaml | 2 +- extension/DEV_README.md | 2 +- extension/package.json | 6 +- extension/scripts/install_from_source.py | 2 +- extension/src/README.md | 3 +- extension/src/activation/environmentSetup.ts | 421 ++------------------------- 6 files changed, 24 insertions(+), 412 deletions(-) (limited to 'extension/src/activation/environmentSetup.ts') diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index d9bba4cd..dc670137 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -106,7 +106,7 @@ jobs: - name: Build and Publish run: | cd extension - npm run full-package + npm run package # - name: Commit changes # run: | diff --git a/extension/DEV_README.md b/extension/DEV_README.md index 72ea5c6a..8e244bc3 100644 --- a/extension/DEV_README.md +++ b/extension/DEV_README.md @@ -10,7 +10,7 @@ This is the Continue VS Code Extension. Its primary jobs are 1. Clone this repo 2. `cd extension` -3. `npm run full-package` +3. `npm run package` > If NPM is not installed, you can use `brew install node` on Mac, or see the [installation page](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm) for other platforms, or more detailed instructions. diff --git a/extension/package.json b/extension/package.json index fcf2c1a8..d350b3ee 100644 --- a/extension/package.json +++ b/extension/package.json @@ -226,11 +226,7 @@ "test": "node ./out/test/runTest.js", "jest": "jest --config ./jest.config.js", "typegen": "node scripts/typegen.js", - "package": "mkdir -p ./build && vsce package --out ./build", - "full-package": "npm install && npm run typegen && npm run clientgen && cd react-app && npm install && npm run build && cd .. && npm run package", - "install-extension": "code --install-extension ./build/continue-0.0.8.vsix", - "uninstall": "code --uninstall-extension .continue", - "reinstall": "rm -rf ./build && npm run package && npm run uninstall && npm run install-extension" + "package": "npm install && npm run typegen && npm run clientgen && cd react-app && npm install && npm run build && cd .. && mkdir -p ./build && vsce package --out ./build" }, "devDependencies": { "@nestjs/common": "^8.4.7", diff --git a/extension/scripts/install_from_source.py b/extension/scripts/install_from_source.py index d004259b..5e16bf21 100644 --- a/extension/scripts/install_from_source.py +++ b/extension/scripts/install_from_source.py @@ -53,7 +53,7 @@ def main(): resp = run("cd ../../continuedev; poetry install; poetry run typegen") resp = run( - "cd ..; npm i; cd react-app; npm i; cd ..; npm run full-package") + "cd ..; npm i; cd react-app; npm i; cd ..; npm run package") if resp.stderr: print("Error packaging the extension. Please try again.") diff --git a/extension/src/README.md b/extension/src/README.md index 4969890f..ef90c31b 100644 --- a/extension/src/README.md +++ b/extension/src/README.md @@ -12,7 +12,7 @@ 5. From `continue/extension`, run `npm install` -6. Run `npm run full-package` +6. Run `npm run package` 7. Open `src/activation/activate.ts` file (or any TypeScript file) @@ -22,7 +22,6 @@ 10. Every time you make changes to the code, you need to run `npm run esbuild` unless you make changes inside of `react-app` and then you need to run `npm run build` from there - ## Alternative: Install from source Update: directions to root README diff --git a/extension/src/activation/environmentSetup.ts b/extension/src/activation/environmentSetup.ts index 56d5a628..01fd2e5c 100644 --- a/extension/src/activation/environmentSetup.ts +++ b/extension/src/activation/environmentSetup.ts @@ -10,65 +10,6 @@ import * as vscode from "vscode"; import * as os from "os"; import fkill from "fkill"; -const WINDOWS_REMOTE_SIGNED_SCRIPTS_ERROR = - "A Python virtual enviroment cannot be activated because running scripts is disabled for this user. In order to use Continue, please enable signed scripts to run with this command in PowerShell: `Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser`, reload VS Code, and then try again."; - -const MAX_RETRIES = 3; -async function retryThenFail( - fn: () => Promise, - retries: number = MAX_RETRIES -): Promise { - try { - if (retries < MAX_RETRIES && process.platform === "win32") { - let [stdout, stderr] = await runCommand("Get-ExecutionPolicy"); - if (!stdout.includes("RemoteSigned")) { - [stdout, stderr] = await runCommand( - "Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser" - ); - console.log("Execution policy stdout: ", stdout); - console.log("Execution policy stderr: ", stderr); - } - } - - return await fn(); - } catch (e: any) { - if (retries > 0) { - return await retryThenFail(fn, retries - 1); - } - - // Show corresponding error message depending on the platform - let msg = - "Failed to set up Continue extension. Please email hi@continue.dev and we'll get this fixed ASAP!"; - try { - switch (process.platform) { - case "win32": - msg = WINDOWS_REMOTE_SIGNED_SCRIPTS_ERROR; - break; - case "darwin": - break; - case "linux": - const [pythonCmd] = await getPythonPipCommands(); - msg = await getLinuxAptInstallError(pythonCmd); - break; - } - } finally { - console.log("After retries, failed to set up Continue extension", msg); - vscode.window - .showErrorMessage(msg, "View Logs", "Retry") - .then((selection) => { - if (selection === "View Logs") { - vscode.commands.executeCommand("continue.viewLogs"); - } else if (selection === "Retry") { - // Reload VS Code window - vscode.commands.executeCommand("workbench.action.reloadWindow"); - } - }); - } - - throw e; - } -} - async function runCommand(cmd: string): Promise<[string, string | undefined]> { console.log("Running command: ", cmd); var stdout: any = ""; @@ -147,216 +88,6 @@ export async function getPythonPipCommands() { return [pythonCmd, pipCmd]; } -function getActivateUpgradeCommands(pythonCmd: string, pipCmd: string) { - let activateCmd = ". env/bin/activate"; - let pipUpgradeCmd = `${pipCmd} install --upgrade pip`; - if (process.platform == "win32") { - activateCmd = ".\\env\\Scripts\\activate"; - pipUpgradeCmd = `${pythonCmd} -m pip install --upgrade pip`; - } - return [activateCmd, pipUpgradeCmd]; -} - -function checkEnvExists() { - const envBinPath = path.join( - serverPath(), - "env", - process.platform == "win32" ? "Scripts" : "bin" - ); - return ( - fs.existsSync(path.join(envBinPath, "activate")) && - fs.existsSync( - path.join(envBinPath, process.platform == "win32" ? "pip.exe" : "pip") - ) - ); -} - -async function checkRequirementsInstalled() { - // First, check if the requirements have been installed most recently for a later version of the extension - if (fs.existsSync(requirementsVersionPath())) { - const requirementsVersion = fs.readFileSync( - requirementsVersionPath(), - "utf8" - ); - if (requirementsVersion !== getExtensionVersion()) { - // Remove the old version of continuedev from site-packages - const [pythonCmd, pipCmd] = await getPythonPipCommands(); - const [activateCmd] = getActivateUpgradeCommands(pythonCmd, pipCmd); - const removeOldVersionCommand = [ - `cd "${serverPath()}"`, - activateCmd, - `${pipCmd} uninstall -y continuedev`, - ].join(" ; "); - await runCommand(removeOldVersionCommand); - return false; - } - } - - let envLibsPath = path.join( - serverPath(), - "env", - process.platform == "win32" ? "Lib" : "lib" - ); - // If site-packages is directly under env, use that - if (fs.existsSync(path.join(envLibsPath, "site-packages"))) { - envLibsPath = path.join(envLibsPath, "site-packages"); - } else { - // Get the python version folder name - const pythonVersions = fs.readdirSync(envLibsPath).filter((f: string) => { - return f.startsWith("python"); - }); - if (pythonVersions.length == 0) { - return false; - } - const pythonVersion = pythonVersions[0]; - envLibsPath = path.join(envLibsPath, pythonVersion, "site-packages"); - } - - const continuePath = path.join(envLibsPath, "continuedev"); - - return fs.existsSync(continuePath); -} - -async function getLinuxAptInstallError(pythonCmd: string) { - // 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]; - const installVenvCommand = `apt-get install python3.${version}-venv`; - await runCommand("apt-get update"); - return `[Important] Continue needs to create a Python virtual environment, but python3.${version}-venv is not installed. Please run this command in your terminal: \`${installVenvCommand}\`, reload VS Code, and then try again.`; -} - -async function createPythonVenv(pythonCmd: string) { - if (checkEnvExists()) { - console.log("Python env already exists, skipping..."); - } else { - // Assemble the command to create the env - const createEnvCommand = [ - `cd "${serverPath()}"`, - `${pythonCmd} -m venv env`, - ].join(" ; "); - - const [stdout, stderr] = await runCommand(createEnvCommand); - if ( - stderr && - stderr.includes("running scripts is disabled on this system") - ) { - console.log("Scripts disabled error when trying to create env"); - await vscode.window.showErrorMessage(WINDOWS_REMOTE_SIGNED_SCRIPTS_ERROR); - throw new Error(stderr); - } else if ( - stderr?.includes("On Debian/Ubuntu systems") || - stdout?.includes("On Debian/Ubuntu systems") - ) { - const msg = await getLinuxAptInstallError(pythonCmd); - console.log(msg); - await vscode.window.showErrorMessage(msg); - } else if (checkEnvExists()) { - console.log("Successfully set up python env at ", `${serverPath()}/env`); - } else if ( - stderr?.includes("Permission denied") && - stderr?.includes("python.exe") - ) { - // This might mean that another window is currently using the python.exe file to install requirements - // So we want to wait and try again - let i = 0; - await new Promise((resolve, reject) => - setInterval(() => { - if (i > 5) { - reject("Timed out waiting for other window to create env..."); - } - if (checkEnvExists()) { - resolve(null); - } else { - console.log("Waiting for other window to create env..."); - } - i++; - }, 5000) - ); - } else { - const msg = [ - "Python environment not successfully created. Trying again. Here was the stdout + stderr: ", - `stdout: ${stdout}`, - `stderr: ${stderr}`, - ].join("\n\n"); - console.log(msg); - throw new Error(msg); - } - } -} - -async function setupPythonEnv() { - console.log("Setting up python env for Continue extension..."); - - const [pythonCmd, pipCmd] = await getPythonPipCommands(); - const [activateCmd, pipUpgradeCmd] = getActivateUpgradeCommands( - pythonCmd, - pipCmd - ); - - await retryThenFail(async () => { - // First, create the virtual environment - await createPythonVenv(pythonCmd); - - // Install the requirements - if (await checkRequirementsInstalled()) { - console.log("Python requirements already installed, skipping..."); - } else { - const installRequirementsCommand = [ - `cd "${serverPath()}"`, - activateCmd, - pipUpgradeCmd, - `${pipCmd} install -r requirements.txt`, - ].join(" ; "); - const [, stderr] = await runCommand(installRequirementsCommand); - if (stderr) { - throw new Error(stderr); - } - // Write the version number for which requirements were installed - fs.writeFileSync(requirementsVersionPath(), getExtensionVersion()); - } - }); -} - -function readEnvFile(path: string) { - if (!fs.existsSync(path)) { - return {}; - } - let envFile = fs.readFileSync(path, "utf8"); - - let env: { [key: string]: string } = {}; - envFile.split("\n").forEach((line) => { - let [key, value] = line.split("="); - if (typeof key === "undefined" || typeof value === "undefined") { - return; - } - env[key] = value.replace(/"/g, ""); - }); - return env; -} - -function writeEnvFile(path: string, key: string, value: string) { - if (!fs.existsSync(path)) { - fs.writeFileSync(path, `${key}="${value}"`); - return; - } - - let env = readEnvFile(path); - env[key] = value; - - let newEnvFile = ""; - for (let key in env) { - newEnvFile += `${key}="${env[key]}"\n`; - } - fs.writeFileSync(path, newEnvFile); -} - async function checkServerRunning(serverUrl: string): Promise { // Check if already running by calling /health try { @@ -381,16 +112,6 @@ export function getContinueGlobalPath(): string { return continuePath; } -function setupServerPath() { - const sPath = serverPath(); - const extensionServerPath = path.join(getExtensionUri().fsPath, "server"); - const files = fs.readdirSync(extensionServerPath); - files.forEach((file) => { - const filePath = path.join(extensionServerPath, file); - fs.copyFileSync(filePath, path.join(sPath, file)); - }); -} - function serverPath(): string { const sPath = path.join(getContinueGlobalPath(), "server"); if (!fs.existsSync(sPath)) { @@ -411,22 +132,13 @@ function serverVersionPath(): string { return path.join(serverPath(), "server_version.txt"); } -function requirementsVersionPath(): string { - return path.join(serverPath(), "requirements_version.txt"); -} - export function getExtensionVersion() { const extension = vscode.extensions.getExtension("continue.continue"); return extension?.packageJSON.version || ""; } -export async function startContinuePythonServer() { - // Check vscode settings - const serverUrl = getContinueServerUrl(); - if (serverUrl !== "http://localhost:65432") { - return; - } - +// Returns whether a server of the current version is already running +async function checkOrKillRunningServer(serverUrl: string): Promise { console.log("Checking if server is old version"); // Kill the server if it is running an old version if (fs.existsSync(serverVersionPath())) { @@ -436,7 +148,7 @@ export async function startContinuePythonServer() { (await checkServerRunning(serverUrl)) ) { // The current version is already up and running, no need to continue - return; + return true; } } console.log("Killing old server..."); @@ -447,6 +159,20 @@ export async function startContinuePythonServer() { console.log("Failed to kill old server:", e); } } + return false; +} + +export async function startContinuePythonServer() { + // Check vscode settings + const serverUrl = getContinueServerUrl(); + if (serverUrl !== "http://localhost:65432") { + return; + } + + // Check if server is already running + if (await checkOrKillRunningServer(serverUrl)) { + return; + } // Get name of the corresponding executable for platform const exeDir = path.join(getExtensionUri().fsPath, "server", "exe"); @@ -482,115 +208,6 @@ export async function startContinuePythonServer() { console.log(`stdout: ${data.toString()}`); }); - return; - - return await retryThenFail(async () => { - console.log("Checking if server is old version"); - // 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: any) { - if (!e.message.includes("Process doesn't exist")) { - console.log("Failed to kill old server:", e); - } - } - - // Do this after above check so we don't have to waste time setting up the env - await setupPythonEnv(); - - // Spawn the server process on port 65432 - const [pythonCmd] = await getPythonPipCommands(); - const activateCmd = - process.platform == "win32" - ? ".\\env\\Scripts\\activate" - : ". env/bin/activate"; - - const command = `cd "${serverPath()}" && ${activateCmd} && cd .. && ${pythonCmd} -m server.run_continue_server`; - - return new Promise(async (resolve, reject) => { - console.log("Starting Continue python server..."); - try { - const child = spawn(command, { - shell: true, - }); - child.stderr.on("data", (data: any) => { - if ( - data.includes("Uvicorn running on") || // Successfully started the server - data.includes("only one usage of each socket address") || // [windows] The server is already running (probably a simultaneously opened VS Code window) - data.includes("address already in use") // [mac/linux] The server is already running (probably a simultaneously opened VS Code window) - ) { - console.log("Successfully started Continue python server"); - resolve(null); - } else if (data.includes("ERROR") || data.includes("Traceback")) { - console.log("Error starting Continue python server: ", data); - } else { - console.log(`stdout: ${data}`); - } - }); - child.on("error", (error: any) => { - console.log(`error: ${error.message}`); - }); - - child.on("close", (code: any) => { - console.log(`child process exited with code ${code}`); - }); - - child.stdout.on("data", (data: any) => { - console.log(`stdout: ${data}`); - }); - - // Write the current version of vscode to a file called server_version.txt - fs.writeFileSync(serverVersionPath(), getExtensionVersion()); - } 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(); - } - } - }); - }); -} - -export function isPythonEnvSetup(): boolean { - const pathToEnvCfg = path.join(serverPath(), "env", "pyvenv.cfg"); - return fs.existsSync(pathToEnvCfg); -} - -export async function downloadPython3() { - // Download python3 and return the command to run it (python or python3) - let os = process.platform; - let command: string = ""; - let pythonCmd = "python3"; - if (os === "darwin") { - throw new Error("python3 not found"); - } else if (os === "linux") { - command = - "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"; - pythonCmd = "python"; - } - - var [stdout, stderr] = await runCommand(command); - if (stderr) { - throw new Error(stderr); - } - console.log("Successfully downloaded python3"); - - return pythonCmd; + // Write the current version of vscode extension to a file called server_version.txt + fs.writeFileSync(serverVersionPath(), getExtensionVersion()); } -- cgit v1.2.3-70-g09d2 From 7d2e13c5b29f9b7f93f009f464a253afc6bd4fe8 Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Wed, 2 Aug 2023 20:31:02 -0700 Subject: download binary from s3 bucket --- extension/src/activation/environmentSetup.ts | 48 +++++++++++++++++++++------- 1 file changed, 36 insertions(+), 12 deletions(-) (limited to 'extension/src/activation/environmentSetup.ts') diff --git a/extension/src/activation/environmentSetup.ts b/extension/src/activation/environmentSetup.ts index 01fd2e5c..b3482a92 100644 --- a/extension/src/activation/environmentSetup.ts +++ b/extension/src/activation/environmentSetup.ts @@ -162,6 +162,20 @@ async function checkOrKillRunningServer(serverUrl: string): Promise { return false; } +export async function downloadFromS3( + bucket: string, + fileName: string, + destination: string +) { + const s3Url = `https://${bucket}.s3.amazonaws.com/${fileName}`; + const response = await fetch(s3Url); + if (!response.ok) { + throw new Error(`HTTP error! status: ${response.status}`); + } + const buffer = await response.buffer(); + fs.writeFileSync(destination, buffer); +} + export async function startContinuePythonServer() { // Check vscode settings const serverUrl = getContinueServerUrl(); @@ -174,22 +188,32 @@ export async function startContinuePythonServer() { return; } + // Download the server executable + const bucket = "continue-server-binaries"; + const fileName = `extension/exe/${ + os.platform() === "win32" + ? "windows/run.exe" + : os.platform() === "darwin" + ? "mac/run" + : "linux/run" + }`; + const destination = path.join( + getExtensionUri().fsPath, + "server", + "exe", + "run" + ); + await downloadFromS3(bucket, fileName, destination); + // Get name of the corresponding executable for platform - const exeDir = path.join(getExtensionUri().fsPath, "server", "exe"); - let exePath: string; - if (os.platform() === "win32") { - exePath = path.join(exeDir, "windows", "run.exe"); - } else if (os.platform() === "darwin") { - exePath = path.join(exeDir, "mac", "run"); - // Add permissions - await runCommand(`chmod +x ${exePath}`); - await runCommand(`xattr -dr com.apple.quarantine ${exePath}`); - } else { - exePath = path.join(exeDir, "linux", "run"); + if (os.platform() === "darwin") { + // Add necessary permissions + await runCommand(`chmod +x ${destination}`); + await runCommand(`xattr -dr com.apple.quarantine ${destination}`); } // Run the executable - const child = spawn(exePath, { + const child = spawn(destination, { shell: true, }); child.stderr.on("data", (data: any) => { -- cgit v1.2.3-70-g09d2 From 5c111f75717e542ec0be9b73b2ee1f1e495c629c Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Wed, 2 Aug 2023 21:27:35 -0700 Subject: cleaning environmentSetup --- extension/src/activation/activate.ts | 47 +++--------- extension/src/activation/environmentSetup.ts | 106 ++++++++++----------------- extension/src/bridge.ts | 2 +- extension/src/continueIdeClient.ts | 7 -- extension/src/debugPanel.ts | 2 +- extension/src/util/messenger.ts | 1 - 6 files changed, 52 insertions(+), 113 deletions(-) (limited to 'extension/src/activation/environmentSetup.ts') 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 { // 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 { 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("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); -- cgit v1.2.3-70-g09d2 From a4f3ae9f7fe29036cdbea0d48491ae8d106a359c Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Wed, 2 Aug 2023 21:57:44 -0700 Subject: make sure directory exists before downloading --- extension/src/activation/environmentSetup.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'extension/src/activation/environmentSetup.ts') diff --git a/extension/src/activation/environmentSetup.ts b/extension/src/activation/environmentSetup.ts index fd83c8ca..b25c7b82 100644 --- a/extension/src/activation/environmentSetup.ts +++ b/extension/src/activation/environmentSetup.ts @@ -105,6 +105,15 @@ async function checkOrKillRunningServer(serverUrl: string): Promise { return false; } +function ensureDirectoryExistence(filePath: string) { + const dirname = path.dirname(filePath); + if (fs.existsSync(dirname)) { + return true; + } + ensureDirectoryExistence(dirname); + fs.mkdirSync(dirname); +} + export async function downloadFromS3( bucket: string, fileName: string, @@ -122,6 +131,7 @@ export async function downloadFromS3( throw new Error(errText); } const buffer = await response.buffer(); + ensureDirectoryExistence(destination); fs.writeFileSync(destination, buffer); } -- cgit v1.2.3-70-g09d2 From fdb043a2320abcea3f9c835c6dcdec0050e89553 Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Wed, 2 Aug 2023 22:20:26 -0700 Subject: logging --- .github/workflows/main.yaml | 24 ++++++++++++------------ extension/src/activation/environmentSetup.ts | 17 ++++++++++++++--- 2 files changed, 26 insertions(+), 15 deletions(-) (limited to 'extension/src/activation/environmentSetup.ts') diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 8610f363..67d248e2 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -113,18 +113,18 @@ jobs: run: | cd extension npm run package - npx vsce publish patch -p ${{ secrets.VSCE_TOKEN }} - - name: Commit changes - run: | - git config --local user.email "action@github.com" - git config --local user.name "GitHub Action" - git commit -am "ci: 💚 Update package.json version [skip ci]" - - - name: Push changes - uses: ad-m/github-push-action@master - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - branch: ${{ github.ref }} + # npx vsce publish patch -p ${{ secrets.VSCE_TOKEN }} + # - name: Commit changes + # run: | + # git config --local user.email "action@github.com" + # git config --local user.name "GitHub Action" + # git commit -am "ci: 💚 Update package.json version [skip ci]" + + # - name: Push changes + # uses: ad-m/github-push-action@master + # with: + # github_token: ${{ secrets.GITHUB_TOKEN }} + # branch: ${{ github.ref }} - name: Upload .vsix artifact uses: actions/upload-artifact@v2 diff --git a/extension/src/activation/environmentSetup.ts b/extension/src/activation/environmentSetup.ts index b25c7b82..6bfa7d07 100644 --- a/extension/src/activation/environmentSetup.ts +++ b/extension/src/activation/environmentSetup.ts @@ -139,16 +139,17 @@ export async function startContinuePythonServer() { // Check vscode settings const serverUrl = getContinueServerUrl(); if (serverUrl !== "http://localhost:65432") { + console.log("Continue server is being run manually, skipping start"); return; } // Check if server is already running if (await checkOrKillRunningServer(serverUrl)) { + console.log("Continue server already running"); return; } // Download the server executable - const bucket = "continue-server-binaries"; const fileName = os.platform() === "win32" @@ -189,14 +190,24 @@ export async function startContinuePythonServer() { ); } + console.log("Downloaded server executable at ", destination); // Get name of the corresponding executable for platform if (os.platform() === "darwin") { // Add necessary permissions - await runCommand(`chmod +x ${destination}`); - await runCommand(`xattr -dr com.apple.quarantine ${destination}`); + const [stdout, stderr] = await runCommand(`chmod +x ${destination}`); + console.log("Setting permissions for Continue server..."); + console.log(stdout); + console.log(stderr); + const [stdout1, stderr1] = await runCommand( + `xattr -dr com.apple.quarantine ${destination}` + ); + console.log("..."); + console.log(stdout1); + console.log(stderr1); } // Run the executable + console.log("Starting Continue server..."); const child = spawn(destination, { shell: true, }); -- cgit v1.2.3-70-g09d2 From 0e6a0c94254de045bf3c722089228b0e033f7255 Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Wed, 2 Aug 2023 22:40:54 -0700 Subject: await file download --- .github/workflows/main.yaml | 24 ++++++++++++------------ extension/src/activation/environmentSetup.ts | 11 ++++------- 2 files changed, 16 insertions(+), 19 deletions(-) (limited to 'extension/src/activation/environmentSetup.ts') diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 67d248e2..8610f363 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -113,18 +113,18 @@ jobs: run: | cd extension npm run package - # npx vsce publish patch -p ${{ secrets.VSCE_TOKEN }} - # - name: Commit changes - # run: | - # git config --local user.email "action@github.com" - # git config --local user.name "GitHub Action" - # git commit -am "ci: 💚 Update package.json version [skip ci]" - - # - name: Push changes - # uses: ad-m/github-push-action@master - # with: - # github_token: ${{ secrets.GITHUB_TOKEN }} - # branch: ${{ github.ref }} + npx vsce publish patch -p ${{ secrets.VSCE_TOKEN }} + - name: Commit changes + run: | + git config --local user.email "action@github.com" + git config --local user.name "GitHub Action" + git commit -am "ci: 💚 Update package.json version [skip ci]" + + - name: Push changes + uses: ad-m/github-push-action@master + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + branch: ${{ github.ref }} - name: Upload .vsix artifact uses: actions/upload-artifact@v2 diff --git a/extension/src/activation/environmentSetup.ts b/extension/src/activation/environmentSetup.ts index 6bfa7d07..a1c4f7ee 100644 --- a/extension/src/activation/environmentSetup.ts +++ b/extension/src/activation/environmentSetup.ts @@ -178,7 +178,7 @@ export async function startContinuePythonServer() { } if (shouldDownload) { - vscode.window.withProgress( + await vscode.window.withProgress( { location: vscode.ProgressLocation.Notification, title: "Installing Continue server...", @@ -194,16 +194,13 @@ export async function startContinuePythonServer() { // Get name of the corresponding executable for platform if (os.platform() === "darwin") { // Add necessary permissions - const [stdout, stderr] = await runCommand(`chmod +x ${destination}`); console.log("Setting permissions for Continue server..."); - console.log(stdout); - console.log(stderr); + fs.chmodSync(destination, 0o7_5_5); const [stdout1, stderr1] = await runCommand( `xattr -dr com.apple.quarantine ${destination}` ); - console.log("..."); - console.log(stdout1); - console.log(stderr1); + console.log("stdout: ", stdout1); + console.log("stderr: ", stderr1); } // Run the executable -- cgit v1.2.3-70-g09d2 From df58e7902c757bc693e953dc57e1f2dff5a2957b Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Wed, 2 Aug 2023 23:12:25 -0700 Subject: add .exe file extension --- extension/src/activation/environmentSetup.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'extension/src/activation/environmentSetup.ts') diff --git a/extension/src/activation/environmentSetup.ts b/extension/src/activation/environmentSetup.ts index a1c4f7ee..20d1df35 100644 --- a/extension/src/activation/environmentSetup.ts +++ b/extension/src/activation/environmentSetup.ts @@ -162,7 +162,7 @@ export async function startContinuePythonServer() { getExtensionUri().fsPath, "server", "exe", - "run" + "run" + (os.platform() === "win32" ? ".exe" : "") ); // First, check if the server is already downloaded -- cgit v1.2.3-70-g09d2 From 4421a3e9c2098b5b2793449a03cdf390e81aa460 Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Wed, 2 Aug 2023 23:15:48 -0700 Subject: add .exe on windows --- extension/src/activation/environmentSetup.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'extension/src/activation/environmentSetup.ts') diff --git a/extension/src/activation/environmentSetup.ts b/extension/src/activation/environmentSetup.ts index 20d1df35..8d9578e8 100644 --- a/extension/src/activation/environmentSetup.ts +++ b/extension/src/activation/environmentSetup.ts @@ -162,7 +162,7 @@ export async function startContinuePythonServer() { getExtensionUri().fsPath, "server", "exe", - "run" + (os.platform() === "win32" ? ".exe" : "") + `run${os.platform() === "win32" ? ".exe" : ""}` ); // First, check if the server is already downloaded @@ -203,6 +203,13 @@ export async function startContinuePythonServer() { console.log("stderr: ", stderr1); } + // Validate that the file exists + if (!fs.existsSync(destination)) { + const errText = `- Failed to install Continue server.`; + vscode.window.showErrorMessage(errText); + throw new Error(errText); + } + // Run the executable console.log("Starting Continue server..."); const child = spawn(destination, { -- cgit v1.2.3-70-g09d2 From bfd2f09cd6ebdc18e8162555a1859f0098b14cd3 Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Thu, 3 Aug 2023 01:11:41 -0700 Subject: small fixes to setup --- continuedev/src/continuedev/libs/util/paths.py | 20 ++++++++++++-------- extension/src/activation/environmentSetup.ts | 20 ++++++++++---------- 2 files changed, 22 insertions(+), 18 deletions(-) (limited to 'extension/src/activation/environmentSetup.ts') diff --git a/continuedev/src/continuedev/libs/util/paths.py b/continuedev/src/continuedev/libs/util/paths.py index 1e11898f..83a472ad 100644 --- a/continuedev/src/continuedev/libs/util/paths.py +++ b/continuedev/src/continuedev/libs/util/paths.py @@ -36,16 +36,20 @@ def getConfigFilePath() -> str: path = os.path.join(getGlobalFolderPath(), "config.py") os.makedirs(os.path.dirname(path), exist_ok=True) - with open(path, 'r') as f: - existing_content = f.read() - - if not os.path.exists(path) or existing_content.strip() == "": + if not os.path.exists(path): with open(path, 'w') as f: f.write(default_config) - elif " continuedev.core" in existing_content: - with open(path, 'w') as f: - f.write(existing_content.replace(" continuedev.", - " continuedev.src.continuedev.")) + else: + with open(path, 'r') as f: + existing_content = f.read() + + if existing_content.strip() == "": + with open(path, 'w') as f: + f.write(default_config) + elif " continuedev.core" in existing_content: + with open(path, 'w') as f: + f.write(existing_content.replace(" continuedev.", + " continuedev.src.continuedev.")) return path diff --git a/extension/src/activation/environmentSetup.ts b/extension/src/activation/environmentSetup.ts index 8d9578e8..db457bd2 100644 --- a/extension/src/activation/environmentSetup.ts +++ b/extension/src/activation/environmentSetup.ts @@ -83,23 +83,23 @@ export function getExtensionVersion() { // Returns whether a server of the current version is already running async function checkOrKillRunningServer(serverUrl: string): Promise { console.log("Checking if server is old version"); + const serverRunning = 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() && - (await checkServerRunning(serverUrl)) - ) { + if (serverVersion === getExtensionVersion() && serverRunning) { // The current version is already up and running, no need to continue return true; } } - console.log("Killing old server..."); - try { - await fkill(":65432"); - } catch (e: any) { - if (!e.message.includes("Process doesn't exist")) { - console.log("Failed to kill old server:", e); + if (serverRunning) { + console.log("Killing old server..."); + try { + await fkill(":65432"); + } catch (e: any) { + if (!e.message.includes("Process doesn't exist")) { + console.log("Failed to kill old server:", e); + } } } return false; -- cgit v1.2.3-70-g09d2