diff --git a/crates/mist-api/src/builder.mist b/crates/mist-api/src/builder.mist index 3f3295a..1feb6df 100644 --- a/crates/mist-api/src/builder.mist +++ b/crates/mist-api/src/builder.mist @@ -31,8 +31,6 @@ pub fn build(mut args Vec, root PathBuf) bool { args.remove(0); args.insert(1, "--message-format=json".to_string()); - let is_root = root == env::current_dir().expect("Failed getting env"); - let mut command = Command::new("cargo") .args(args) .stdout(Stdio::piped()) @@ -56,15 +54,6 @@ pub fn build(mut args Vec, root PathBuf) bool { if span.is_primary { let rust_path = root.join(&span.file_name); - let mist_file = span - .file_name - .replacen(&mist_src, "src", 1) - .trim_end_matches(".rs") - .to_string() - + ".mist"; - - let mist_path = root.join(&mist_file); - let mapping_path = rust_path.with_extension("map.json"); if !fs::exists(&mapping_path).expect("Unable to check if map file exists") { @@ -75,11 +64,13 @@ pub fn build(mut args Vec, root PathBuf) bool { let map = mapping.entry(mapping_path.clone()).or_insert_with(fn() { let map_str = fs::read_to_string(mapping_path).expect("Failed to read map file"); - serde_json::from_str(&map_str).expect("Failed to parse map file") + serde_json::from_str(&map_str).expect("Failed to parse map file") }); + let mist_file = map.mist_path.strip_prefix(&root); + let [_, rev_mapper::MistMap[line, column]] = - rev_mapper::find_mapping(&map, &rev_mapper::RustMap(span.line_end, span.column_start)) + map.find(&rev_mapper::RustMap(span.line_end, span.column_start)) .expect("Unable to find mapping"); let mist_msg = MistDiagnosticMessage { @@ -88,13 +79,12 @@ pub fn build(mut args Vec, root PathBuf) bool { msg.message.message, span.label.clone().unwrap_or_default() ), - file_name: if is_root { - (); // TODO: fix this - mist_file + file_name: if let Ok(mist_file) = mist_file { + mist_file.to_string_lossy().to_string() } else { - mist_path.to_string_lossy().to_string() + map.mist_path.to_string_lossy().to_string() }, - file_path: mist_path, + file_path: map.mist_path.clone(), line: line, column: column }; diff --git a/crates/mist-api/src/transpiler.mist b/crates/mist-api/src/transpiler.mist index 2c32c94..42a8302 100644 --- a/crates/mist-api/src/transpiler.mist +++ b/crates/mist-api/src/transpiler.mist @@ -8,7 +8,6 @@ use std::time; use std::env; use mist_parser::error; -use mist_parser::rev_mapper; use crate::modules; use mist_codegen::GetRust; @@ -201,7 +200,7 @@ fn transpile_file(path *PathBuf, source *str, mut output_file PathBuf, mod_decl } } - let mut gc = mist_codegen::RustCodegen::new(); + let mut gc = mist_codegen::RustCodegen::new(path.clone()); let parsed = match mist_parser::parse(source) { Ok[ast] => ast; @@ -239,7 +238,7 @@ fn transpile_file(path *PathBuf, source *str, mut output_file PathBuf, mod_decl let res = fs::write(&output_file, format!("{mod_decl}{output}")); - rev_mapper::shift_rust_mappings(&mut gc.mapping, mod_decl.lines().count() as isize, 0); + gc.mapping.shift_rust(mod_decl.lines().count() as isize, 0); let output_file_map = output_file.with_extension("map.json");