fix Analyzer file path #118
This commit is contained in:
@@ -2,7 +2,7 @@ use std::path::{Path, PathBuf};
|
|||||||
|
|
||||||
use mist_codegen::RustCodegen;
|
use mist_codegen::RustCodegen;
|
||||||
use mist_parser::rev_mapper::Mapping;
|
use mist_parser::rev_mapper::Mapping;
|
||||||
use mist_parser::{MistFmtConfig, parse};
|
use mist_parser::{MistFmtConfig, parse, parse_module};
|
||||||
|
|
||||||
pub struct TranspiledFile {
|
pub struct TranspiledFile {
|
||||||
pub mist_path: PathBuf,
|
pub mist_path: PathBuf,
|
||||||
@@ -30,6 +30,21 @@ pub fn transpile_mist<'a>(
|
|||||||
rust_path.set_file_name("mod.rs");
|
rust_path.set_file_name("mod.rs");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Prioritize the module declaration from the source over the file stem.
|
||||||
|
// Every transpile re-parses so we always pick up the current declaration.
|
||||||
|
if let Ok(Some((_, ref name))) = parse_module(source) {
|
||||||
|
if rust_path.file_name().map(|v| v.to_str()).unwrap_or_default() != Some("mod.rs") {
|
||||||
|
if let Some(ext) = rust_path.extension().map(|e| e.to_owned()) {
|
||||||
|
let mut new_name = std::ffi::OsString::from(&name.0);
|
||||||
|
new_name.push(".");
|
||||||
|
new_name.push(ext);
|
||||||
|
rust_path.set_file_name(new_name);
|
||||||
|
} else {
|
||||||
|
rust_path.set_file_name(&name.0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let parsed = parse(source).map_err(TranspileError::Parse)?;
|
let parsed = parse(source).map_err(TranspileError::Parse)?;
|
||||||
|
|
||||||
for item in &parsed.items {
|
for item in &parsed.items {
|
||||||
@@ -66,6 +81,21 @@ pub fn transpile_mist_no_sem(
|
|||||||
rust_path.set_file_name("mod.rs");
|
rust_path.set_file_name("mod.rs");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Prioritize the module declaration from the source over the file stem.
|
||||||
|
// Every transpile re-parses so we always pick up the current declaration.
|
||||||
|
if let Ok(Some((_, ref name))) = parse_module(source) {
|
||||||
|
if rust_path.file_name().map(|v| v.to_str()).unwrap_or_default() != Some("mod.rs") {
|
||||||
|
if let Some(ext) = rust_path.extension().map(|e| e.to_owned()) {
|
||||||
|
let mut new_name = std::ffi::OsString::from(&name.0);
|
||||||
|
new_name.push(".");
|
||||||
|
new_name.push(ext);
|
||||||
|
rust_path.set_file_name(new_name);
|
||||||
|
} else {
|
||||||
|
rust_path.set_file_name(&name.0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let parsed = parse(source).map_err(|e| format!("parse error: {e:?}"))?;
|
let parsed = parse(source).map_err(|e| format!("parse error: {e:?}"))?;
|
||||||
|
|
||||||
let mut codegen = RustCodegen::new(mist_path.to_path_buf());
|
let mut codegen = RustCodegen::new(mist_path.to_path_buf());
|
||||||
|
|||||||
Reference in New Issue
Block a user