VS Code Server#

The VS Code Server app provides the browser version of Visual Studio Code (VS Code). For more information, check out the official VS Code guidelines.

Before you connect#

VS Code automatically generates the hidden folders .vscode and .vscode-server in your $VSC_HOME, which can become quite big, especially when installing multiple extensions. To prevent $VSC_HOME from filling up, we recommend creating symlinks to redirect these folders to your $VSC_DATA directory. If these folders already exist, move them to your $VSC_DATA directory before creating symlinks. Execute the following commands to automate the process:

[[ -d ~/.vscode ]] && mv -nv ~/.vscode $VSC_DATA/
[[ -d ~/.vscode-server ]] && mv -nv ~/.vscode-server $VSC_DATA/
mkdir -pv $VSC_DATA/vscode $VSC_DATA/vscode-server
[[ -L ~/.vscode ]] || ln -sv $VSC_DATA/vscode ~/.vscode
[[ -L ~/.vscode-server ]] || ln -sv $VSC_DATA/vscode-server ~/.vscode-server

Terminal in VS Code#

To open a terminal window in VS Code, click the three horizontal lines in the top left corner and select ‘Terminal - New Terminal’. This will open a shell on the node you are running your session on. You can use this as a regular shell, meaning that you can submit jobs, load modules and so on. Notice that, by default, you are starting in your $VSC_HOME directory.

VS Code as an IDE#

VS Code contains many different options and menus, but we will only discuss how to set it up as an integrated development environment (IDE) for your favorite coding language. For any language you want to use you need two things: an installation of the specific interpreter or compiler, and a VS Code extension that allows you to connect to it. The extensions can be found in the ‘extensions’ menu. In what follows, the steps for Python are described.

Python IDE#

There are multiple Python extensions available, but only the Microsoft ‘Python’ extension has been tested by VSC support. To install this extension, go to ‘Extensions’, search for ‘Python’, and install the one developed by ‘ms-python’.

Once installed, if you open a script, you can use VS Code as an IDE and run the lines of code from within the script (keyboard shortcut shift+enter). VS Code will start a Python session with the currently selected Python interpreter.

The ‘Python’ extension gives you the possibility to choose other interpreters as well. In the right bottom corner, you can see the selected Python version right next to ‘Python’. If you click the Python version, a list of Python versions and paths will appear in the command palette. You can also use virtual environments or Conda environments here (if you have any environments already, you should see them here as well). We recommend against using any of the ‘system’ Python versions (located under /bin or /usr/bin), as they are quite old.

For more information about creating customized Python environments, have a look at the documentation on VSCdocPython packages.

Python modules and environments#

To use Python and Python packages provided by the VSCdocsoftware modules in the Python IDE, follow these steps:

  1. In the ‘Pre-run Scriptlet’ of the resources form, module load the modules that you need. A commonly used software module is SciPy-bundle, a bundle of data science packages such as numpy, pandas, and scipy.

  2. In the VS Code interface, select the corresponding Python version + path as outlined above. Make sure to select the exact same path as that of your loaded Python module. To get the path, type the following command in your VS Code terminal:

    which python
    

The steps for using virtual environments on top of loaded software modules are exactly the same. Note that activating the virtual environment in the ‘Pre-run Scriptlet’ is not required: just selecting the Python version + path located in the virtual environment at <path-to-venv>/bin/python3.x is sufficient.

Running Jupyter inside VS Code#

It’s also possible to edit/run Jupyter notebooks inside VS Code. Below are the instructions for Python:

  1. When using Jupyter with a Pure module environment, make sure to load any modules you need in the ‘Pre-run scriptlet’ in the resources form.

    If you also need the Matplotlib Lab extension, make sure to also load a compatible ipympl module.

  2. In your VS Code session, install the ‘Jupyter’ extension developed by ‘ms-toolsai’.

  3. Open a Jupyter notebook or create a new one.

  4. Click ‘Select Kernel’ at the top right of the window.

  5. In the command palette, select ‘Python Environments…’, next select the Python version and path that you need.