14 VS Code Sessions | RStudio Workbench Edition 1.4.1707-4

14.1 Overview

RStudio Workbench allows you to launch VS Code sessions from the home page via the Job Launcher, if configured. Users can start VS Code sessions that allow them to work with VS Code while still working within the administrative framework provided by RStudio, such as authentication, PAM session management, etc.

Note: Before VS Code sessions can be launched, the Job Launcher must be setup correctly. For more information, see the Job Launcher section.

Note: RStudio is not affiliated with Microsoft. Your usage of the open source code-server and VS Code are subject to their respective licenses: see here and here.

14.1.1 RStudio Workbench Extension

VS Code sessions are intended to be used with the RStudio Workbench VS Code extension installed. The extension provides users with a button to open RStudio Workbench homepage in a new tab and enables users to easily and securely proxy Shiny, Dash, and Streamlit web servers. If the extension is not installed, VS Code sessions will launch but without the additional features; users working on these types of apps will not be able to access the servers they are running on.

14.2 Installation

14.2.1 General Installation

In order to add VS Code integration to RStudio Workbench, you must first install the open-source code-server wrapper, available at rstd.io/vs-code-server. code-server is a wrapper which allows access to VS Code via a webserver in a browser, allowing Workbench to create VS Code sessions and proxy them through the browser.

To install, simply run the command rstudio-server install-vs-code <path to installation directory>. This will install the code-server binary, and automatically configure /etc/rstudio/vscode.conf. The default configuration will allow users to manage their own extensions; if use of a global extensions directory is desired, then vscode.conf should be updated to include --extensions-dir after it has been created. For example, to install everything at /opt/code-server:

# likely need root privilege to install to /opt
sudo rstudio-server install-vs-code /opt/code-server

Once the installation completes, you’ll need to restart the RStudio service for it to detect availability of VS Code sessions.

Note: You must also install code-server on any Launcher nodes (for Local or Slurm plugins) and within any containers used (if using Kubernetes).

If you’d like to install everything manually, simply download the code-server Linux distributable and extract it to the desired location on the RStudio Workbench host(s).

For example, to manually install code-server under /opt:

# create directory to house code-server
mkdir /opt/code-server
cd /opt/code-server

# download the code server package
wget https://rstd.io/vs-code-server -O vs-code-server.tar.gz

# extract code-server binary
tar zxvf vs-code-server.tar.gz --strip 1

# remove the archive
rm vs-code-server.tar.gz

14.2.2 Installing the RStudio Workbench Extension

14.2.2.1 Requirements

The extension requires a minimum version of code-server of 3.8.1, and the install-vs-code-ext command will upgrade code-server automatically for you if you include the -d flag with the directory to install code-server in. Compatability between code-server, RStudio Workbench, and the RStudio Workbench extension is only guaranteed with code-server version 3.8.1, though later versions may work as expected. The install-vs-code-ext command can upgrade code-server automatically for you if you include the -d flag with the directory that code-server should be installed in. For example, your command may look like this:

rstudio-server install-vs-code-ext -d /opt/code-server

14.2.2.2 Installation

If using a global extensions directory, the install-vs-code-ext script can be used to install the latest version of the extension. This script is run when upgrading RStudio Workbench, but may not be able to install the extension if code-server does not meet the minimum version described above.

If allowing user extension directories, and the requirements above are met, the extension will be installed on a per user basis when the user launches their first VS Code session.

14.2.3 Installing Language Extensions

If code-server has been configured with a global extensions directory, then code-server’s extensions marketplace will be disabled for users who do not have write access to this directory. Extensions can only be installed by users with write access to this global directory. Otherwise, users are able to manage their own extensions, and installs must be performed on a per user basis by the user.
There are three ways in which extensions can be installed to code-server:

  1. Install the extension through code-server’s hosted repository. This can be done from within a VS Code session via the UI (similar to how extensions are added in VS Code). Alternatively, this can be done via the command line with the following command, with the --extensions-dir argument omitted when a global directory is not in use:
/opt/code-server/code-server --extensions-dir /opt/code-server/extensions --install-extension <extension name>
  1. Download an extension in VSIX format from an online marketplace such as Open VSX. Then, install it using the --install-extension command like the example above, passing the VSIX file path as the extension name. Note that if the latest version of the extension is incompatible with the version of code-server, it will fail to install. You can try using an older version of the extension in this case.

Note: It is against VS Code’s Terms of Service to use the official Marketplace extensions with third party tools like code-server. We strongly recommend using a free and open source alternative like Open VSX.

  1. Build the extension from source. There are several extensions freely available on GitHub that can be built into a VSIX file yourself and then installed via the --install-extension command. Building third party extensions from source is outside of the scope of this document.

RStudio does not provide support for external extensions. If you have questions or issues we encourage you to check Stack Overflow, the extension’s repository, or code-server’s repository.

14.3 Configuration

14.3.1 VS Code Configuration

Configuration of the VS Code feature is handled via the config file /etc/rstudio/vscode.conf. Note that this file is not automatically created by RStudio, and must be created before being configured, and the VS Code feature is disabled by default. The following table lists the various configuration options that are available to be specified in the vscode.conf configuration file:

/etc/rstudio/vscode.conf

Config Option Description Default Value
enabled Enables launching of VS Code sessions. 0 (disabled)
exe Path to the code-server executable. VS Code sessions rely on the open source code-server project. For more information, see the project site /opt/code-server/code-server
version The version of VS Code code-server being used. If set to auto, the version is automatically detected by running the code-server version command. If VS Code is being launched via the Launcher and is not installed locally, you are strongly encouraged to set this to the version in use. Running against multiple different code-server versions simultaneously in different Launcher clusters is not supported – they must all be running the same version, or issues will occur. auto
args Arguments to be passed to the code-server command. It is strongly recommended that you do not change this unless you know what you’re doing! You can supply an --extensions-dir= to point to previously installed extensions via this parameter. If no –host argument is supplied, a default of –host=0.0.0.0 will be assumed. –host=0.0.0.0
session-clusters Comma-delimited list of available Job Launcher clusters for launching VS Code sessions. Leave blank to specify all clusters.
default-session-cluster The default Job Launcher cluster to use when launching a VS Code session.
default-session-container-image The default container image to use when launching a containerized VS Code session.
session-container-images Comma-delimited list of images that may be used for running VS Code sessions.
vscode-session-path Path to the VS Code Session launcher executable/script. It is recommended that you do not change this unless you know what you’re doing, and you need to point to a different script. /usr/lib/rstudio-server/bin/vscode-session-run
session-no-profile Enables/disables running of bash profile scripts when starting VS Code sessions. 0 (run profile scripts)

For example, your vscode.conf file might look like the following:

/etc/rstudio/vscode.conf

exe=/usr/bin/code-server
enabled=1
default-session-cluster=Kubernetes
default-session-container-image=rstudio:vscode-session

14.3.2 VS Code code-server Versions

Currently, RStudio Workbench supports code-server 3.8.1. Due to differences between code-server versions, RStudio Workbench needs to know the versions of code-server that is in use. It can be automatically detected by RStudio Workbench on start up by running the code-server command, or can be specified by using the version setting in /etc/rstudio/vscode.conf. Automatic version detection is done if the default value of auto is used.

If you are running VS Code in a remote cluster like Kubernetes, you will need to manually specify the version of code-server if it is not locally installed or is not running the same version as the remote cluster. Due to version differences, running against multiple different versions of code-server in different Launcher clusters simultaneously is not supported – the versions must match in all clusters.

You can manually specify the version number like so:

/etc/rstudio/vscode.conf

version=3.8.1

14.3.3 VS Code User Settings

By default, code-server writes VS Code user settings under ~/.local/share/code-server. This can be changed by adding the user-data-dir path argument to the VS Code options, like so:

/etc/rstudio/vscode.conf

exe=/usr/bin/code-server
args=--host=0.0.0.0 --verbose
user-data-dir=<desired user path>

Note that the specified in the configuration can contain the ~ to represent the user’s home directory.

Whenever a VS Code session is launched, RStudio automatically merges the user settings template file at /etc/rstudio/vscode-user-settings.json with the user’s settings file. This file should be a valid JSON file that contains desired VS Code user settings. Any matching settings that already exist in the user settings file are not overriden, allowing users the freedom to customize their environment. You should use the vscode-user-settings.json file to provide them with a simple baseline configuration.

If you installed VS Code via the sudo rstudio-server install-vs-code command, a simple template is created for you automatically which instructs VS Code to use the bash shell by default and to disable automatic extension updates. The generated file looks like the following:

**/etc/rstudio/vscode-user-settings.json

{
      "terminal.integrated.shell.linux": "/bin/bash",
      "extensions.autoUpdate": false,
      "extensions.autoCheckUpdates": false
}

14.3.4 Launcher Configuration

When creating containerized VS Code sessions via the Job Launcher, you will need to specify mount points as appropriate to mount the users’ home drives and any other desired paths. In order for sessions to run properly within containers, it is required to mount the home directories into the containers.

For more information, see Launcher Mounts. Note that you can specify the Workbench with VS Code to configure mount entries that should only be mounted for VS Code sessions.

Note: Only a user’s home folder is visible within VS Code sessions. To access other folders, create symbolic links to them within the home folder.

14.3.5 Container Configuration

When running VS Code sessions in containers, such as by using the Kubernetes Job Launcher plugin, you will need to ensure that the image(s) used to launch VS Code sessions contain, at minimum, the following:

  1. code-server installation
  2. RStudio Workbench session binaries
  3. If creating container users (see Server Configuration), you must have the libuser1-dev or libuser-devel packages, depending on your platform to install the libuser library and development tools.

For ease of use, it is recommended that you use the r-session-complete Docker image as a base for any VS Code session images you intend to create.

14.4 Troubleshooting

If you experience issues related to running VS Code sessions, you can use the Launcher verification tool which will attempt to launch VS Code sessions and provide diagnostic output about what could be going wrong. For more information, see the Troubleshooting section for the Job Launcher integration documentation.

Read more here: Source link