Skip to content

Commit a5dabb1

Browse files
authored
🐛 - copy namespace compiler assets and asts to /lib/bs to fix editor support (#121)
1 parent f864793 commit a5dabb1

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

src/build/parse.rs

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,29 @@ pub fn generate_asts(
203203
namespaces::compile_mlmap(package, module_name, &build_state.bsc_path);
204204
let mlmap_hash_after = helpers::compute_file_hash(&compile_path);
205205

206+
let suffix = package
207+
.namespace
208+
.to_suffix()
209+
.expect("namespace should be set for mlmap module");
210+
// copy the mlmap to the bs build path for editor tooling
211+
let base_build_path = package.get_build_path() + "/" + &suffix;
212+
let base_bs_build_path = package.get_bs_build_path() + "/" + &suffix;
213+
let _ = std::fs::copy(
214+
base_build_path.to_string() + ".cmi",
215+
base_bs_build_path.to_string() + ".cmi",
216+
);
217+
let _ = std::fs::copy(
218+
base_build_path.to_string() + ".cmt",
219+
base_bs_build_path.to_string() + ".cmt",
220+
);
221+
let _ = std::fs::copy(
222+
base_build_path.to_string() + ".cmj",
223+
base_bs_build_path.to_string() + ".cmj",
224+
);
225+
let _ = std::fs::copy(
226+
base_build_path.to_string() + ".mlmap",
227+
base_bs_build_path.to_string() + ".mlmap",
228+
);
206229
match (mlmap_hash, mlmap_hash_after) {
207230
(Some(digest), Some(digest_after)) => !digest.eq(&digest_after),
208231
_ => true,
@@ -299,7 +322,7 @@ fn generate_ast(
299322
);
300323

301324
/* Create .ast */
302-
if let Some(res_to_ast) = Some(
325+
let result = if let Some(res_to_ast) = Some(
303326
Command::new(bsc_path)
304327
.current_dir(&build_path_abs)
305328
.args(parser_args)
@@ -322,7 +345,20 @@ fn generate_ast(
322345
"Could not find canonicalize_string_path for file {} in package {}",
323346
filename, package.name
324347
))
348+
};
349+
match &result {
350+
Ok((ast_path, _)) => {
351+
let dir = std::path::Path::new(filename).parent().unwrap();
352+
let _ = std::fs::copy(
353+
build_path_abs.to_string() + "/" + ast_path,
354+
std::path::Path::new(&package.get_bs_build_path())
355+
.join(dir)
356+
.join(ast_path),
357+
);
358+
}
359+
Err(_) => (),
325360
}
361+
result
326362
}
327363

328364
fn path_to_ast_extension(path: &Path) -> &str {

0 commit comments

Comments
 (0)