|
2 | 2 |
|
3 | 3 | !!! danger "Preview" |
4 | 4 |
|
5 | | - The extension is currently in preview and as such is subject to change. You may encounter 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). |
| 5 | + The SQLMesh Visual Studio Code extension is in preview and undergoing active development. You may encounter bugs or API incompatibilities with the SQLMesh version you are running. |
6 | 6 |
|
7 | | -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. |
| 7 | + We encourage you to try the extension and [create Github issues](https://github.com/tobikodata/sqlmesh/issues) for any problems you encounter. |
| 8 | + |
| 9 | +In this guide, you'll set up the SQLMesh extension in the Visual Studio Code IDE software (which we refer to as "VSCode"). |
| 10 | + |
| 11 | +We'll show you the capabilities of the extension and how to troubleshoot common issues. |
8 | 12 |
|
9 | 13 | ## Installation |
10 | 14 |
|
11 | | -Installation is done through the official [marketplace](https://marketplace.visualstudio.com/items?itemName=tobikodata.sqlmesh) or by searching for `SQLMesh` in the "Extensions" tab of Visual Studio Code. |
| 15 | +### VSCode extension |
| 16 | + |
| 17 | +Install the extension through the official Visual Studio [marketplace website](https://marketplace.visualstudio.com/items?itemName=tobikodata.sqlmesh) or by searching for `SQLMesh` in the VSCode "Extensions" tab. |
12 | 18 |
|
13 | | -For further guidance on how to install extensions, see the [relevant Visual Studio Code documentation](https://code.visualstudio.com/docs/configure/extensions/extension-marketplace#_install-an-extension). |
| 19 | +Learn more about installing VSCode extensions in the [official documentation](https://code.visualstudio.com/docs/configure/extensions/extension-marketplace#_install-an-extension). |
14 | 20 |
|
15 | | -### Recommended setup |
| 21 | +### Python setup |
16 | 22 |
|
17 | | -While installing the extension is simple, setting up a Python environment 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. |
| 23 | +While installing the extension is simple, setting up and configuring a Python environment in VSCode is a bit more involved. |
18 | 24 |
|
19 | | -#### SQLMesh Core |
| 25 | +We recommend using a dedicated *Python virtual environment* to install SQLMesh. Visit the [Python documentation](https://docs.python.org/3/library/venv.html) for more information about virtual environments. |
20 | 26 |
|
21 | | -For SQLMesh core, you can create a virtual environment, activate it and install SQLMesh as follows: |
| 27 | +We describe the steps to create and activate a virtual environment below, but additional information is available on the [SQLMesh installation page](installation.md). |
| 28 | + |
| 29 | +We first install the SQLMesh library, which is required by the extension. |
| 30 | + |
| 31 | +Open a terminal instance in your SQLMesh project's directory and issue this command to create a virtual environment in the `.venv` directory: |
22 | 32 |
|
23 | 33 | ```bash |
24 | 34 | python -m venv .venv |
25 | | -source .venv/bin/activate |
26 | | -pip install 'sqlmesh[lsp]' |
27 | 35 | ``` |
28 | 36 |
|
29 | | -Once you have the virtual environment, you can ensure 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. |
| 37 | +Next, activate the virtual environment: |
30 | 38 |
|
31 | | - |
| 39 | +```bash |
| 40 | +source .venv/bin/activate |
| 41 | +``` |
32 | 42 |
|
33 | | -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: |
| 43 | +#### Open-source SQLMesh |
34 | 44 |
|
35 | | - |
| 45 | +If you are using open-source SQLMesh, install SQLMesh with the `lsp` extra that enables the VSCode extension (learn more about SQLMesh extras [here](installation.md#install-extras)): |
| 46 | + |
| 47 | +```bash |
| 48 | +pip install 'sqlmesh[lsp]' |
| 49 | +``` |
36 | 50 |
|
37 | 51 | #### Tobiko Cloud |
38 | 52 |
|
39 | | -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. |
| 53 | +If you are using Tobiko Cloud, the `tcloud` library will install SQLMesh for you. |
| 54 | + |
| 55 | +First, follow the [Python setup](#python-setup) steps above to create and activate a Python environment. Next, install `tcloud`: |
40 | 56 |
|
41 | 57 | ```bash |
42 | | -python -m venv .venv |
43 | | -source .venv/bin/activate |
44 | 58 | pip install tcloud |
45 | 59 | ``` |
46 | 60 |
|
47 | | -Once you have the virtual environment, you can ensure 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. |
| 61 | +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). |
| 62 | + |
| 63 | +### VSCode Python interpreter |
| 64 | + |
| 65 | +A Python virtual environment contains its own copy of Python (the "Python interpreter"). We need to make sure VSCode is using your virtual environment's interpreter rather than a system-wide or other interpreter that does not have access to the SQLMesh library we just installed. |
| 66 | + |
| 67 | +Confirm that VSCode is using the correct interpreter by going to the [command palette](https://code.visualstudio.com/docs/getstarted/userinterface#_command-palette) and clicking `Python: Select Interpreter`. Select the Python executable that's in the virtual environment's directory `.venv`. |
48 | 68 |
|
49 | 69 |  |
50 | 70 |
|
51 | | -You can use the `tcloud` commands in your terminal to perform operations as usual, or the extension exposes the same commands through the command palette under the following commands: |
52 | | -- `Sign in to Tobiko Cloud` |
53 | | -- `Sign out of Tobiko Cloud` |
| 71 | +Once that's done, validate that the everything is working correctly by checking the `sqlmesh` channel in the [output panel](https://code.visualstudio.com/docs/getstarted/userinterface#_output-panel). It displays the Python interpreter path and details of your SQLMesh installation: |
54 | 72 |
|
55 | | -## Features |
| 73 | + |
56 | 74 |
|
57 | | -### Lineage |
| 75 | +## Features |
58 | 76 |
|
59 | | -The extension adds a lineage view to SQLMesh models. To view the lineage of a model, use the `Lineage` tab in the panel as shown below: |
| 77 | +SQLMesh's VSCode extension makes it easy to edit and understand your SQLMesh project with these features: |
60 | 78 |
|
61 | | - |
| 79 | +- Lineage |
| 80 | + - Interactive view of model lineage |
| 81 | +- Editor |
| 82 | + - Auto-completion for model names and SQLMesh keywords |
| 83 | + - Model summaries when hovering over model references |
| 84 | + - Links to open model files from model references |
| 85 | + - Inline SQLMesh linter diagnostics |
| 86 | +- VSCode commands |
| 87 | + - Format SQLMesh project files |
| 88 | + - Sign in/out of Tobiko Cloud (Tobiko Cloud users only) |
62 | 89 |
|
63 | | -### Commands |
| 90 | +### Lineage |
64 | 91 |
|
65 | | -The extension exposes the following commands through the command palette: |
| 92 | +The extension adds a lineage view to SQLMesh models. To view the lineage of a model, go to the `Lineage` tab in the panel: |
66 | 93 |
|
67 | | -- `Sign in to Tobiko Cloud` |
68 | | -- `Sign out of Tobiko Cloud` |
69 | | -- `Format SQLMesh project` |
| 94 | + |
70 | 95 |
|
71 | | -### LSP Features |
| 96 | +### Editor |
72 | 97 |
|
73 | | -The SQLMesh LSP adds several features to the editor: |
| 98 | +The SQLMesh VSCode extension includes several features that make editing SQLMesh models easier and quicker: |
74 | 99 |
|
75 | 100 | **Completion** |
76 | 101 |
|
77 | | -When writing SQL models, keywords, or model names, you should see completion suggestions. |
| 102 | +See auto-completion suggestions when writing SQL models, keywords, or model names. |
78 | 103 |
|
79 | 104 |  |
80 | 105 |
|
81 | 106 | **Go to definition and hover information** |
82 | 107 |
|
83 | | -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 when you click, you will be taken to the model definition. |
| 108 | +Hovering over a model name shows a tooltip with the model description. Clicking the model name opens the file containing the model definition. |
84 | 109 |
|
85 | 110 | **Diagnostics** |
86 | 111 |
|
87 | | -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. |
| 112 | +If you have the [SQLMesh linter](../guides/linter.md) enabled, issues are reported directly in your editor. This works for both SQLMesh's built-in linter rules and custom linter rules. |
88 | 113 |
|
89 | 114 |  |
90 | 115 |
|
91 | 116 | **Formatting** |
92 | 117 |
|
93 | | -The SQLMesh LSP also adds a formatting provider for SQLMesh models. When you write SQL models, you can use the formatter to format models consistently. |
| 118 | +SQLMesh's model formatting tool is integrated directly into the editor, so it's easy to format models consistently. |
| 119 | + |
| 120 | +### Commands |
| 121 | + |
| 122 | +The SQLMesh VSCode extension provides the following commands in the VSCode command palette: |
| 123 | + |
| 124 | +- `Format SQLMesh project` |
| 125 | +- `Sign in to Tobiko Cloud` (Tobiko Cloud users only) |
| 126 | +- `Sign out of Tobiko Cloud` (Tobiko Cloud users only) |
94 | 127 |
|
95 | 128 | ## Troubleshooting |
96 | 129 |
|
97 | | -### LSP extensions |
| 130 | +### Python environment woes |
| 131 | + |
| 132 | +The most common problem is the extension not using the correct Python interpreter. |
| 133 | + |
| 134 | +Follow the [setup process described above](#vscode-python-interpreter) to ensure that the extension is using the correct Python interpreter. |
| 135 | + |
| 136 | +If you have checked the VSCode `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). |
| 137 | + |
| 138 | +### Missing Python dependencies |
98 | 139 |
|
99 | | -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. |
| 140 | +When installing SQLMesh, some dependencies required by the VSCode extension are not installed unless you specify the `lsp` "extra". |
| 141 | + |
| 142 | +If you are using open-source SQLMesh, install the `lsp` extra by running this command in your terminal: |
100 | 143 |
|
101 | 144 | ```bash |
102 | 145 | pip install 'sqlmesh[lsp]' |
103 | 146 | ``` |
104 | 147 |
|
105 | | -If you are in a cloud environment, you can ensure the extension requirements are correctly installed by adding `lsp` to the list of extras required in the `tcloud.yaml` file. |
106 | | - |
107 | | -### Python environment woes |
108 | | - |
109 | | -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). |
| 148 | +If you are using Tobiko Cloud, make sure `lsp` is included in the list of extras specified in the [`tcloud.yaml` configuration file](../cloud/tcloud_getting_started.md#connect-tobiko-cloud-to-data-warehouse). |
110 | 149 |
|
111 | 150 | ### SQLMesh compatibility |
112 | 151 |
|
113 | | -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). |
| 152 | +While the SQLMesh VSCode 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. |
| 153 | + |
| 154 | +If you encounter a problem, please raise an issue [here](https://github.com/tobikodata/sqlmesh/issues). |
0 commit comments