Skip to main content

Code Server for VS Code

Visual Studio Code (VS Code) is a lightweight and highly customizable source code editor developed by Microsoft. It is designed to provide developers with a powerful and efficient environment for coding, debugging, and building applications. VS Code supports a wide range of programming languages and offers features like syntax highlighting, intelligent code completion, debugging capabilities, and Git integration. It also provides a vast library of extensions that enhance its functionality, allowing developers to personalize their coding experience based on their preferences and requirements.

For a detailed documentation of VS Code, please see https://code.visualstudio.com/docs.

tip

While development is very convenient using VS Code sessions launched via the terrabyte portal, and we recommend this as the preferred approach, these sessions do not allow for submitting SLURM jobs for testing because the sessions themselves run as a SLURM job, and submitting SLURM jobs from within a running SLURM job is prohibited. However, -although a bit less convenient- it is possible to connect to terrabyte via a local VS Code session through SSH, which allows for submitting SLURM jobs. We explain this possibility at the bottom of this page..

Start a new VS Code session

In order to start a new VS Code session on the terrabyte Portal,

  1. Click on the Code Server for VS Code icon on the dashboard or select Code Server for VS Code in the drop down list under Development in the upper menu bar.

Portal Development menu VS Code entry

  1. Select the cluster partition and the resources to be used for the session and click on Launch.

Portal VS Code allocation

  1. Once the session is ready, you can connect to it via Connect to VS Code.
tip

If you have to wait for long times until your session gets launched, select a different cluster partition. hpda2_compute is usually a good choice. You may check available cluster resources with sinfo on the login node.

Portal VS Code launcher

  1. A new browser window with VS Code will open. Be patient: It may take some seconds until the application is completely loaded. Your browser window may stay blank white during loading.

Portal VS Code welcome page

  1. By default, the file explorer shows your home directory. You can access other folders/projects on the DSS by clicking on the menu icon Portal menu stack icon → File → Open Folder.

  2. You can install and activate any of the thousands extensions available by clicking on the extension icon Portal VS Code extensions icon and searching for a key word.

Portal VS Code extensions

  1. You can close and resume the browser window anytime during your specified run time. By clicking on My Interactive Sessions in the upper menu bar, you can resume your session as explanied in step 3.

  2. In order to terminate the session before the run time ends, go to My Interactive Sessions, select the respective session and click on Delete.

Example: Develop, run and debug Python code in a custom conda environment

If not yet done: Install the Python extension (see step 6 of example above).

  1. Change into the working directory where your Python code is located by clicking on the menu icon Portal menu stack icon → File → Open Folder.

  2. In the explorer, select the file you like to modify.

  3. Do your modifications. They will be saved automatically.

  4. Activate your custom environment to run the code with:

    a. Press F1

    b. In the search-window, type Python and choose Python: Select Interpreter

    Portal VS Code select interpreter

    c. Click on + Enter interpreter path...

    Portal VS Code enter interpreter path

    d. Enter the path to the Python-binary of your environment. You may click on Find... in order to browse for the file.

    Portal VS Code select interpreter

  5. Click the Run and Debug-icon, and then Run and Debug in order to run the code and get debugging information

Portal VS Code rund and debug

Portal VS Code debugger

Example: Connect to DLR-GitLab

  1. Change to the explorer view:

Portal VS Code explorer view icon

  1. Change to the folder where to clone the GitLab repository to: menu icon

Portal VS Code menu icon → File → Open Folder

  1. If necessary, create a new folder and change into it as described in the step before.

Portal VS Code new folder

  1. Open a terminal: menu icon Portal VS Code menu icon → Terminal → New Terminal

  2. In the terminal, your working directoy is automatically set to the folder in your explorer. Now clone the repository by typing into the terminal Attention: You will be asked for your DLR-GitLab credentials in a popup-window.

git clone https://gitlab.dlr.de/your/repo
  1. If not yet done, specify your Git user name and email:
git config user.name "Surname, Name"
git config user.email "Name.Surname@dlr.de"
  1. Select the branch you would like to work with or create a new branch by clicking on the current branch in the lower left corner (in our case the master branch).

Portal VS Code create new branch

  1. The current branch will be displayed in the lower left corner.

  2. Make changes, test the code, etc.

  3. To commit the changes, change to the source control section where all changes are listed. Enter a commit-message and click on Commit. You may also stage the changes beforehand or directly stage them when prompted. Attention: You will be asked for your DLR-GitLab credentials in a popup-window.

Portal VS Code commit

Merge Requests

Merge requests can be made directly out of VS code, but this requires to install the extension "GitLab Workflow". The installation and setup process is very straightforward and explained in the official GitLab documentation: https://docs.gitlab.com/ee/user/project/repository/vscode.html

Once the GitLab workflow extension has been setup, it can be opened via the GitLab-icon Portal VS Code GitLab icon and merge requests can be made by clicking on Create MR at the bottom left of the browser window:

Portal VS Code merge request

Connect to terrabyte via SSH from a local VS Code session

  1. Open your local VS Code editor and install the Remote-SSH extension.

  2. Got to settings (Crtl + ,) and search for remote.SSH.showLoginTerminal in the search field. Activate Always reveal the SSH login terminal. This setting only needs to be configured once.

  3. Press F1 to open the list of available extension functionalities, select Remote-SSH: Add new SSH-host, and enter the SSH command to connect to the terrabyte login node (ssh [your ID]@login.terrabyte.lrz.de).

  4. Press F1 and select Remote-SSH: Connect to Host, then select login.terrabyte.lrz.de.

  5. In the terminal enter your terrabyte credentials and your 2FA token.

  6. Open the folder where you would like to work. You will unfortunately be prompted again for your credentials. After completing another round of authentication, you should be able to work normally.

  7. To test your code as a SLURM job, open a new terminal and submit your SLURM script with sbatch.