Hey,
I want to read the generated .cmt file from a rescript project and do some analysis of the types. I found an example:
let get_initial_env = (file_name: string): Env.t => {
let cmt = readCmt(file_name);
switch (cmt) {
| {Cmt_format.cmt_initial_env: env, cmt_loadpath} =>
Config.load_path := cmt_loadpath;
/* We call [env_of_only_summary] else the environment is empty
(contains only the summary) and cannot be searched.
*/
try(Envaux.env_of_only_summary(env)) {
| Envaux.Error(error) =>
Envaux.report_error(Format.str_formatter, error);
failwith(Format.flush_str_formatter());
};
| _ => failwith("Cannot extract cmt data.")
};
};
But it doesn’t work for code that uses/imports other modules. I always get something like:
FAILED: src/html/Html.cmj
Fatal error: exception Env.Error(_)
So, my question is, is this actually supposed to work, or should I somehow use the env module from https://github.com/rescript-lang/ocaml/tree/24bd8f7f4ee641ea78c536ef557e25396cb4d537
It looks like it’s trying to load the cmj files and fails
I also had a quick look at reanalyze, but I could not make sense of it. They somehow define an Env module here: https://github.com/rescript-association/reanalyze/blob/6335ce4399ecb305e653561d2d01912fd6c8f917/src/Il.ml ,but manually add all the stuff.
So to sum it up, I want to load a cmt file + the environment so that I can traverse the typedtree and look up types with Env.find_type