How do I use Visual Studio Code ?
VS Code editor is installed on all CS machines. You can launch the editor by finding it in the Applications menu.
If you would like to launch it from within a terminal, via the code
command, you will need to load the necessary environment module as shown below:
module load ide/visual-studio-code
After that, the code
command will be available in your current terminal session.
Refer to Environment Modules page for more information on how to find and use modules and make them persistent.
How do I use Visual Studio Code remotely?
In this use-case Visual Studio Code is installed and running on your personal machine (laptop or desktop). You write and edit code on your laptop, but connect to the CS machines for running the code. The connection is handled by a proprietary SSH extension which you will need to install on your laptop.
It is not feasible for SNA to support this use case, yet we are listing some common issues and troubleshooting steps below.
Troubleshooting Remote VS Code Connection
SNAs are not experts on the specific details of VS Code or its proprietary extensions, however, we have encountered a few common issues that users may experience when using VS Code remotely. These issues include:
- Connection drops
- VS Code repeatedly asking for a password even though supplied password is correct
- Multiple sessions can’t exist simultaneously
- Only the session from the last connected server will work
- Connections work on some machines and do not work on some other machines.
Possible Causes
When a user connects remotely to a CS machine via VS code, it creates a sub-directory under the user’s home directory to facilitate the connection. We believe that corruption of files under vscode directories is likely the main cause of most connection issues. Since home directories on CS Linux machines are shared across machines, your home directory and its content is the same on all machines. This increases the likelyhood of clashes and overwriting files when one logs in to multiple machines via remote vscode. Other causes of corruption could be:
- Accessing multiple CS machines simultaneously while using VS Code.
- Ungraceful shutdown of a connection on one machine and re-connecting to another machine.
Suggested Solution
The ideal solution is to change the default path of VS Code server directory to a path local on the remote host you are connecting to.
By default the location is ~/.vscode-server
, which is in your home directory. The following steps will show how to change this.
- Delete the
~/.vscode-server
directory by logging in without VS Code, using an SSH client to connect (see here). Enter the following commands:
pkill -u <your-CS-username> node
rm -rf ~/.vscode-server
- Open VS Code on your laptop
- Go to the Settings
- Go to Remote SSH extension’s settings by typing
@ext:ms-vscode-remote.remote-ssh install
in the search box (see screenshot below) - Now, under Server Install Path, click Add Item and add the following key:value pair
Item = host
Value = /s/$HOSTNAME/a/tmp/$USERThe “host” in the Item field must match with the host you have in your SSH config file. The Value field stays the same for all hosts, so use the exact value as listed above.
- Hit Ok
- Do this for each and every host in your SSH configuration. Click Add Item to add more hosts. Notice how the path stays the same for all hosts, see screenshot below
- Now connect to one of the remote machines and you would notice that the
.vscode-server
directory gets created on a local filesystem on this host, not in your home directory.Always close your remote connections via File –> Close Remote Connection instead of just closing the window.