Implemented updated mapping data structure

This commit is contained in:
2026-06-15 15:04:10 +02:00
parent 663dab52ec
commit 12cf4e94d8
2 changed files with 10 additions and 21 deletions
+8 -18
View File
@@ -31,8 +31,6 @@ pub fn build(mut args Vec<String>, root PathBuf) bool {
args.remove(0); args.remove(0);
args.insert(1, "--message-format=json".to_string()); 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") let mut command = Command::new("cargo")
.args(args) .args(args)
.stdout(Stdio::piped()) .stdout(Stdio::piped())
@@ -56,15 +54,6 @@ pub fn build(mut args Vec<String>, root PathBuf) bool {
if span.is_primary { if span.is_primary {
let rust_path = root.join(&span.file_name); 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"); let mapping_path = rust_path.with_extension("map.json");
if !fs::exists(&mapping_path).expect("Unable to check if map file exists") { if !fs::exists(&mapping_path).expect("Unable to check if map file exists") {
@@ -75,11 +64,13 @@ pub fn build(mut args Vec<String>, root PathBuf) bool {
let map = mapping.entry(mapping_path.clone()).or_insert_with(fn() { 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"); 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<rev_mapper::Mapping>(&map_str).expect("Failed to parse map file")
}); });
let mist_file = map.mist_path.strip_prefix(&root);
let [_, rev_mapper::MistMap[line, column]] = 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"); .expect("Unable to find mapping");
let mist_msg = MistDiagnosticMessage { let mist_msg = MistDiagnosticMessage {
@@ -88,13 +79,12 @@ pub fn build(mut args Vec<String>, root PathBuf) bool {
msg.message.message, msg.message.message,
span.label.clone().unwrap_or_default() span.label.clone().unwrap_or_default()
), ),
file_name: if is_root { file_name: if let Ok(mist_file) = mist_file {
(); // TODO: fix this mist_file.to_string_lossy().to_string()
mist_file
} else { } 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, line: line,
column: column column: column
}; };
+2 -3
View File
@@ -8,7 +8,6 @@ use std::time;
use std::env; use std::env;
use mist_parser::error; use mist_parser::error;
use mist_parser::rev_mapper;
use crate::modules; use crate::modules;
use mist_codegen::GetRust; 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) { let parsed = match mist_parser::parse(source) {
Ok[ast] => ast; 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}")); 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"); let output_file_map = output_file.with_extension("map.json");