Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add jbang #118

Closed
wants to merge 3 commits into from
Closed

add jbang #118

wants to merge 3 commits into from

Conversation

maxandersen
Copy link

This adds a jbang language but it would make more sense this was used by java
to enable use of dependencies.

i.e. you can run this java code with this:

///usr/bin/env jbang "$0" "$@" ; exit $?
//DEPS com.github.lalyos:jfiglet:0.0.8

import com.github.lalyos.jfiglet.FigletFont;

class hello {

    public static void main(String... args) throws Exception {
        System.out.println(FigletFont.convertOneLine(
               "Hello " + ((args.length>0)?args[0]:"jbang")));  ;;
    }
}

Notice the //DEPS line that is picked up by jbang to build and run with that dependency.

I did try add install steps under manual but for some reason java is not available
within that making it difficult to install jbang using jbang itself.

Is there a way to have java available in the manual section ?

Otherwise I'll need to add more manual steps to install jbang.

@maxandersen
Copy link
Author

mentioned in #117

Copy link
Member

@raxod502 raxod502 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution! Added some comments below. In response to your question about making sure Java is available during installation, that's what the prepare block is for. There are some examples in the installation tutorial, e.g. https://github.com/raxod502/riju/blob/master/doc/tutorial/install.md#compile-from-source.

I'd like to keep JBang separate from Java since I feel it is really a different language, even if it's very similar. But no objection to having them both in parallel.

langs/jbang.yaml Outdated Show resolved Hide resolved
langs/jbang.yaml Outdated Show resolved Hide resolved
langs/jbang.yaml Outdated Show resolved Hide resolved
trace:
server: "off"
code: "TODO"
item: "TODO"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind including the changes from #121 to the language server configuration?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure.

Btw. Do you know of a way to have the lsp run on the directory output of a command ? Jbang can set up ide workspace that has dependencies etc. Configured.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, you'll probably want to do something like for Q# where you also install the language at build time, and use its tooling to generate a project skeleton:

https://github.com/raxod502/riju/blob/85afa783e5532206f66df5120ad0bac6e47eec70/langs/qsharp.yaml#L25-L37

Which can then be populated into the runtime directory at container start:

https://github.com/raxod502/riju/blob/85afa783e5532206f66df5120ad0bac6e47eec70/langs/qsharp.yaml#L43-L46

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's more the other way.

Need to run 'jbang edit --no-open main.java' which scans the java code and sets up the right ide metadata. Can also run with --live to have it continuously update it if java dependencies changes.

Note it's just relevant for the Lsp so might just be enough do it when user toggle it on/off.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Well, if you need to have the user code before starting LSP, then you probably want to put this into the lsp.start command, as you suggested.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These seem like they should be part of the same language, instead of being separate. We generally don't have multiple different variants for a language.

jshell is a variance of java used for jshell.

jbang is just wrapping it here.

Can't have it in one language as it requires a different named file (.jsh vs .java).

Max Rydahl Andersen and others added 2 commits September 26, 2021 22:11
Co-authored-by: Radon Rosborough <radon.neon@gmail.com>
@maxandersen
Copy link
Author

I've updated jbang w/java and also added a JShell variant which adds repl support..

btw. how does one come back to the repl after having pressed run ?

@@ -0,0 +1,138 @@
id: "jbang"
name: "Java w/JBang"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw. not too hapy about this name but just putting "JBang" means java users wont find it.

@raxod502
Copy link
Member

raxod502 commented Oct 3, 2021

btw. how does one come back to the repl after having pressed run ?

The contract is described here: https://github.com/raxod502/riju/blob/1c8b0e14529d8b37eead3fd939612b9d518f1985/doc/tutorial/run.md#languages-with-repls

In other words, a repl should always be started automatically after the code is run, for languages that have repls.

also added a JShell variant which adds repl support

These seem like they should be part of the same language, instead of being separate. We generally don't have multiple different variants for a language.

just putting "JBang" means java users wont find it

I think we may have to live with that for now; I'd like to keep the language names canonical for now. A better way to make JBang discoverable for users looking for Java would be to add an explicit language search option which can index on more metadata than just the language name (see #125).

manual: |
install -d "${pkg}/usr/local/bin"
curl -Ls https://sh.jbang.dev | bash -s - app setup
cp ~/.jbang/bin/* "${pkg}/usr/local/bin/"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
cp ~/.jbang/bin/* "${pkg}/usr/local/bin/"
cp "$HOME/.jbang/bin"/* "${pkg}/usr/local/bin/"

Copy link
Member

@raxod502 raxod502 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay here.

It sounds like JShell is actually an official part of Java, which I didn't realize at first. Because of that, I think it would make more sense to include it directly into Riju's primary Java support. Ideally, we would have JShell support in both Java and JBang.

Can't have it in one language as it requires a different named file

JShell should be able to interoperate with traditional Java code (.java), right? It's just that the code has to be standard Java, rather than JShell input. You should be able to import and run Java code from files in your working directory, which lines up with how repl/run integration works for most languages on Riju.

So if we did things this way, langs/java.yaml would grow new repl and scope options, and we'd also have most of the same options in langs/jbang.yaml.

@raxod502 raxod502 closed this Jan 29, 2022
@raxod502
Copy link
Member

This thread is being closed automatically by Tidier because it is labeled with "waiting on response" and has not seen any activity for 90 days. But don't worry—if you have any information that might advance the discussion, leave a comment and I will be happy to reopen the thread :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants