cleaning environmentSetup
This commit is contained in:
parent
0f0cbf6d65
commit
5c111f7571
6 changed files with 52 additions and 113 deletions
|
|
@ -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");
|
||||
|
|
|
|||
|
|
@ -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") {
|
||||
|
|
|
|||
|
|
@ -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") ||
|
||||
|
|
|
|||
|
|
@ -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(() => {
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue