GraalVM Visual Studio Code Extensions

This section explains how to start using GraalVM Visual Studio Code Extension. 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 an extension 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.

Following features are supported by GraalVM VSCode Extension from VSCode Marketplace:

Install Extension

GraalVM VSCode extension 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):

To verify whether the path to GraalVM home directory is provided, navigate to Preferences -> Settings -> Extensions -> GraalVM -> Home or open the VS Code’s integrated terminal using the View -> Terminal menu command and type echo $GRAALVM_HOME.

If the path is provided properly, the following debug configurations can be used:

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:

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.