diff options
Diffstat (limited to 'extension/src')
-rw-r--r-- | extension/src/activation/environmentSetup.ts | 87 | ||||
-rw-r--r-- | extension/src/continueIdeClient.ts | 4 | ||||
-rw-r--r-- | extension/src/suggestions.ts | 23 | ||||
-rw-r--r-- | extension/src/telemetry.ts | 4 |
4 files changed, 68 insertions, 50 deletions
diff --git a/extension/src/activation/environmentSetup.ts b/extension/src/activation/environmentSetup.ts index d4c81d2e..4e6be9b3 100644 --- a/extension/src/activation/environmentSetup.ts +++ b/extension/src/activation/environmentSetup.ts @@ -9,6 +9,7 @@ import { getContinueServerUrl } from "../bridge"; import fetch from "node-fetch"; import * as vscode from "vscode"; import fkill from "fkill"; +import { sendTelemetryEvent, TelemetryEvent } from "../telemetry"; const MAX_RETRIES = 5; async function retryThenFail( @@ -17,13 +18,16 @@ async function retryThenFail( ): Promise<any> { try { return await fn(); - } catch (e) { + } catch (e: any) { 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!" ); + sendTelemetryEvent(TelemetryEvent.ExtensionSetupError, { + error: e.message, + }); throw e; } } @@ -47,6 +51,12 @@ async function runCommand(cmd: string): Promise<[string, string | undefined]> { stdout = ""; } + if (stderr) { + sendTelemetryEvent(TelemetryEvent.ExtensionSetupError, { + error: stderr, + }); + } + return [stdout, stderr]; } @@ -71,9 +81,11 @@ async function getPythonPipCommands() { } } + let pipCmd = pythonCmd.endsWith("3") ? "pip3" : "pip"; + const version = stdout.split(" ")[1]; const [major, minor] = version.split("."); - if (parseInt(major) !== 3 || parseInt(minor) < 7) { + if (parseInt(major) !== 3 || parseInt(minor) < 8) { // Need to check specific versions const checkPython3VersionExists = async (minorVersion: number) => { const [stdout, stderr] = await runCommand( @@ -82,24 +94,27 @@ async function getPythonPipCommands() { return typeof stderr === "undefined" || stderr === ""; }; - const validVersions = [7, 8, 9, 10, 11, 12]; + const VALID_VERSIONS = [8, 9, 10, 11, 12]; let versionExists = false; - for (const minorVersion of validVersions) { + for (const minorVersion of VALID_VERSIONS) { if (await checkPython3VersionExists(minorVersion)) { versionExists = true; - break; + pythonCmd = `python3.${minorVersion}`; + pipCmd = `pip3.${minorVersion}`; } } if (!versionExists) { vscode.window.showErrorMessage( - "Continue requires Python3 version 3.7 or greater. Please update your Python3 installation, reload VS Code, and try again." + "Continue requires Python3 version 3.8 or greater. Please update your Python3 installation, reload VS Code, and try again." ); - throw new Error("Python3 is not installed."); + throw new Error("Python3.8 or greater is not installed."); } + } else { + pythonCmd = `python${major}.${minor}`; + pipCmd = `pip${major}.${minor}`; } - const pipCmd = pythonCmd.endsWith("3") ? "pip3" : "pip"; return [pythonCmd, pipCmd]; } @@ -283,34 +298,33 @@ export async function startContinuePythonServer() { return; } - 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; + 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..."); + await fkill(":65432"); } - console.log("Killing old server..."); - await fkill(":65432"); - } - // Do this after above check so we don't have to waste time setting up the env - await setupPythonEnv(); + // Do this after above check so we don't have to waste time setting up the env + await setupPythonEnv(); - let activateCmd = ". env/bin/activate"; - let pythonCmd = "python3"; - if (process.platform == "win32") { - activateCmd = ".\\env\\Scripts\\activate"; - pythonCmd = "python"; - } + const [pythonCmd] = await getPythonPipCommands(); + const activateCmd = + process.platform == "win32" + ? ".\\env\\Scripts\\activate" + : ". env/bin/activate"; - let command = `cd "${path.join( - getExtensionUri().fsPath, - "scripts" - )}" && ${activateCmd} && cd .. && ${pythonCmd} -m scripts.run_continue_server`; + const command = `cd "${path.join( + getExtensionUri().fsPath, + "scripts" + )}" && ${activateCmd} && cd .. && ${pythonCmd} -m scripts.run_continue_server`; - return await retryThenFail(async () => { console.log("Starting Continue python server..."); return new Promise(async (resolve, reject) => { @@ -318,22 +332,25 @@ export async function startContinuePythonServer() { const child = spawn(command, { shell: true, }); - child.stdout.on("data", (data: any) => { - console.log(`stdout: ${data}`); - }); child.stderr.on("data", (data: any) => { + console.log(`stdout: ${data}`); if ( data.includes("Uvicorn running on") || // Successfully started the server data.includes("address already in use") // The server is already running (probably a simultaneously opened VS Code window) ) { console.log("Successfully started Continue python server"); resolve(null); - } else { - console.log(`stderr: ${data}`); + } else if (data.includes("ERROR") || data.includes("Traceback")) { + sendTelemetryEvent(TelemetryEvent.ExtensionSetupError, { + error: data, + }); } }); child.on("error", (error: any) => { console.log(`error: ${error.message}`); + sendTelemetryEvent(TelemetryEvent.ExtensionSetupError, { + error: error.message, + }); }); // Write the current version of vscode to a file called server_version.txt diff --git a/extension/src/continueIdeClient.ts b/extension/src/continueIdeClient.ts index 8f45b849..999bca88 100644 --- a/extension/src/continueIdeClient.ts +++ b/extension/src/continueIdeClient.ts @@ -408,6 +408,10 @@ class IdeProtocolClient { sendHighlightedCode(highlightedCode: (RangeInFile & { contents: string })[]) { this.messenger?.send("highlightedCodePush", { highlightedCode }); } + + sendAcceptRejectSuggestion(accepted: boolean) { + this.messenger?.send("acceptRejectSuggestion", { accepted }); + } } export default IdeProtocolClient; diff --git a/extension/src/suggestions.ts b/extension/src/suggestions.ts index baa49711..6e5a444f 100644 --- a/extension/src/suggestions.ts +++ b/extension/src/suggestions.ts @@ -5,7 +5,7 @@ import { translate, readFileAtRange } from "./util/vscode"; import * as fs from "fs"; import * as path from "path"; import { registerAllCodeLensProviders } from "./lang-server/codeLens"; -import { extensionContext } from "./activation/activate"; +import { extensionContext, ideProtocolClient } from "./activation/activate"; export interface SuggestionRanges { oldRange: vscode.Range; @@ -241,19 +241,14 @@ function selectSuggestion( suggestions = JSON.parse(rawData); } - if (accept === "new" || (accept === "selected" && suggestion.newSelected)) { - suggestions.push({ - accepted: true, - timestamp: Date.now(), - suggestion: suggestion.newContent, - }); - } else { - suggestions.push({ - accepted: false, - timestamp: Date.now(), - suggestion: suggestion.newContent, - }); - } + const accepted = + accept === "new" || (accept === "selected" && suggestion.newSelected); + suggestions.push({ + accepted, + timestamp: Date.now(), + suggestion: suggestion.newContent, + }); + ideProtocolClient.sendAcceptRejectSuggestion(accepted); // Write the updated suggestions back to the file fs.writeFileSync( diff --git a/extension/src/telemetry.ts b/extension/src/telemetry.ts index ea71a545..db5cb8ca 100644 --- a/extension/src/telemetry.ts +++ b/extension/src/telemetry.ts @@ -35,6 +35,8 @@ export enum TelemetryEvent { AutoDebugThisTest = "AutoDebugThisTest", // Command run to generate docstring GenerateDocstring = "GenerateDocstring", + // Error setting up the extension + ExtensionSetupError = "ExtensionSetupError", } export function sendTelemetryEvent( @@ -48,4 +50,4 @@ export function sendTelemetryEvent( userId: vscode.env.machineId, properties, }); -}
\ No newline at end of file +} |