# VSCode

VSCode applications are available on Nuvolos as the suggested GUI integrated development environment for Python. All VS Code applications come with a `conda` environment already in place in which you can [install your required packages](/features/applications/install-a-software-package.md).

## Installing VSCode extensions

Nuvolos runs [code-server](https://github.com/coder/code-server) in VSCode applications. Because `code-server` uses its own extension marketplace, some extensions available in the [Visual Studio Code Marketplace](https://marketplace.visualstudio.com/) may not appear in the Nuvolos extension browser. Many extensions are also distributed as .vsix files and can be installed manually.

To install an extension from a `.vsix` file:

1. Download the extension `.vsix` file.
2. Upload the file to Nuvolos.
3. In VS Code, open the Extensions view.
4. Open the extensions view menu and select Install from VSIX.
5. Choose the uploaded `.vsix` file and complete the installation.

## Persistent terminal sessions

By default, VSCode terminals are vanilla Bash sessions on Nuvolos, which are prone to stop when not used for a longer while. If you plan to run shell commands for hours and want to monitor their output, it's recommended to use [tmux](https://man7.org/linux/man-pages/man1/tmux.1.html) or screen.

### Set tmux as your default terminal

You can configure tmux as your default terminal in VSCode with the following steps

1. Verify with the command `which tmux` if tmux is installed already. If not, you can install it with `conda install tmux`
2. In VSCode, press `Ctrl + Shift + P` and search for `Open User Settings (JSON)`
3. In the opened JSON, add the following block

```
"terminal.integrated.profiles.linux": {
    "tmux": {
        "path": "tmux",
        "args": ["new-session", "-A", "-s", "${workspaceFolder}"],
        "icon": "terminal-tmux",
    },
},
"terminal.integrated.defaultProfile.linux": "tmux",
```

Now every time you open a new terminal, it'll be by default a tmux session. Every [workspace folder](https://code.visualstudio.com/docs/editing/workspaces/workspaces) will have a different named session with the above configuration, e.g.:

1. You can open folder `ABC` in VSCode and start a new terminal, start a long-running script there
2. Change workspace folder to `DEF` in VSCode and start a new terminal. You'll get a different tmux session here
3. Change back to folder `ABC` in VSCode. If you open a terminal, you should see the outputs of your long-running script

## Interactive Python development

The VS Code application is an excellent interactive development environment. You can find a detailed and complete guide for interactive development with IPython [here](https://code.visualstudio.com/docs/python/jupyter-support-py), the following documentation helps you get started quickly in the context of the Nuvolos apps.

### Creating an interactive IPython window in VS Code

VS Code comes equipped with a conda package manager. In order to be able to start interactive IPython windows, you will first need to install some packages into the VS Code app. To do so, take the following steps:

1. Open a VS Code command prompt either by finding **View > Command Palette** in the menu, or by hitting the **Ctrl + Shift + P** key combination.
2. In the VS Code command palette, type Jupyter: Create and the autocomplete should offer you the Create Interactive Window option.
3. You might be prompted to install ipykernel, in this case proceed to do so (this might take a minute or so to complete).\
   \
   **If you have omitted step 3, you can later:**
4. Open a terminal in VS Code. You can do this by finding **Terminal > New Terminal** in the menu or hitting the **Ctrl + Shift + \`** key combination. In the terminal type `conda install --freeze-installed ipykernel` and wait for the process to complete. After that, you should be able to perform steps 1 and 2 without any further issues.

## Accessing a local webserver in the browser

Sometimes you may need to run a local web server in your VS Code application, for example to view TensorBoard or a Streamlit app. Because Nuvolos applications are isolated from one another, you cannot access that server directly from your local browser. Instead, use VS Code port forwarding.

In most cases, VS Code forwards the port automatically after the server starts. To verify this, open the **Ports** tab and check whether the server port appears there.

For example, if you run:

```
python3 -m http.server 9000
```

VS Code should detect the server and show a notification with an option to open it in the browser. You can also open the forwarded service later from the **Ports** tab by selecting **Open in Browser** for that port.

## Debugging Python in VSCode

VS Code provides a visual debugger for Python scripts. To enable it in Nuvolos:

1. Install the [Python Debugger](https://open-vsx.org/extension/ms-python/debugpy) extension.
2. Open the **Run and Debug** view from the left sidebar.
3. Start with the default configuration if you want to debug the Python file currently open in the editor.
4. To create a custom configuration, select the settings or gear control next to **Run and Debug** and add a launch configuration in `launch.json`.
5. In the configuration dropdown, select the debug configuration you want to use, then start debugging.

A common setting to customize is the current working directory. If your script must run from a specific folder, set `cwd` explicitly or use `${fileDirname}` to use the folder of the file being debugged. For more advanced configuration options: <https://code.visualstudio.com/docs/editor/debugging#_launch-configurations>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.nuvolos.com/user-guides/application-specific-guides/vscode.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
