Code Monkey home page Code Monkey logo

Comments (2)

sogaiu avatar sogaiu commented on July 18, 2024

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.

from vscode-janet.

sogaiu avatar sogaiu commented on July 18, 2024

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).

from vscode-janet.

Related Issues (7)

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.