Visual Studio Code
Visual Studio Code is an integrated development environment (IDE) from Microsoft which can be used for local development with numerous extensions and is highly customizable.
Resources Eager
VS Code is notable for misbehaving on the login nodes. Whenever possible strictly use it locally or see below how to configure it.
Running or Debugging Your Code
If Visual Studio Code is connected to remote systems, avoid running or debugging your code, as this will execute code on the login nodes, which can lead to performance issues or system disruptions. Instead, use the code-server environment, which provides a safer and more appropriate context for debugging tasks.
- Use VS Code locally and avoid connecting it to the systems. Save your changes to your project files with Git, and pull the changes onto the systems when ready to test.
- Use
nanoorvimto edit files directly on the systems. - For debugging and quick testing, you can load the
code-servermodule. - When all the above are not possible, configure VS Code for remote connections.
Local Usage¶
The advantages of using VS Code locally are: * speed & stability: running VS Code locally means fewer network interruptions and faster performance, which is ideal for iterative development; * direct access: you can interact with files, extensions, and terminals directly on your machine with zero latency; * offline capability: you’re not tied to an internet connection or remote server, so you can code anytime, anywhere.
We recommend that you develop locally with VS Code. You are then able to customize and extend VS Code with your preferred extensions and language.
Once you are ready to test your project on the systems, you can save your changes into a Git repository, push them to a remote host like GitHub or GitLab, then connect to the system and pull your changes to perform the test.
To learn more on how to work with source control, please see VS Code Source Control.
Once you have saved and pushed your changes to your remote repository, connect to the system via the terminal.
Then clone your repository (if it does not exist).
or change directory to your repository and pull the changes withThen test your changes in a short interactive job using minimal resources.
Editing Files on the Systems¶
While VS Code is great for local development, sometimes you need direct access to files on a remote system. In such cases, terminal-based editors like nano or vim offer a lightweight and efficient way to edit files directly from the command line.
If you prefer a graphical interface, the JupyterLab text editor provides a versatile alternative. It supports Markdown, Python scripts, and other formats.
Debugging and Testing¶
If you need to debug or test your code on the systems, you can start a code-server instance from Jupyter Lab.
- Access one of the options to launch JupyterLab.
- Select minimal resources and start an interactive JupyterLab job.
- On the Launcher tab, click on the VS Code launcher button.
Note
The code-server instance you are accessing is running in a compute job that does not have internet access.
The code-server module has several common extensions already available, but we can add more upon request.
Custom Extension Installation¶
TBD...
Configuration of VS Code for Remote Connection¶
If none of the above works for your case, one can configure VS Code to connect to a remote host with the Remote SSH extension.
SSH Configuration¶
If not done already, generate your SSH key and add your public SSH key on the CCDB.
Then create (or add) an SSH configuration file to your local computer:
Host *
ServerAliveInterval 30
User your_username
Host rorqual narval nibi fir
HostName %h.alliancecan.ca
Local Configuration¶
-
In VS Code, open the Command Palette: Press
Ctrl+Shift+P(Windows/Linux) orCmd+Shift+P(macOS). -
Open the user settings (
Preferences: Open User Settings (JSON)) and paste (or merge) the following configuration:local-settings.json{ // file-watch + search "files.watcherExclude": { "**/.git/**": true, "**/node_modules/**": true, "**/dist/**": true, "**/build/**": true, }, "search.exclude": { "**/.git/objects/**": true, "**/.git/subtree-cache/**": true, "**/node_modules/**": true, }, "search.maxThreads": 2, "search.ripgrep.maxThreads": 2, "search.useIgnoreFiles": true, // extensions & updates "remote.extensionKind": { "*": [ "ui" ], "ms-python.python": [ "ui" ] }, "remote.defaultExtensionsIfInstalledLocally": [ "GitHub.vscode-pull-request-github" ], // remote-ssh "remote.SSH.showLoginTerminal": false, "remote.SSH.enableDynamicForwarding": false, "remote.SSH.enableServerAutoShutdown": 30, "workbench.startupEditor": "none", } -
Save it and restart VS Code.
Remote Configuration¶
-
Log in to the system via an external terminal.
-
Create the directory.
-
Create the
settings.jsonmachine configuration. -
Copy the configuration below. You may need to manually merge settings with your own if any already.
system-settings.json{ // file-watch + search "files.watcherExclude": { "**/.git/**": true, "**/node_modules/**": true, "**/dist/**": true, "**/build/**": true, "/**": true, }, "search.exclude": { "**/.git/objects/**": true, "**/.git/subtree-cache/**": true, "**/node_modules/**": true, "/**": true, }, "search.followSymlinks": false, "search.maxThreads": 2, "search.ripgrep.maxThreads": 2, "search.useIgnoreFiles": true, "search.searchOnType": false, // extensions & updates "extensions.autoCheckUpdates": false, "extensions.autoUpdate": false, "update.mode": "none", "remote.extensionKind": { "*": [ "ui" ], "ms-python.python": [ "ui" ] }, // Copilot "chat.agent.enabled": false, "github.copilot.enable": { "*": false, }, "remote.defaultExtensionsIfInstalledLocally": [ "GitHub.vscode-pull-request-github" ], // telemetry & git "telemetry.enableTelemetry": false, "telemetry.enableCrashReporter": false, "telemetry.telemetryLevel": "off", "telemetry.feedback.enabled": false, "git.autofetch": false, "git.enableStatusBarSync": false, // remote-ssh "remote.SSH.showLoginTerminal": false, "remote.SSH.enableDynamicForwarding": false, "remote.SSH.enableServerAutoShutdown": 30, "workbench.startupEditor": "none", }
Connecting¶
- Open the Command Palette in VS Code: Press
Ctrl+Shift+P(Windows/Linux) orCmd+Shift+P(macOS). - Type
remoteand then selectConnect to Host... - Choose the host (remote system) and confirm.
You'll now be connected to a login node.
Login Node
Do not test, debug or run your code as it runs on the login node!
Closing Your Connection¶
- Open the Command Palette in VS Code: Press
Ctrl+Shift+P(Windows/Linux) orCmd+Shift+P(macOS). - Type
remoteand then selectRemote-SSH: Kill VS Code Server on Host... - Choose the host (remote system) and confirm.
- Open the File menu, and select
Close Remote Connection.
Advanced - Connecting to an Interactive Compute Node¶
The following is only needed for advanced usage.
Update your ssh configuration to add the following lines:
- In an external terminal, connected to the system via an ssh connection, start a new interactive job (with
salloc) with at least 2000M of memory.- Note the allocated compute node name.
- If you need to work with
SLURM_*environment variables in VS Code, save them all in a source file:
- In VS Code, start a new remote session with the name of the allocated compute node.
- Press
F1orCtrl+Shift+Pto start the command prompt>in the Command Palette. - Start typing Remote and select Remote-SSH: Connect to Host... > Remote-SSH: Connect to Host...
- Enter the noted compute node name.
- If you get prompted for the type of operating system, select Linux.
- Press
- If you need to work with
SLURM_*environment variables, navigate to the working directory in a VS Code terminal and source theslurm_var.shfile.
Special Notes¶
- VS Code is banned on tamIA login nodes.
- VS Code is banned on Fir login nodes.