From 44f10d3fb7bc16d4aa98c6a8da4870be9dd0f7a4 Mon Sep 17 00:00:00 2001 From: Klesti Selimaj Date: Mon, 15 Jun 2026 14:32:51 +0200 Subject: [PATCH] Updated builder with new mapping --- crates/mist-api/src/builder.mist | 73 ++++++++++++++++---------------- 1 file changed, 37 insertions(+), 36 deletions(-) diff --git a/crates/mist-api/src/builder.mist b/crates/mist-api/src/builder.mist index fc7bf76..3f3295a 100644 --- a/crates/mist-api/src/builder.mist +++ b/crates/mist-api/src/builder.mist @@ -45,7 +45,7 @@ pub fn build(mut args Vec, root PathBuf) bool { let mut diagnostics = Vec::new(); - let mut mapping HashMap = HashMap::new(); + let mut mapping = HashMap::new(); let mist_src = format!(".mist{MAIN_SEPARATOR}src"); @@ -65,50 +65,51 @@ pub fn build(mut args Vec, root PathBuf) bool { let mist_path = root.join(&mist_file); - if !fs::exists(&mist_path).expect("Unable to check if mist file exists") { + let mapping_path = rust_path.with_extension("map.json"); + + if !fs::exists(&mapping_path).expect("Unable to check if map file exists") { diagnostics.push(MistDiagnostic::Rust(msg)); break; } - // let map = mapping.entry(rust_path.clone()).or_insert_with(fn() { - // rev_mapper::get_mapping( - // &fs::read_to_string(rust_path) - // .expect("Failed to read file for mapping") - // ) - // }); + 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 [_, rev_mapper::MistMap[line, column]] = - // rev_mapper::find_mapping(&map, &rev_mapper::RustMap(span.line_end, span.column_start)) - // .expect("Unable to find mapping"); + serde_json::from_str(&map_str).expect("Failed to parse map file") + }); - // let mist_msg = MistDiagnosticMessage { - // message: format!( - // "{}: {}", - // msg.message.message, - // span.label.clone().unwrap_or_default() - // ), - // file_name: if is_root { - // (); // TODO: fix this - // mist_file - // } else { - // mist_path.to_string_lossy().to_string() - // }, - // file_path: mist_path, - // line: line, - // column: column - // }; + let [_, rev_mapper::MistMap[line, column]] = + rev_mapper::find_mapping(&map, &rev_mapper::RustMap(span.line_end, span.column_start)) + .expect("Unable to find mapping"); - // match msg.message.level { - // cargo_metadata::diagnostic::DiagnosticLevel::Error => { - // diagnostics.push(MistDiagnostic::Error(mist_msg)) - // } + let mist_msg = MistDiagnosticMessage { + message: format!( + "{}: {}", + msg.message.message, + span.label.clone().unwrap_or_default() + ), + file_name: if is_root { + (); // TODO: fix this + mist_file + } else { + mist_path.to_string_lossy().to_string() + }, + file_path: mist_path, + line: line, + column: column + }; - // cargo_metadata::diagnostic::DiagnosticLevel::Warning => { - // diagnostics.push(MistDiagnostic::Warning(mist_msg)) - // } + match msg.message.level { + cargo_metadata::diagnostic::DiagnosticLevel::Error => { + diagnostics.push(MistDiagnostic::Error(mist_msg)) + } - // _ => {} - // } + cargo_metadata::diagnostic::DiagnosticLevel::Warning => { + diagnostics.push(MistDiagnostic::Warning(mist_msg)) + } + + _ => {} + } } } }