Fix module system in analyzer

This commit is contained in:
2026-06-30 21:04:12 +02:00
parent a5dad690bf
commit d0a72b49f0
+17 -6
View File
@@ -10,6 +10,7 @@ use heck::ToSnakeCase;
use mist_api::transpiler::MistConfig; use mist_api::transpiler::MistConfig;
use mist_parser::MistFmtConfig; use mist_parser::MistFmtConfig;
use mist_parser::error::ParseError; use mist_parser::error::ParseError;
use mist_parser::parse_module;
use mist_parser::rev_mapper::{Mapping, MistMap, RustMap}; use mist_parser::rev_mapper::{Mapping, MistMap, RustMap};
use ropey::Rope; use ropey::Rope;
use serde::Deserialize; use serde::Deserialize;
@@ -2006,20 +2007,30 @@ fn compute_mod_decls(
let mut sorted = files.clone(); let mut sorted = files.clone();
sorted.sort(); sorted.sort();
for file in &sorted { for file in &sorted {
let stem = match file.file_stem().and_then(|s| s.to_str()) {
Some(s) => s,
None => continue,
};
// Skip the root package entry file (e.g. main.mist) // Skip the root package entry file (e.g. main.mist)
if *file == package_path { if *file == package_path {
continue; continue;
} }
// Skip any subdirectory package.mist — it's the directory's own // Skip any subdirectory package.mist — it's the directory's own
// entry file, not a sibling submodule. // entry file, not a sibling submodule.
if stem == "package" { if file.file_name().and_then(|s| s.to_str()) == Some("package.mist") {
continue; continue;
} }
mod_decl.push_str(&format!("pub mod {};\n", stem)); // Use the module declaration from the file if present,
// otherwise fall back to file stem.
let mod_name = documents
.get(file)
.and_then(|rope| {
let source = rope.to_string();
parse_module(&source).ok().flatten().map(|(_, name)| name.0)
})
.or_else(|| {
file.file_stem()
.and_then(|s| s.to_str().map(String::from))
});
if let Some(name) = mod_name {
mod_decl.push_str(&format!("pub mod {};\n", name));
}
} }
if dir == src_root { if dir == src_root {