use std::collections::BTreeMap;
use std::sync::Arc;
use crate::ir::FileIr;
use crate::resolution::rust::identity::position;
#[derive(Debug)]
pub(super) struct ModuleDeclaration {
pub(super) name: Arc<str>,
pub(super) declared_paths: Box<[Arc<str>]>,
pub(super) inline_scope: Option<u32>,
pub(super) index: u32,
}
pub(super) fn declarations_by_scope(ir: &FileIr) -> BTreeMap<u32, Arc<[ModuleDeclaration]>> {
let mut scopes: BTreeMap<u32, Vec<ModuleDeclaration>> = BTreeMap::new();
for (index, site) in ir.module_declarations.iter().enumerate() {
scopes
.entry(position(site.scope))
.or_default()
.push(ModuleDeclaration {
name: Arc::from(&*site.name),
declared_paths: site
.declared_paths
.iter()
.map(|path| Arc::from(&**path))
.collect(),
inline_scope: site.inline_scope.map(position),
index: position(index),
});
}
scopes
.into_iter()
.map(|(scope, declarations)| (scope, Arc::from(declarations)))
.collect()
}