Create an interface file for this implementation

Is possible to create an interface file for .res files the way it was done with .re files?

For example in reason-language-server?

Thank you.


It’s probably bsc -i, but I don’t understand why there are non-ascii characters in the interface.

1 Like

You need to have a compiled *.cmi of the file you want to generate the interface for.
It resides in lib/bs/...

Also, the output of -i yields .mli syntax, and as far as I know there is no direct step (yet) to do this with bsc in one go. Thus, I made a simple bash script:

set -e

bsc -i  lib/bs/src/$1.cmi > src/$1.mli
bsc -format src/$1.mli > src/$1.resi
rm src/$1.mli

You can put that easily in your package.json scripts and run it with npm run intf YourFile.res or something.

1 Like

Doesnt quite work off the .cmi in lib/bs/src/$1.cmi.
bsc -i src/$1.res > src/$1.mli is producing the .mli at any rate.
Seem like we would have to go from mli to re first maybe.

bsc -i src/$1.res > src/$1.mli
refmt --parse ml --print re "$1" >"${1%.mli}.rei"
rm src/$1.mli

Which doesnt work either but will have to get back to it. Thanks for the assist.

That’s weird. For me it does not work with a .res which opens another File which it says cannot be found.
This info is only available at the CMI stage I guess, and that works always for me (with ReScript 9.0.1 at least).
Also a refmt step should not be necessary.

1 Like

I had a prototype of supporting this

rescript inspect path/to/your/source

It will automatically build the specific target and generate readable output, any suggestion to the CLI?

1 Like

Yeah, I would not call it inspect, maybe just rescript interface.
rescript create-interface or the like seems too long, though.

1 Like

interface is too specific, I am thinking to provide more information in the future

1 Like

inspect is an overloaded term, especially in JS where it currently most commonly refers to running the node debugger. What about describe?

1 Like

thanks for the suggestion. Let’s call it dump. We support cmi, and may support cmj and ast in the future