Skip to content

Commit

Permalink
[vscode][4/n] Setup Env Variables: Add helper text to existing env pa…
Browse files Browse the repository at this point in the history
…th (#1284)

[vscode][4/n] Setup Env Variables: Add helper text to existing env path

This PR I had some issues with reading the env template, so for now I'm
splitting up this logic and will follow up next PR

## Test Plan


https://github.com/lastmile-ai/aiconfig/assets/151060367/6aad117f-0c55-4549-8f46-1b438c6ebf4b

---
Stack created with [Sapling](https://sapling-scm.com). Best reviewed
with
[ReviewStack](https://reviewstack.dev/lastmile-ai/aiconfig/pull/1284).
* #1285
* __->__ #1284
* #1283
* #1280
  • Loading branch information
rossdanlm authored Feb 22, 2024
2 parents 13a54bc + 351c376 commit 12af50c
Showing 1 changed file with 37 additions and 21 deletions.
58 changes: 37 additions & 21 deletions vscode-extension/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -764,18 +764,33 @@ async function setupEnvironmentVariables(context: vscode.ExtensionContext) {
return;
}

const envTemplatePath = vscode.Uri.joinPath(
context.extensionUri,
"static",
"env_template.env"
);

if (fs.existsSync(envPath)) {
vscode.window.showInformationMessage(
"Env file already exists, will implement next PR"
);
var helperText: string = "\ntest, will change next PR";
// fs.readFile(envTemplatePath.fsPath, function read(err, data) {
// if (err) {
// throw err;
// }
// helperText = "\n" + data.toString();
// });

// TODO: Check if we already appended the template text to existing .env
// file before. If we did, don't do it again
fs.appendFile(envPath, helperText, function (err) {
if (err) {
throw err;
}
console.log(
`Added .env template text from ${envTemplatePath.fsPath} to ${envPath}`
);
});
} else {
// Create the .env file from the sample
const envTemplatePath = vscode.Uri.joinPath(
context.extensionUri,
"static",
"env_template.env"
);

try {
await vscode.workspace.fs.copy(
envTemplatePath,
Expand All @@ -787,19 +802,20 @@ async function setupEnvironmentVariables(context: vscode.ExtensionContext) {
`Error creating new file ${envTemplatePath}: ${err}`
);
}
}

const doc = await vscode.workspace.openTextDocument(envPath);
if (doc) {
vscode.window.showTextDocument(doc, {
preview: false,
// Tried using vscode.ViewColumn.Active but that overrides existing
// walkthrough window
viewColumn: vscode.ViewColumn.Beside,
});
vscode.window.showInformationMessage(
"Please define your environment variables."
);
}
// Open the env file that was either was created or already existed
const doc = await vscode.workspace.openTextDocument(envPath);
if (doc) {
vscode.window.showTextDocument(doc, {
preview: false,
// Tried using vscode.ViewColumn.Active but that overrides existing
// walkthrough window
viewColumn: vscode.ViewColumn.Beside,
});
vscode.window.showInformationMessage(
"Please define your environment variables."
);
}
}

Expand Down

0 comments on commit 12af50c

Please sign in to comment.