Skip to content

Commit fd7930f

Browse files
authored
Fix lsp crashes (#155)
1 parent 30ba3f3 commit fd7930f

File tree

4 files changed

+77
-7
lines changed

4 files changed

+77
-7
lines changed

.github/workflows/build.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,10 @@ jobs:
1616
runs-on: macos-latest
1717
env:
1818
RUST_BACKTRACE: "1"
19-
SCCACHE_GHA_ENABLED: "true"
20-
RUSTC_WRAPPER: "sccache"
2119
steps:
2220
- uses: actions/checkout@v4
2321
with:
2422
ref: ${{ github.ref }}
25-
- name: setup sccache
26-
uses: mozilla-actions/[email protected]
27-
with:
28-
version: "v0.7.7"
2923
- uses: dtolnay/rust-toolchain@master
3024
with:
3125
toolchain: stable

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+
}

tests/suffix.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ fi
2727
# Count files with new extension
2828
file_count=$(find . -name *.res.js | wc -l)
2929

30-
if [ "$file_count" -eq 10 ];
30+
if [ "$file_count" -eq 20 ];
3131
then
3232
success "Found files with correct suffix"
3333
else

0 commit comments

Comments
 (0)