---
title: Develop a query in VS Code (Groovy)
sidebar_label: VS Code
---

The [Deephaven VS Code extension](https://marketplace.visualstudio.com/items?itemName=deephaven.vscode-deephaven) is a powerful tool for developing server-side Deephaven queries in Python or Groovy directly from Microsoft Visual Studio Code (VS Code). It provides an alternative to the [Deephaven IDE](./deephaven-ide.md) for users who prefer to do their development in VS Code, or who want to do development in a local IDE rather than a browser. The Deephaven VS Code extension allows the usage of VS Code's many features and other extensions for query development such as [GitHub Copilot](https://marketplace.visualstudio.com/items?itemName=GitHub.copilot).

## Install the Deephaven VS Code Extension

The Deephaven VS Code extension can be installed from the [VS Code Marketplace](https://marketplace.visualstudio.com/items?itemName=deephaven.vscode-deephaven) or from the extension browser inside of VS Code. The extension is currently `pre-release`, so you'll need to install it as such.

![Install Deephaven VS Code Extension](../../assets/vscode/vscode-install-pre-release.png)

Once installed, there will be a new Deephaven icon in the **Activity** bar (the sidebar containing navigation icons).

![VS Code - Activity Bar Icon](../../assets/vscode/vscode-dh-activity-bar.gif)

Clicking the Deephaven icon opens a new panel containing details of configured Deephaven servers. By default, the extension is configured to connect to a single Community server hosted at `http:localhost:10000`. Enterprise servers can be configured via the `deephaven.enterpriseServers` setting in VS Code user or workspace settings. To open one of the VS Code settings.json files:

1. Open the **Command Palette** by clicking `cmd/ctrl + shift + p`
1. Type `settings` and select **Preferences: Open User Settings (JSON)** or **Preferences: Open Workspace Settings (JSON)**. Change user settings to apply to all workspaces, and workspace settings to apply to the current workspace only.

   ![VS Code - Command Palette Settings](../../assets/vscode/vscode-palette-settings.png)

1. Add the following entry to the `settings.json` file (change the URL and port to that of your Deephaven installation; the default port is `8123` for a server without Envoy and `8000` for a server with Envoy):

   ```json
   "deephaven.enterpriseServers": [
     "https://demo.deephaven.io:8123/",
   ]
   ```

> [!NOTE]
> Some VS Code bugs cause flakiness with the `run` button. VS Code `v90` introduced an optional `workbench.editor.alwaysShowEditorActions` setting. Setting this to `true` improves the experience. Namely, the run button will not disappear when running commands or selecting its dropdown. See https://github.com/deephaven/vscode-deephaven/issues/1 for more details.

## Develop a Query

1. Open a workspace in VS Code.

1. Activate the `Deephaven` view by clicking the **Deephaven** icon in the `activity bar`.

   ![Activate Deephaven View](../../assets/vscode/vscode-deephaven-view-groovy.gif)

1. Create a new script in the workspace named `simple_ticking.groovy`, and paste the following code into it:

   ```groovy
   simpleTicking = timeTable("PT2S")
   ```

1. Run the script by clicking the **Run Deephaven File** action at the top of the file:

   ![VS Code - Run Deephaven File](../../assets/vscode/vscode-run-file-groovy.png)

1. Provide credentials when prompted for login.
1. You should see a ticking table in a new panel!

   ![VS Code Ticking Table](../../assets/vscode/vscode-ticking-table.png)

1. If you open a Query Monitor tab in the Deephaven IDE, you should see an `Interactive Console` query for the VS Code connection.
   ![VS Code Interactive Console Query](../../assets/vscode/vscode-interactive-console-query.png)

   The id in the `Name` column will match the id in the connection in VS Code.
   ![VS Code Connection ID](../../assets/vscode/vscode-connection-id.png)

## Make a PQ

Once you have a working query in VS Code, you can make it a Persistent Query (PQ) in the Deephaven IDE. Queries run from VS Code will only persist within the active session. Making a PQ will allow it to persist in between sessions.

To create a new Persistent Query, in the **Query Monitor** tab:

1. Click the **New** button.
1. Click the **Script** tab in the query details panel.
1. Change the runtime dropdown to **Groovy**.
1. Copy / paste your query from VS Code into the code area of the **Script** tab:

   ![VS Code - Create a PQ](../../assets/vscode/vscode-pq-details-groovy.gif)

1. Click the **Save** button.

## View the PQ

After saving the new query, it appears in the [Query Monitor](../../interfaces/web/query-monitor.md), and its status changes to `Running` once the query successfully starts.

![VS Code - PQ List](../../assets/vscode/vscode-pq-list-groovy.png)

Once your Persistent Query is running, you can access the `simpleTicking` table from the **Panels** menu in a Code Studio.

![VS Code - Open PQ in Code Studio](../../assets/vscode/vscode-pq-code-studio-groovy.gif)

## Related documentation

- [Develop a Query in Deephaven IDE](./deephaven-ide.md)
- [Develop a Query in Git](../../query-management/git.md)
