Parinfer WebAssembly


#1

Jason shared on slack on May 2:

So, I have parinfer-rust building and running with WebAssembly. The wasm tools for Rust aren’t quite sorted out, so it was rough. But not sure what to do next.

From https://github.com/eraserhd/parinfer-rust/commit/036beebb33fd9f64dc306defd6b739e98bb127b2#diff-a9c08c1a0090ce558d26bd079fc86472, it looks like there’s some serialization of the options, and not sure what format it gets back:

    Rust.cparinfer.then((cparinfer) => {
    let request = JSON.stringify({
      mode: "indent",
      text: "(def x",
      options: {
        "cursorX": 3,
        "cursorLine": 0
      }
    });
    let response = cparinfer.run_parinfer(request);
    console.log(response);
  });

Next steps:

  1. run against our JS test suite
  2. run against our JS perf script
  3. see how we can release this on npm
  4. see if we should release this in place of the original parinfer.js

#2

A. The interface is different, owing to the fact that Rust can’t really work with JavaScript native objects. To compensate, the JSON is passed in as a string and deserialized into Rust objects. I think there’s a way to wrap it to preserve the interface, though. I’m adding these tasks to my personal task list:

  • Wrap JavaScript interface to preserve parinfer.js semantics.
  • Make wrapper hide the fact that Rust.parinfer is a promise.

B. Cleanup. Right now, the repo contains two Rust crates and a Vim plugin. I think the two Rust crates can be merged and the Vim plugin moved elsewhere. There is a tool for publishing Rust code to npm. My task list:

  • Merge Rust crates
  • Move Vim plugin elsewhere (includes publishing Rust crate)
  • Publish to npm

C. Differences. Right now, returnParens is not verified, and forceBalance definitely does not work right.

  • Fix forceBalance

D. Tests. I copied the JSON generated from the markdown files into the repo and all tests currently pass. (returnParens and forceBalance are not tested). There’s a nice markdown-parsing library that I think can be used to run the markdown tests directly. We should do this.

  • Run Markdown tests directly.

#3

Make wrapper hide the fact that Rust.parinfer is a promise.

not sure you need to do this. if it’s doing something asynchronous, then it’s likely neither possible nor desirable.

There’s a nice markdown-parsing library that I think can be used to run the markdown tests directly. We should do this.

probably not worth it! the code for doing all the markdown parsing is not trivial, and it doesn’t need to be portable anyway. all the metadata needed from those markdown files is dumped in the JSON files for portability.

Publish to npm

Let me know how this goes, might be best to just publish to the parinfer package name when ready. :+1:

Thanks a lot!