summaryrefslogtreecommitdiff
path: root/extension/src
diff options
context:
space:
mode:
authorNate Sesti <sestinj@gmail.com>2023-07-07 21:04:53 -0700
committerNate Sesti <sestinj@gmail.com>2023-07-07 21:04:53 -0700
commit6f0e6340bb22ee150ef4b7996750f4c63c0bc2a7 (patch)
tree2c7f0db9274f66e17d3f9d2480077037ac8f15fd /extension/src
parent08ad48a3f7a3facb52605b10c6d0e7666d03551a (diff)
downloadsncontinue-6f0e6340bb22ee150ef4b7996750f4c63c0bc2a7.tar.gz
sncontinue-6f0e6340bb22ee150ef4b7996750f4c63c0bc2a7.tar.bz2
sncontinue-6f0e6340bb22ee150ef4b7996750f4c63c0bc2a7.zip
fix: :bug: install python-virtualenv on linux, fix git hash files error
Diffstat (limited to 'extension/src')
-rw-r--r--extension/src/activation/environmentSetup.ts60
-rw-r--r--extension/src/diffs.ts19
2 files changed, 54 insertions, 25 deletions
diff --git a/extension/src/activation/environmentSetup.ts b/extension/src/activation/environmentSetup.ts
index bbf93f65..90ec9259 100644
--- a/extension/src/activation/environmentSetup.ts
+++ b/extension/src/activation/environmentSetup.ts
@@ -189,32 +189,46 @@ async function setupPythonEnv() {
`${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 (checkEnvExists()) {
- break;
- } else if (stderr) {
- if (stderr.includes("running scripts is disabled on this system")) {
- vscode.window.showErrorMessage(
- "A Python virtual enviroment cannot be activated because running scripts is disabled for this user. 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 [stdout, stderr] = await runCommand(createEnvCommand);
+ if (
+ stderr &&
+ stderr.includes("running scripts is disabled on this system")
+ ) {
+ await vscode.window.showErrorMessage(
+ "A Python virtual enviroment cannot be activated because running scripts is disabled for this user. Please enable signed scripts to run with this command in PowerShell: `Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser`, reload VS Code, and then try again."
+ );
+ throw new Error(stderr);
+ } else if (
+ stderr?.includes("On Debian/Ubuntu systems") ||
+ stdout?.includes("On Debian/Ubuntu systems")
+ ) {
+ // First, try to run the command to install python3-venv
+ let [stdout, stderr] = await runCommand(`${pythonCmd} --version`);
+ if (stderr) {
throw new Error(stderr);
- } else {
- // Remove the env and try again
- const removeCommand = `rm -rf "${path.join(
- getExtensionUri().fsPath,
- "scripts",
- "env"
- )}"`;
- await runCommand(removeCommand);
}
+ const version = stdout.split(" ")[1].split(".")[1];
+ const installVenvCommand = `apt-get install python3.${version}-venv`;
+ await runCommand("apt-get update");
+ // Ask the user to run the command to install python3-venv (requires sudo, so we can't)
+ // First, get the python version
+ const msg = `[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.`;
+ console.log(msg);
+ await vscode.window.showErrorMessage(msg);
+ } else if (checkEnvExists()) {
+ console.log(
+ "Successfully set up python env at ",
+ getExtensionUri().fsPath + "/scripts/env"
+ );
+ } 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);
}
- console.log(
- "Successfully set up python env at ",
- getExtensionUri().fsPath + "/scripts/env"
- );
}
await retryThenFail(async () => {
diff --git a/extension/src/diffs.ts b/extension/src/diffs.ts
index dbfd8f59..b9ef8384 100644
--- a/extension/src/diffs.ts
+++ b/extension/src/diffs.ts
@@ -39,14 +39,25 @@ class DiffManager {
originalFilepath: string,
newFilepath: string
): vscode.TextEditor | undefined {
- // If the file doesn't yet exist, don't open the diff editor
- if (!fs.existsSync(newFilepath)) {
+ // If the file doesn't yet exist or the basename is a single digit number (git hash object or something), don't open the diff editor
+ if (
+ !fs.existsSync(newFilepath) ||
+ path.basename(originalFilepath).match(/^\d$/)
+ ) {
return undefined;
}
const rightUri = vscode.Uri.parse(newFilepath);
const leftUri = vscode.Uri.file(originalFilepath);
const title = "Continue Diff";
+ console.log(
+ "Opening diff window with ",
+ leftUri,
+ rightUri,
+ title,
+ newFilepath,
+ originalFilepath
+ );
vscode.commands.executeCommand("vscode.diff", leftUri, rightUri, title);
const editor = vscode.window.activeTextEditor;
@@ -112,11 +123,13 @@ class DiffManager {
newFilepath = Array.from(this.diffs.keys())[0];
}
if (!newFilepath) {
+ console.log("No newFilepath provided to accept the diff");
return;
}
// Get the diff info, copy new file to original, then delete from record and close the corresponding editor
const diffInfo = this.diffs.get(newFilepath);
if (!diffInfo) {
+ console.log("No corresponding diffInfo found for newFilepath");
return;
}
fs.writeFileSync(
@@ -132,10 +145,12 @@ class DiffManager {
newFilepath = Array.from(this.diffs.keys())[0];
}
if (!newFilepath) {
+ console.log("No newFilepath provided to reject the diff");
return;
}
const diffInfo = this.diffs.get(newFilepath);
if (!diffInfo) {
+ console.log("No corresponding diffInfo found for newFilepath");
return;
}