Skip to content

Sung/vscode-env-vars #4803

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

Merged
merged 13 commits into from
Jun 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 25 additions & 5 deletions docs/guides/vscode.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ If you are using Tobiko Cloud, the `tcloud` library will install SQLMesh for you
First, follow the [Python setup](#python-setup) steps above to create and activate a Python environment. Next, install `tcloud`:

```bash
pip install tcloud
pip install tcloud # always make sure to install the latest version of tcloud
```

Finally, add the `lsp` extra to your `tcloud.yml` configuration file, as described [here](../cloud/tcloud_getting_started.md#connect-tobiko-cloud-to-data-warehouse).
Expand Down Expand Up @@ -155,11 +155,31 @@ The VSCode extension is based on a [language server](https://en.wikipedia.org/wi

If you have environment variables that are needed by the context and the language server, you can use one of these approaches to pass variables to the language server:

- Open VSCode from a terminal that has the variables set
- Use environment variables pulled from somewhere else dynamically (e.g. a `.env` file) in your config
- Set the environment variables in the python environment that the extension uses. You can find detailed instructions [here](https://code.visualstudio.com/docs/python/environments#_environment-variables)
- Open VSCode from a terminal that has the variables set already.
- If you have `export ENV_VAR=value` in your shell configuration file (e.g. `.zshrc` or `.bashrc`) when initializing the terminal by default, the variables will be picked up by the language server if opened from that terminal.
- Use environment variables pulled from somewhere else dynamically in your `config.py` for example by connecting to a secret store
- By default, a `.env` file in your root project directory will automatically be picked up by the language server through the python environment that the extension uses. For exact details on how to set the environment variables in the Python environment that the extension uses, see [here](https://code.visualstudio.com/docs/python/environments#_environment-variables)

### Python environment woes
You can verify that the environment variables are being passed to the language server by printing them in your terminal.

1. `Cmd +Shift + P` (`Ctrl + Shift + P` in case of Windows) to start the VSCode command bar
![print_env_vars](./vscode/print_env_vars.png)
2. Select the option: `SQLMesh: Print Environment Variables`
3. You should see the environment variables printed in the terminal
![terminal_env_vars](./vscode/terminal_env_vars.png)

If you change your setup during development (e.g., add variables to your shell config), you must restart the language server for the changes to take effect. You can do this by running the following command in the terminal:

1. `Cmd +Shift + P` (`Ctrl + Shift + P` in case of Windows) to start the VSCode command bar
2. Select the option: `SQLMesh: Restart Servers`
![restart_servers](./vscode/restart_servers.png)
![loaded](./vscode/loaded.png)

> This loaded message will appear in the lower left corner of the VSCode window.

3. Print the environment variables based on the instructions above to verify the changes have taken effect.

### Python environment issues

The most common problem is the extension not using the correct Python interpreter.

Expand Down
Binary file added docs/guides/vscode/loaded.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/guides/vscode/print_env_vars.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/guides/vscode/restart_servers.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/guides/vscode/terminal_env_vars.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.