This is an early work-in-progress extension for vscode-java. It aims at providing support for the JBang scripts written in Java (and partial support for Kotlin and Groovy).
Pre-requisites:
- JBang is installed and available in the PATH. Alternatively, you can set the
jbang.home
preference to point to aJBang
installation - vscode-java is installed.
Outstanding issues:
- Modifications to build.jbang files don't trigger autosynchronization nor do they report diagnostics. See jbang-eclipse#25.
- The Java Runtime for current file is not displayed in the status bar. See vscode-java#2552.
- If you open a folder containing JBang scripts, the first JBang script found will be used to configure a "Project"'s classpath. When configuring the
java.import.jbang.projectPerScript
setting totrue
, each script in the folder will be assigned a specific classpath. Toggling this setting requires calling theJava: Clean Java Language Server Workspace
command to take effect. - Modifying JBang directives in a file will update the classpath of the file.
- Snippets are provided for JBang directives.
- Autocompletion for dependencies in
//DEPS
- Autocompletion for
//SOURCES
and//FILES
- Partial autocompletion for
//JAVA_OPTIONS
,//JAVAC_OPTIONS
,//RUNTIME_OPTIONS
and//COMPILE_OPTIONS
- Display dependency documentation on completion/hover
- JBang scripts can be run/debugged from the
Run JBang
orDebug JBang
codelens, that show on top of the type declaration or main method, if there is one. - If a (.java) script is included in a Maven or Gradle project's hierarchy, right-clicking on the script and selecting
JBang > Synchronize JBang
will add the script's parent folder to the project's source path and the JBang dependencies will be added to the project's classpath. - Create a new JBang script from an existing template with the
JBang: Create a new script
command. - Annotation processors are automatically detected and configured.
- Partial support for
build.jbang
files: If a folder containingbuild.jbang
is opened, it'll be used to configure the Java settings of its //SOURCES. Currently, changes inbuild.jbang
require manually triggering theJBang > Synchronize JBang
command (via codelens or context menu) to take effect. - Export the script as a native binary, by right-clicking on the script and selecting the
JBang > Export as native binary
menu. This requires GraalVM to be installed with the native-image extension. See https://www.jbang.dev/documentation/guide/latest/usage.html#build-and-run-native-image-experimental - Install the script as an application available from the path, by right-clicking on the script and selecting the
JBang > install application
menu. Select the application name and whether to generate a native application or not. See https://www.jbang.dev/documentation/guide/latest/install.html - Automagically configures JBang-managed JDKs, i.e. no need to configure
java.configuration.runtimes
. - Partial support for Kotlin and Groovy scripts: completion for directive and run command are available, but no classpath management when editing the files.
- Autocompletion for JBang catalogs (i.e.
jbang-catalog.json
files)
jbang.home
: Specifies the folder path to the JBang directory (not the executable), eg.~/.sdkman/candidates/jbang/current
. On Windows, backslashes must be escaped, egC:\\ProgramData\\chocolatey\\lib\\jbang
. Used by theJBang: Create a new script
wizard and theRun JBang
code lens. Useful in casejbang
is not automatically picked up from the $PATH, for some reason.jbang.wizard.templates.showDescriptions
: When set totrue
(the default), shows JBang template descriptions in theJBang: Create a new script
wizard, else hides them.java.import.jbang.projectPerScript
: When set totrue
, each script found in the opened folder will be imported as its own project, with its own classpath.false
by default. Toggling this setting requires calling theJava: Clean Java Language Server Workspace
command to take effect.jbang.completion.onSelect.autosave
: When set totrue
(the default), automatically save the file after//DEPS
completion is selected, so the classpath gets updated.
Continuous Integration builds can be installed from the Visual Studio Marketplace, as Pre-release builds. Alternatively, you can head to https://github.com/jbangdev/jbang-vscode/releases/tag/latest, download the most recent jbang-vscode-<version>.vsix
file and install it by following the instructions here.
- Visual Studio Code or compatible editors
- Language Support for Java
- Node.js 14+
- JDK 17+
Step 1. Fork and clone this repository
Step 2. Fork and clone the jbangdev/jbang-eclipse repository, which contains the JBang/Eclipse core plugin and its jdt.ls extension
Note: Ensure that the cloned repositories are under the same parent directory:
YOUR_FOLDER/
├──── jbang-vscode/
├──── jbang-eclipse/
Step 3. Navigate into jbang-vscode/
$ cd jbang-vscode/
Step 4. Install npm dependencies
$ npm ci
Step 5. Build the JBang/Eclipse integration plugin and its jdt.ls extension
$ npm run build-ext
This script places the built jars in jbang-vscode/jars/
.
Step 6. Build the VS Code extension
$ npx vsce package
This will generate a jbang-vscode-<version>.vsix
file in the jbang-vscode/
directory.