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

Enhancement: Make extension work independently on jpm / spork being installed #13

Open
fuxoft opened this issue Feb 25, 2023 · 2 comments

Comments

@fuxoft
Copy link

fuxoft commented Feb 25, 2023

Janet is a small language that can be conveniently installed and used just by copying a single binary, with no other dependencies or libraries.

However, the formatting in the VS Code extension only works if spork is installed. To install spork, jpm has to be installed.

It's trivial to modify the extension so that it runs independently on jpm or spork, requiring just the janet binary. I think this would make it easier to use the extension for people who are e.g. just trying Janet out and do not (yet) even know what jpm or spork is.

@fuxoft fuxoft changed the title Enhancement: Make extension weork independently on jpm / spork being installed Enhancement: Make extension work independently on jpm / spork being installed Feb 25, 2023
@sogaiu
Copy link

sogaiu commented Feb 25, 2023

I started thinking about how this might be done.

Two possibilities (may be there are others) about how the extension might access bits necessary for spork/fmt functionality to work are:

  1. Include a bundled spork/fmt.janet file
  2. Include the content of the file as a string

The latter might look rather messy if the formatting is accomplished via the current means of sending text to a janet repl.

Perhaps the approach of a bundled file would be preferrable.

It's been a while since I've done VSCode extension tinkering, but it looks like it is (or at least was) possible to get at a file which the extension bundles. I think the following is an example of a function that can get the absolute path to a relevant file:

    /**
     * Returns the absolute path to a file located in our misc folder.
     *
     * @param file The base file name.
     * @param context The context of this extension to get its path regardless where it is installed.
     * @param webview When given format the path for use in this webview.
     *
     * @returns The computed path.
     */
    public static getMiscPath(file: string, context: ExtensionContext, webview?: Webview): string {
        if (webview) {
            const uri = Uri.file(context.asAbsolutePath(path.join("misc", file)));

            return webview.asWebviewUri(uri).toString();
        }

        return context.asAbsolutePath(path.join("misc", file));
    }

via: https://github.com/mike-lischke/vscode-antlr4/blob/c25c25c1bd56a92ffafc24c26caee053db077941/src/frontend/FrontendUtils.ts#L22-L39

So with the absolute path in hand presumably we can modify this bit:

sendSource(terminal, "(import spork/fmt) (fmt/format-file \""+

to import our bundled file.

If that kind of approach works, may be it will also be easier (as compared with storing the functionality in a string) to update the included spork/fmt.janet file from time to time. One example of why one might want to update the content is that sometimes things are added to janet that one might want to highlight differently.

@sogaiu
Copy link

sogaiu commented Feb 25, 2023

Ok, here is a draft.

Have only tried on a Linux box.

There may be better ways, but at least it seems doable.

The main changes code-wise are here. I tried to arrange for things in a way such that nothing got introduced in one's repl environment that would interfere with other things going on (not sure if I was successful).

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

No branches or pull requests

2 participants