ScalablyTyped/Converter

[Feature Request] Support the JVM (for scalajs interop)

robmwalsh opened this issue · 1 comments

I've been working on a language server implementation. The corresponding vscode extension is written in scala.js using ScalablyTyped which has for the most part ( #463 aside) is working brilliantly.

The server is written in scala running on the JVM which is very sad because while ScalablyTyped has generated facades for all of these types which are now flying over the wire towards my server (LSP uses JSONRPC 2.0 for comms), I'm now needing to write case classes which essentially correspond 1:1 to the ScalablyTyped facades which are sitting unused just out of reach. I'm also doing nasty hacks to make json decoders/encoders behave how I need them to.

I'm wondering if it's even in the realms of possibility? It strikes me as something that could be fairly easy or near impossible depending how scalably typed works behind the scenes.

Yeah, this would absolutely be possible. Some work, but certainly possible.

Basically we could use the flavour subsystem, which is just a function from AST to AST which enables you to do arbitrary rewrites and generate arbitrary scala code based on the imported type descriptions. The Scala AST itself is powerful enough to express all the most common syntax, and could be extended if needed. An example transformation is GenCompanions which is responsible for generating companion objects with apply methods for types we can instantiate.

For an example of what a more powerful transformation can do, here is a ActionButton react component syntax thing, based on libUtilActionButtonMod

I guess some problems will show up:

  • we'll need json codecs. I guess there will be some type juggling to get it all to line up
  • json codecs may be especially hard for untagged union types

There is no infrastructure to generate both a scalajs jar and a scala jar. Could save some time here by copy/pasting source code I guess.