|
| 1 | +# Visual Studio Code Extension |
| 2 | + |
| 3 | +> The extension is currently in **preview** and as such is subject to change. You may also encoutnter bugs and api incompatibilities with the SQLMesh version you are running. We encourage you to try it and raise any issues [here](https://github.com/tobikodata/sqlmesh/issues). |
| 4 | +
|
| 5 | +In this quickstart guide, you'll set up the SQLMesh extension in Visual Studio Code, we'll show you the capabilities of the extension and how to troubleshoot common issues. |
| 6 | + |
| 7 | +## Installation |
| 8 | + |
| 9 | +Installation is done through the VSCode extension marketplace, search for `SQLMesh` and install the extension from the [marketplace](https://marketplace.visualstudio.com/items?itemName=tobikodata.sqlmesh). For a more in depth guide on how to install extensions, see the [VSCode documentation](https://code.visualstudio.com/docs/configure/extensions/extension-marketplace#_install-an-extension). |
| 10 | + |
| 11 | +### Recommended setup |
| 12 | + |
| 13 | +While installing the extension is simple, setting up a python environmnt correctly is a bit more involved. We do recommend using a dedicated *python virtual environment* to install SQLMesh. For a complete guide visit the [python documentation](https://docs.python.org/3/library/venv.html) but the following steps will create the virtual environment, activate it and install SQLMesh for both a SQLMesh core setup and a Tobiko Cloud setup. |
| 14 | + |
| 15 | +#### SQLMesh Core |
| 16 | + |
| 17 | + but as a summary you can do the following, which will create the virtual environment, activate it and install SQLMesh: |
| 18 | + |
| 19 | +```bash |
| 20 | +python -m venv .venv |
| 21 | +source .venv/bin/activate |
| 22 | +pip install 'sqlmesh[lsp]' |
| 23 | +``` |
| 24 | + |
| 25 | +Once you have the virtual environment, you can make sure that Visual Studio Code is using the correct python interpreter by going to the [command palette](https://code.visualstudio.com/docs/getstarted/userinterface#_command-palette) and running `Python: Select Interpreter`. Select the python executable in the virtual environment. |
| 26 | + |
| 27 | + |
| 28 | + |
| 29 | +Once that's done, you can validate that the extension is correctly using the virtual environment by checking the `sqlmesh` output channel in the [output panel](https://code.visualstudio.com/docs/getstarted/userinterface#_output-panel) which details the python path and the details of your SQLMesh installation and looks as follows: |
| 30 | + |
| 31 | + |
| 32 | + |
| 33 | +#### Tobiko Cloud |
| 34 | + |
| 35 | +For Tobiko Cloud, the tcloud utility is used to install SQLMesh, so you'll need to set up a python environment, activate it and install SQLMesh using the tcloud utility as follows. |
| 36 | + |
| 37 | +```bash |
| 38 | +python -m venv .venv |
| 39 | +source .venv/bin/activate |
| 40 | +pip install tcloud |
| 41 | +``` |
| 42 | + |
| 43 | +Once you have the virtual environment, you can make sure that Visual Studio Code is using the correct python interpreter by going to the [command palette](https://code.visualstudio.com/docs/getstarted/userinterface#_command-palette) and running `Python: Select Interpreter`. Select the python executable in the virtual environment. |
| 44 | + |
| 45 | + |
| 46 | + |
| 47 | +You can use the `tcloud` commands in your terminal to do the operations as usual or the extension exposes the same commands through the command pallette under the following commands: |
| 48 | +- `Sign in to Tobiko Cloud` |
| 49 | +- `Sign out of Tobiko Cloud` |
| 50 | + |
| 51 | +## Features |
| 52 | + |
| 53 | +### Lineage |
| 54 | + |
| 55 | +The extension adds a lineage view to the SQLMesh models. To view the lineage of a model, use the `Lineage` tab in the panel as shown below: |
| 56 | + |
| 57 | + |
| 58 | + |
| 59 | +### Commands |
| 60 | + |
| 61 | +The extension exposes the following commands through the command palette: |
| 62 | + |
| 63 | +- `Sign in to Tobiko Cloud` |
| 64 | +- `Sign out of Tobiko Cloud` |
| 65 | +- `Format SQLMesh project` |
| 66 | + |
| 67 | +### LSP Features |
| 68 | + |
| 69 | +The SQLMesh LSP adds a number of features to the editor: |
| 70 | + |
| 71 | +**Completion** |
| 72 | + |
| 73 | +When writing SQL models, keywords or model names, you should see a completion suggestion. |
| 74 | + |
| 75 | + |
| 76 | + |
| 77 | +**Go to definition and hover information** |
| 78 | + |
| 79 | +The SQLMesh LSP adds a definition provider for SQLMesh models. When you hover over a model name, you should see a tooltip with the model description and on click you will be taken to the model definition. |
| 80 | + |
| 81 | +**Diagnostics** |
| 82 | + |
| 83 | +The SQLMesh LSP adds a diagnostic provider for your SQLMesh project. If you have the SQLMesh linter enabled, issues will be reported in your editor. This works for both SQLMesh built in rules and custom rules. |
| 84 | + |
| 85 | + |
| 86 | + |
| 87 | +**Formatting** |
| 88 | + |
| 89 | +The SQLMesh LSP also adds a formatting provider for SQLMesh models. When you write SQL models, you should see the model formatted correctly. |
| 90 | + |
| 91 | +## Troubleshooting |
| 92 | + |
| 93 | +### LSP extensions |
| 94 | + |
| 95 | +When installing SQLMesh, some dependencies that are required by the extension are not installed by default. You can install them by running the following command in your terminal. Specifying the `[lsp]` flag will install the dependencies required by the extension. |
| 96 | + |
| 97 | +```bash |
| 98 | +pip install 'sqlmesh[lsp]' |
| 99 | +``` |
| 100 | + |
| 101 | +If you are in a cloud environment, you can make sure the extension requirements are correctly installed by adding `lsp` to the list of extras required in the `tcloud.yaml` file. |
| 102 | + |
| 103 | +### Python environment woes |
| 104 | + |
| 105 | +The most common issue is that the extension is not using the correct python interpreter. We recommend following the [recommended setup](#recommended-setup) to ensure that the extension is using the correct python interpreter. If you have checked the `sqlmesh` output channel and the extension is still not using the correct python interpreter, please raise an issue [here](https://github.com/tobikodata/sqlmesh/issues). |
| 106 | + |
| 107 | +### SQLMesh compatibility |
| 108 | + |
| 109 | +While the extension is in preview and the APIs to the underlying SQLMesh version are not stable, we do not guarantee compatibility between the extension and the SQLMesh version you are using. If you encounter an issue, please raise an issue [here](https://github.com/tobikodata/sqlmesh/issues). |
| 110 | + |
0 commit comments