GraalVM Visual Studio Code Extensions

This section explains how to start using GraalVM Visual Studio Code Extensions, introduced in the 19.2 version. Visual Studio Code (from now on VS Code) is a source-code editor  that provides embedded Git and GitHub control, syntax highlighting, code refactoring etc.. To enable a polyglot environment in VS Code, we created extensions for GraalVM supported languages: JS, Ruby, R, Python. This allows a simple registration of GraalVM as a runtime, code editing and debugging of polyglot applications.

The following extensions are available from VSCode Marketplace:

  • GraalVM – a VS Code extension providing the basic environment for editing and debugging programs running on GraalVM and includes JavaScript and Node.js support by default.
  • GraalVM R – a VS Code extension providing the basic support for editing and debugging R programs running on GraalVM.
  • Graalvm Ruby – a VS Code extension providing the basic support for editing and debugging Ruby programs on GraalVM.
  • GraalVM Python – a VS Code extension providing the basic support for editing and debugging Python programs running on GraalVM.
  • GraalVM Extensions Pack – pack of all above listed extensions for simpler installation.

Install Extensions

GraalVM VSCode extensions can be simply installed from VSCode IDE Extensions panel by searching for GraalVM

GraalVM Extension

Upon the graalvm extension installation, launch VS Code by double-clicking on the icon in the launchpad or by typing code . from the CLI. The user is then requested to provide a path to the GraalVM home directory.

For that purpose, next options can be used (invoke by Ctrl+Shift+P hot keys combination):

  • Select GraalVM Installation - Provides the UI to select an already installed GraalVM. By default, the following locations are searched for the already installed GraalVM:
    • the extension’s global storage
    • /opt folder as the default RPM install location
    • PATH environment variable content
    • GRAALVM_HOME environment variable content
    • JAVA_HOME environment variable content
  • Install GraalVM - Downloads the latest GraalVM release from Github and installs it within the extension’s global storage.
  • Install GraalVM Component - Downloads and installs one of the GraalVM’s optional components.

To verify whether the PATH environment variable is valid, navigate to Code -> Preferences -> Settings -> Extensions -> GraalVM -> Home:

If the path to GraalVM home directory is provided properly, the following debug configurations can be used:

  • Attach - Attaches debugger to a locally running GraalVM.
  • Attach to Remote - Attaches debugger to the debug port of a remote GraalVM.
  • Launch JavaScript - Launches JavaScript using GraalVM in a debug mode.
  • Launch Node.js Application - Launches a Node.js network application using GraalVM in a debug mode.

Languages interoperability is one of the defining features of GraalVM, enabled with Polyglot APIs. The code completion invoked inside JavaScript sources provides items for Polyglot.eval(...), Polyglot.evalFile(...) and Java.type(...) calls.

For JavaScript sources opened in the editor, all the Polyglot.eval(...) calls are detected and the respective embedded languages are injected to their locations. For example, having an R code snippet called via the Polyglot API from inside the JavaScript source, the R language code is embedded inside the corresponding JavaScript string and all VS Code’s editing features (syntax highlighting, bracket matching, auto closing pairs, code completion, etc.) treat the content of the string as the R source code.

R Extension

Upon the extension installation in VS Code, GraalVM is checked for presence of the R component and a user is provided with an option of an automatic installation of the missing component. The Ctrl+Shift+P command from the Command Palette can be also used to invoke Install GraalVM Component option to install the R component manually.

Once GraalVM contains the R component, the following debug configurations can be used to debug your R scripts running on GraalVM:

  • Launch R Script - Launches an R script using GraalVM in a debug mode.
  • Launch R Terminal - Launches an integrated R terminal running on GraalVM in a debug mode.

Thanks to languages interoperability within GraalVM, the code completion invoked inside R sources provides items for eval.polyglot(...) and new("<Java type>", ...) calls. For R sources opened in editor, all the eval.polyglot(...) calls are detected and the respective embedded languages are injected to their locations.

Please note, this R extension depends on the basic support for R language and GraalVM extension in VS Code.

Ruby Extension

Similar to the above R extension installation, GraalVM is checked for presence of the Ruby component and a user is provided with an option of an automatic installation of the missing component. The Ctrl+Shift+P command from the Command Palette can be also used to invoke Install GraalVM Component option to install the Ruby component manually.

Once GraalVM contains the Ruby component, Launch Ruby Script debug configuration can be used to run your Ruby script in a debug mode.

The code completion invoked inside Ruby sources provides items for Polyglot.eval(...), Polyglot.eval_file(...) and Java.type(...) calls. As with other languages, all the Polyglot.eval(...) calls are detected and the respective embedded languages are injected to their locations. For example, the JavaScript language code is embedded inside the corresponding Ruby string and all VS Code’s editing features (syntax highlighting, bracket matching, auto closing pairs, code completion, etc.) treat the content of the string as the JavaScript source code.

This Ruby extension requires a default Ruby language support and GraalVM extension in VS Code.

Python Extension

GraalVM is checked for presence of the Python component and a user is provided with an option of an automatic installation of the missing component, similar to the previous R and Ruby extensions. The Ctrl+Shift+P command from the Command Palette can be also used to invoke Install GraalVM Component option to install the Ruby component manually.

Once GraalVM contains the Ruby component, Launch Python Script debug configuration can be used to run the Python script in a debug mode.

Python VS Code extension requires a default Python language support and GraalVM extension in VS Code.