Skip to content

Commit

Permalink
Order modules in docs sidebar based on exposes
Browse files Browse the repository at this point in the history
  • Loading branch information
rtfeldman committed Nov 19, 2023
1 parent 9a12175 commit 89be091
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
16 changes: 14 additions & 2 deletions crates/compiler/load_internal/src/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3291,7 +3291,7 @@ fn finish(
exposed_types_storage: ExposedTypesStorageSubs,
resolved_implementations: ResolvedImplementations,
dep_idents: IdentIdsByModule,
documentation: VecMap<ModuleId, ModuleDocumentation>,
mut documentation: VecMap<ModuleId, ModuleDocumentation>,
abilities_store: AbilitiesStore,
//
#[cfg(debug_assertions)] checkmate: Option<roc_checkmate::Collector>,
Expand Down Expand Up @@ -3330,6 +3330,18 @@ fn finish(

roc_checkmate::dump_checkmate!(checkmate);

let mut docs_by_module = Vec::with_capacity(state.exposed_modules.len());

for module_id in state.exposed_modules.iter() {
let docs = documentation.remove(module_id).unwrap_or_else(|| {
panic!("A module was exposed but didn't have an entry in `documentation` somehow: {module_id:?}");
});

docs_by_module.push(docs);
}

debug_assert_eq!(documentation.len(), 0);

LoadedModule {
module_id: state.root_id,
interns,
Expand All @@ -3346,7 +3358,7 @@ fn finish(
resolved_implementations,
sources,
timings: state.timings,
docs_by_module: documentation,
docs_by_module,
abilities_store,
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/compiler/load_internal/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub struct LoadedModule {
pub resolved_implementations: ResolvedImplementations,
pub sources: MutMap<ModuleId, (PathBuf, Box<str>)>,
pub timings: MutMap<ModuleId, ModuleTiming>,
pub docs_by_module: VecMap<ModuleId, ModuleDocumentation>,
pub docs_by_module: Vec<(ModuleId, ModuleDocumentation)>,
pub abilities_store: AbilitiesStore,
pub typechecked: MutMap<ModuleId, CheckedModule>,
}
Expand Down
8 changes: 4 additions & 4 deletions crates/docs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,13 @@ pub fn generate_docs_html(root_file: PathBuf, build_dir: &Path) {
.replace("<!-- base -->", &base_url())
.replace(
"<!-- Module links -->",
render_sidebar(loaded_module.docs_by_module.values()).as_str(),
render_sidebar(loaded_module.docs_by_module.iter().map(|(_, docs)| docs)).as_str(),
);

let all_exposed_symbols = {
let mut set = VecSet::default();

for docs in loaded_module.docs_by_module.values() {
for (_, docs) in loaded_module.docs_by_module.iter() {
set.insert_all(docs.exposed_symbols.iter().copied());
}

Expand Down Expand Up @@ -146,7 +146,7 @@ pub fn generate_docs_html(root_file: PathBuf, build_dir: &Path) {
}

// Write each package module's index.html file
for module_docs in loaded_module.docs_by_module.values() {
for (_, module_docs) in loaded_module.docs_by_module.iter() {
let module_name = module_docs.name.as_str();
let module_dir = build_dir.join(module_name.replace('.', "/").as_str());

Expand Down Expand Up @@ -183,7 +183,7 @@ fn render_package_index(root_module: &LoadedModule) -> String {
// The list items containing module links
let mut module_list_buf = String::new();

for module in root_module.docs_by_module.values() {
for (_, module) in root_module.docs_by_module.iter() {
// The anchor tag containing the module link
let mut link_buf = String::new();

Expand Down

0 comments on commit 89be091

Please sign in to comment.