Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[vscode] 7/n listeners and .env #1390

Merged
merged 3 commits into from
Mar 5, 2024
Merged

[vscode] 7/n listeners and .env #1390

merged 3 commits into from
Mar 5, 2024

Conversation

Ankush-lastmile
Copy link
Member

@Ankush-lastmile Ankush-lastmile commented Feb 29, 2024

[vscode] 7/n listeners and .env

Summary:

When the .env file path is set, vscode will invoke api/set_env on each AIConfig server.

Defines a listener to a newly introduced setting for the env_file_path.

This ensures that users do not need to restart vscode to pickup env changes.

Test Plan:

  1. set env file path
  2. changes picked up
  3. changes picked up on restart
  4. Changes picked up when manually removing vscode setting and re-setting env file path and api key
testplan.mp4

Stack created with Sapling. Best reviewed with ReviewStack.

}
);
}

Copy link
Member Author

@Ankush-lastmile Ankush-lastmile Mar 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for anyone unaware,
[ENV_FILE_PATH] is syntax equivalent to resolving the value of ENV_FILE_PATH as the key for the js object.

"vscode-aiconfig.env_file_path": {
"type": "string",
"default": "",
"description": "env_file_path"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Description should be clearer on what this is for

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to "File path to your .env file containing your API keys"

vscode-extension/src/util.ts Show resolved Hide resolved
vscode-extension/src/util.ts Show resolved Hide resolved
Ankush Pala [email protected] added 2 commits March 4, 2024 19:35
Summary:

This diff modifies the AIConfig start and edit commands to take in an dot env path.

Due to core utils logic of handling args, the help messages automatically get updated too.

Also Removes the loadenv() on server init. This is okay because loadenv is invoked at the run step. [see 4/n](#1384)

Test Plan:

```
ankush@ap-mbp aiconfig % aiconfig start -h
/opt/homebrew/lib/python3.11/site-packages/pydantic/_internal/_fields.py:151: UserWarning: Field "model_parsers" has conflict with protected namespace "model_".

You may be able to resolve this warning by setting `model_config['protected_namespaces'] = ()`.
  warnings.warn(
usage: aiconfig start [-h] [--server-port SERVER_PORT] [--log-level LOG_LEVEL] [--server-mode {debug_servers,debug_backend,prod}] [--parsers-module-path PARSERS_MODULE_PATH] [--env-file-path ENV_FILE_PATH]

options:
  -h, --help            show this help message and exit
  --server-port SERVER_PORT
  --log-level LOG_LEVEL
  --server-mode {debug_servers,debug_backend,prod}
  --parsers-module-path PARSERS_MODULE_PATH
  **--env-file-path ENV_FILE_PATH**
```
Summary:

Stack contains changes that updates overall environment setup flow for vscode extension.

This diff adds support to call "SET_ENV_FILE_PATH" implemented in the previous diff.

No functional changes.

Test Plan:
context.subscriptions.push(vscode.workspace.onDidChangeConfiguration(async (event) => {
if (event.affectsConfiguration("vscode-aiconfig")) {
// Get new env
const envPath = vscode.workspace.getConfiguration("vscode-aiconfig").get(ENV_FILE_PATH) as string;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, unless deleting it makes its value empty string instead of undefined

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just checked really quickly and this get method returns an empty string when it is never set. I think this might be configured in the package.json but I'm unaware of how this works at the moment.

@@ -208,6 +210,25 @@ export async function activate(context: vscode.ExtensionContext) {
}
)
);

// Handle changes to the .env path
context.subscriptions.push(vscode.workspace.onDidChangeConfiguration(async (event) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need for async

Copy link
Contributor

@rholinshead rholinshead left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few small things

Summary:

When the .env file path is set, vscode will invoke api/set_env on each AIConfig server.

Defines a listener to a newly introduced setting for the env_file_path.

This ensures that users do not need to restart vscode to pickup env changes.

Test Plan:

1. set env file path
2. changes picked up
3. changes picked up on restart
4. Changes picked up when manually removing vscode setting and re-setting env file path and api key

https://github.com/lastmile-ai/aiconfig/assets/141073967/07ac1d43-28ef-439f-98e7-94a4e73e11c9
@Ankush-lastmile
Copy link
Member Author

  • added an await statement when invoking updateServerEnv
  • modified event handler to execute only if the extension setting for env_file_path is modified

@Ankush-lastmile Ankush-lastmile merged commit a74e8a9 into main Mar 5, 2024
2 checks passed
Ankush-lastmile added a commit that referenced this pull request Mar 5, 2024
[vscode] 8/n Remove LCA env checks

Summary:

Now that a user can specify a .env file path with no restrictions on its
location, the LCA checks need to be removed.

LCA = Lowest Common Ancestor



Test Plan:

---
[//]: # (BEGIN SAPLING FOOTER)
Stack created with [Sapling](https://sapling-scm.com). Best reviewed
with
[ReviewStack](https://reviewstack.dev/lastmile-ai/aiconfig/pull/1398).
* __->__ #1398
* #1390
* #1387
* #1389
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants