Giter Site home page Giter Site logo

jbang-vscode's Introduction

Visual Studio Marketplace Installs Build Status License

JBang for Visual Studio Code

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 a JBang 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.

Features

  • 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 to true, each script in the folder will be assigned a specific classpath. Toggling this setting requires calling the Java: 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 or Debug 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 containing build.jbang is opened, it'll be used to configure the Java settings of its //SOURCES. Currently, changes in build.jbang require manually triggering the JBang > 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)

Preferences

  • jbang.home: Specifies the folder path to the JBang directory (not the executable), eg. ~/.sdkman/candidates/jbang/current. On Windows, backslashes must be escaped, eg C:\\ProgramData\\chocolatey\\lib\\jbang. Used by the JBang: Create a new script wizard and the Run JBang code lens. Useful in case jbang is not automatically picked up from the $PATH, for some reason.
  • jbang.wizard.templates.showDescriptions : When set to true (the default), shows JBang template descriptions in the JBang: Create a new script wizard, else hides them.
  • java.import.jbang.projectPerScript : When set to true, 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 the Java: Clean Java Language Server Workspace command to take effect.
  • jbang.completion.onSelect.autosave : When set to true (the default), automatically save the file after //DEPS completion is selected, so the classpath gets updated.

Installation:

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.

Development Setup

Prerequisites

Setup

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.

jbang-vscode's People

Contributors

fbricon avatar renovate[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

fbricon snjeza

jbang-vscode's Issues

NullPointerException during "Updating workspace folders"

After migrating file to a new machine I got these errors in the output console in VS Code after adding the folder containing jbang scripts to my workspace:

[Error - 10:01:02 AM] May 25, 2023, 10:01:02 AM An internal error occurred during: "Updating workspace folders".
Cannot invoke "java.util.Collection.stream()" because "triggerFiles" is null
java.lang.NullPointerException: Cannot invoke "java.util.Collection.stream()" because "triggerFiles" is null
	at dev.jbang.eclipse.ls.internal.JBangImporter.applies(JBangImporter.java:46)
	at org.eclipse.jdt.ls.core.internal.managers.ProjectsManager.importProjects(ProjectsManager.java:149)
	at org.eclipse.jdt.ls.core.internal.managers.ProjectsManager$2.runInWorkspace(ProjectsManager.java:252)
	at org.eclipse.core.internal.resources.InternalWorkspaceJob.run(InternalWorkspaceJob.java:43)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)

I can't tell whether this was fatal. After a period of time it seemed to resolve itself. Not sure if it was because the Java tooling was still initializing or not?

VS Code Version Info:

Version: 1.78.2
Commit: b3e4e68a0bc097f0ae7907b217c1119af9e03435
Date: 2023-05-10T15:00:40.428Z
Electron: 22.5.2
Chromium: 108.0.5359.215
Node.js: 16.17.1
V8: 10.8.168.25-electron.0
OS: Darwin arm64 21.6.0
Sandboxed: Yes

JBang Extension Version: v0.6.0

Note that while my local machine is running Mac OSX, I'm using the Remote development extensions to connect to a remote Linux (AlmaLinux 8) host where the jbang scripts/code resides.

completion on partial dependencies

can the search/lookup for deps do partial search instead of requiring perfect match?

ie. can //DEPS picocli have a quickfix to look up "info.picocli" as an option?

support Modules

when //MODULE is present vscode java should put dependencies on module classpath not the classpath so the compiler does not complain about missing modules :)

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Warning

These dependencies are deprecated:

Datasource Name Replacement PR?
npm npm-run-all Available

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

asdf
.tool-versions
  • node 20.15.1
github-actions
.github/workflows/ci.yaml
  • actions/checkout v4
  • actions/checkout v4
  • actions/setup-node v4
  • actions/setup-java v4
  • actions/upload-artifact v4
.github/workflows/release.yaml
  • actions/checkout v4
  • actions/checkout v4
  • actions/setup-node v4
  • actions/setup-java v4
  • softprops/action-gh-release v1
npm
package.json
  • axios 1.7.7
  • fast-xml-parser ^4.5.0
  • lru-cache 11.0.1
  • shelljs ^0.8.5
  • vscode-languageclient ^8.1.0
  • @types/mocha 10.0.8
  • @types/node 20.14.11
  • @types/vscode 1.90.0
  • @typescript-eslint/eslint-plugin 8.6.0
  • @typescript-eslint/parser 8.6.0
  • @vscode/test-electron 2.4.1
  • esbuild 0.23.1
  • eslint 9.10.0
  • glob 11.0.0
  • mocha 10.7.3
  • npm-run-all ^4.1.5
  • rimraf ^6.0.1
  • typescript 5.5.2
  • vscode ^1.90.0

  • Check this box to trigger a request for Renovate to run again on this repository

VSCode JBang fails when executing on Windows

Context

On Windows, the extension fails with the following error:

Command 'Jabng: Run JBang' resulted in an error

Cannot read properties of undefined (reading 'fsPath')

image

Environment

Windows: 11
JBang: v0.8.2023082100

debug console fails when running debug jbang

put breakpoint, debug jbang and try evaluate statement in the debug console and I get:

Cannot evaluate because of java.lang.IllegalStateException: Cannot evaluate, please specify projectName in launch.json..

Project fails to sync on gitpod

When opening https://github.com/fbricon/jbangdemo in gitpod, main.java shows an error:

Picked up JAVA_TOOL_OPTIONS:  -Xmx3489m
{
  "originalResource": "/workspace/jbangdemo/src/main.java",
  "backingResource": "/workspace/jbangdemo/src/main.java",
  "applicationJar": "/home/gitpod/.jbang/cache/jars/main.java.7dca200684991d826e312d7e15087740a698e30ff2ca7511d5ec9b1b7e97ab4c.jar",
  "dependencies": [
    "com.github.jamesnetherton:lolcat4j:0.4.0"
  ],
  "resolvedDependencies": [
    "/home/gitpod/.m2/repository/com/github/jamesnetherton/lolcat4j/0.4.0/lolcat4j-0.4.0.jar"
  ],
  "availableJdkPath": "/home/gitpod/.sdkman/candidates/java/current"
}

the "Picked up JAVA_TOOL_OPTIONS: -Xmx3489m" message mixed with the json output is unexpected, breaking jbang-eclipse integration.

quote arguments to avoid problems with spaces in directory

here is what happens when running from folder with a space:

jbang /Users/max/Dropbox/My Mac (Maxs-MBP-2.localdomain)/Downloads/demo/gg/fetch.java
❯ jbang /Users/max/Dropbox/My Mac (Maxs-MBP-2.localdomain)/Downloads/demo/gg/fetch.java
[jbang] [ERROR] Script or alias could not be found or read: '/Users/max/Dropbox/My'
[jbang] Run with --verbose for more details

should have been jbang "/Users/max/Dropbox/My Mac (Maxs-MBP-2.localdomain)/Downloads/demo/gg/fetch.java"

No release version

When installing on Windows 10 VS code - get this message prompt - - Can't Install release version of 'jbandev.jbang-vscode' extension because it has no release version

image

JBang installed via scoop fails to run

Hi,

I have installed JBang using scoop and the JBang command works. However, VScode does not seem to detect it. The error message says that the specified file is not found.

image

"jbang.home": "C:\\Users\\user\\scoop\\apps\\jbang\\current"

get-command jbang

CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
ExternalScript  jbang.ps1                                                     C:\Users\user\scoop\apps\jbang\current\bin\jbang.ps1

JBang-vscode extension version: v0.9.0

 code --version
1.84.2
jbang --version
0.113.0

BR 😄 ,

add find dep to unresolved classes?

feat: code action to search for missing JBang dependencies #77 is awesome

wold be extra awesome if could do similar quickfix when class cannot resolve.

It would be less precise but I would be great to just type class name and the plugin would take a best guess or offer list of possible dependencies that has such class.

Gitpod.io can't run jbang on ipad

When on ipad run jbang action is visible near main menu but cannot click run (I think that is a general gitpod.io issue on ipad); but context menu pops up with run and debug java but no run/debug jbang is shown. Should it not be?

Further more running via cmd+p gives this error:

"Command 'JBang: Run JBang' resulted in an error (Cannot read properties of undefined (reading 'fsPath'))"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.