Skip to content

Commit 5ef6a02

Browse files
committed
fix lsp crashes
1 parent 30ba3f3 commit 5ef6a02

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed

src/build/compile.rs

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,75 @@ fn compile_file(
597597
);
598598
}
599599

600+
match &module.source_type {
601+
SourceType::SourceFile(SourceFile {
602+
interface: Some(Interface { path, .. }),
603+
..
604+
}) => {
605+
// we need to copy the source file to the build directory.
606+
// editor tools expects the source file in lib/bs for finding the current package
607+
// and in lib/ocaml when referencing modules in other packages
608+
let _ = std::fs::copy(
609+
std::path::Path::new(&package.path).join(path),
610+
std::path::Path::new(&package.get_build_path()).join(path),
611+
)
612+
.expect("copying source file failed");
613+
614+
let _ = std::fs::copy(
615+
std::path::Path::new(&package.path).join(path),
616+
std::path::Path::new(&package.get_ocaml_build_path())
617+
.join(std::path::Path::new(path).file_name().unwrap()),
618+
)
619+
.expect("copying source file failed");
620+
}
621+
_ => (),
622+
}
623+
match &module.source_type {
624+
SourceType::SourceFile(SourceFile {
625+
implementation: Implementation { path, .. },
626+
..
627+
}) => {
628+
// we need to copy the source file to the build directory.
629+
// editor tools expects the source file in lib/bs for finding the current package
630+
// and in lib/ocaml when referencing modules in other packages
631+
let _ = std::fs::copy(
632+
std::path::Path::new(&package.path).join(path),
633+
std::path::Path::new(&package.get_build_path()).join(path),
634+
)
635+
.expect("copying source file failed");
636+
637+
let _ = std::fs::copy(
638+
std::path::Path::new(&package.path).join(path),
639+
std::path::Path::new(&package.get_ocaml_build_path())
640+
.join(std::path::Path::new(path).file_name().unwrap()),
641+
)
642+
.expect("copying source file failed");
643+
}
644+
_ => (),
645+
}
646+
647+
// copy js file
648+
match &module.source_type {
649+
SourceType::SourceFile(SourceFile {
650+
implementation: Implementation { path, .. },
651+
..
652+
}) => {
653+
let source = helpers::get_source_file_from_rescript_file(
654+
&std::path::Path::new(&package.path).join(path),
655+
&root_package.config.get_suffix(),
656+
);
657+
let destination = helpers::get_source_file_from_rescript_file(
658+
&std::path::Path::new(&package.get_build_path()).join(path),
659+
&root_package.config.get_suffix(),
660+
);
661+
662+
if source.exists() {
663+
let _ = std::fs::copy(&source, &destination).expect("copying source file failed");
664+
}
665+
}
666+
_ => (),
667+
}
668+
600669
if helpers::contains_ascii_characters(&err) {
601670
if package.is_pinned_dep || package.is_local_dep {
602671
// supress warnings of external deps

src/helpers.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,3 +357,10 @@ pub fn read_file(path: &Path) -> Result<String, std::io::Error> {
357357
file.read_to_string(&mut contents)?;
358358
Ok(contents)
359359
}
360+
361+
pub fn get_source_file_from_rescript_file(path: &Path, suffix: &str) -> PathBuf {
362+
path.with_extension(
363+
// suffix.to_string includes the ., so we need to remove it
364+
&suffix.to_string()[1..],
365+
)
366+
}

0 commit comments

Comments
 (0)