mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 14:24:45 +00:00
Look into values exposed by host and only add those entries to the documentation html
This commit is contained in:
parent
31ccd699e8
commit
ebbdf671ae
2 changed files with 29 additions and 15 deletions
|
@ -2,11 +2,11 @@ use crate::docs::DocEntry::DetachedDoc;
|
||||||
use crate::docs::TypeAnnotation::{
|
use crate::docs::TypeAnnotation::{
|
||||||
Apply, BoundVariable, Function, NoTypeAnn, ObscuredRecord, ObscuredTagUnion, Record, TagUnion,
|
Apply, BoundVariable, Function, NoTypeAnn, ObscuredRecord, ObscuredTagUnion, Record, TagUnion,
|
||||||
};
|
};
|
||||||
|
use crate::file::LoadedModule;
|
||||||
use inlinable_string::InlinableString;
|
use inlinable_string::InlinableString;
|
||||||
use roc_can::scope::Scope;
|
use roc_can::scope::Scope;
|
||||||
use roc_collections::all::MutMap;
|
|
||||||
use roc_module::ident::ModuleName;
|
use roc_module::ident::ModuleName;
|
||||||
use roc_module::symbol::{IdentIds, Interns, ModuleId};
|
use roc_module::symbol::IdentIds;
|
||||||
use roc_parse::ast;
|
use roc_parse::ast;
|
||||||
use roc_parse::ast::CommentOrNewline;
|
use roc_parse::ast::CommentOrNewline;
|
||||||
use roc_parse::ast::{AssignedField, Def};
|
use roc_parse::ast::{AssignedField, Def};
|
||||||
|
@ -19,7 +19,7 @@ pub struct Documentation {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub version: String,
|
pub version: String,
|
||||||
pub docs: String,
|
pub docs: String,
|
||||||
pub modules: Vec<(MutMap<ModuleId, ModuleDocumentation>, Interns)>,
|
pub modules: Vec<LoadedModule>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
|
|
@ -3,14 +3,15 @@ use roc_builtins::std::StdLib;
|
||||||
use roc_can::builtins::builtin_defs_map;
|
use roc_can::builtins::builtin_defs_map;
|
||||||
use roc_load::docs::{DocEntry, TypeAnnotation};
|
use roc_load::docs::{DocEntry, TypeAnnotation};
|
||||||
use roc_load::docs::{ModuleDocumentation, RecordField};
|
use roc_load::docs::{ModuleDocumentation, RecordField};
|
||||||
use roc_load::file::LoadingProblem;
|
use roc_load::file::{LoadedModule, LoadingProblem};
|
||||||
use roc_module::symbol::{Interns, ModuleId};
|
use roc_module::symbol::Interns;
|
||||||
|
|
||||||
use std::fs;
|
use std::fs;
|
||||||
extern crate roc_load;
|
extern crate roc_load;
|
||||||
use bumpalo::Bump;
|
use bumpalo::Bump;
|
||||||
use roc_can::scope::Scope;
|
use roc_can::scope::Scope;
|
||||||
use roc_collections::all::MutMap;
|
use roc_collections::all::MutMap;
|
||||||
|
use roc_load::docs::DocEntry::DocDef;
|
||||||
use roc_region::all::Region;
|
use roc_region::all::Region;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
|
@ -55,14 +56,20 @@ pub fn generate(filenames: Vec<PathBuf>, std_lib: StdLib, build_dir: &Path) {
|
||||||
package
|
package
|
||||||
.modules
|
.modules
|
||||||
.iter()
|
.iter()
|
||||||
.flat_map(|(docs_by_id, _)| docs_by_id.values()),
|
.flat_map(|loaded_module| loaded_module.documentation.values()),
|
||||||
)
|
)
|
||||||
.as_str(),
|
.as_str(),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Write each package's module docs html file
|
// Write each package's module docs html file
|
||||||
for (docs_by_id, interns) in package.modules.iter_mut() {
|
for loaded_module in package.modules.iter_mut() {
|
||||||
for module in docs_by_id.values_mut() {
|
let exposed_values = loaded_module
|
||||||
|
.exposed_to_host
|
||||||
|
.iter()
|
||||||
|
.map(|(symbol, _)| symbol.ident_string(&loaded_module.interns).to_string())
|
||||||
|
.collect::<Vec<String>>();
|
||||||
|
|
||||||
|
for module in loaded_module.documentation.values_mut() {
|
||||||
let module_dir = build_dir.join(module.name.replace(".", "/").as_str());
|
let module_dir = build_dir.join(module.name.replace(".", "/").as_str());
|
||||||
|
|
||||||
fs::create_dir_all(&module_dir)
|
fs::create_dir_all(&module_dir)
|
||||||
|
@ -76,7 +83,7 @@ pub fn generate(filenames: Vec<PathBuf>, std_lib: StdLib, build_dir: &Path) {
|
||||||
)
|
)
|
||||||
.replace(
|
.replace(
|
||||||
"<!-- Module Docs -->",
|
"<!-- Module Docs -->",
|
||||||
render_main_content(interns, module).as_str(),
|
render_main_content(&loaded_module.interns, &exposed_values, module).as_str(),
|
||||||
);
|
);
|
||||||
|
|
||||||
fs::write(module_dir.join("index.html"), rendered_module)
|
fs::write(module_dir.join("index.html"), rendered_module)
|
||||||
|
@ -87,7 +94,11 @@ pub fn generate(filenames: Vec<PathBuf>, std_lib: StdLib, build_dir: &Path) {
|
||||||
println!("🎉 Docs generated in {}", build_dir.display());
|
println!("🎉 Docs generated in {}", build_dir.display());
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_main_content(interns: &Interns, module: &mut ModuleDocumentation) -> String {
|
fn render_main_content(
|
||||||
|
interns: &Interns,
|
||||||
|
exposed_values: &Vec<String>,
|
||||||
|
module: &mut ModuleDocumentation,
|
||||||
|
) -> String {
|
||||||
let mut buf = String::new();
|
let mut buf = String::new();
|
||||||
|
|
||||||
buf.push_str(
|
buf.push_str(
|
||||||
|
@ -100,6 +111,12 @@ fn render_main_content(interns: &Interns, module: &mut ModuleDocumentation) -> S
|
||||||
);
|
);
|
||||||
|
|
||||||
for entry in &module.entries {
|
for entry in &module.entries {
|
||||||
|
if let DocDef(def) = entry {
|
||||||
|
if !exposed_values.contains(&def.name) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
match entry {
|
match entry {
|
||||||
DocEntry::DocDef(doc_def) => {
|
DocEntry::DocDef(doc_def) => {
|
||||||
let mut href = String::new();
|
let mut href = String::new();
|
||||||
|
@ -288,10 +305,7 @@ fn render_sidebar<'a, I: Iterator<Item = &'a ModuleDocumentation>>(modules: I) -
|
||||||
buf
|
buf
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn files_to_documentations(
|
pub fn files_to_documentations(filenames: Vec<PathBuf>, std_lib: StdLib) -> Vec<LoadedModule> {
|
||||||
filenames: Vec<PathBuf>,
|
|
||||||
std_lib: StdLib,
|
|
||||||
) -> Vec<(MutMap<ModuleId, ModuleDocumentation>, Interns)> {
|
|
||||||
let arena = Bump::new();
|
let arena = Bump::new();
|
||||||
let mut files_docs = vec![];
|
let mut files_docs = vec![];
|
||||||
|
|
||||||
|
@ -308,7 +322,7 @@ pub fn files_to_documentations(
|
||||||
std::mem::size_of::<usize>() as u32, // This is just type-checking for docs, so "target" doesn't matter
|
std::mem::size_of::<usize>() as u32, // This is just type-checking for docs, so "target" doesn't matter
|
||||||
builtin_defs_map,
|
builtin_defs_map,
|
||||||
) {
|
) {
|
||||||
Ok(loaded) => files_docs.push((loaded.documentation, loaded.interns)),
|
Ok(loaded) => files_docs.push(loaded),
|
||||||
Err(LoadingProblem::FormattedReport(report)) => {
|
Err(LoadingProblem::FormattedReport(report)) => {
|
||||||
println!("{}", report);
|
println!("{}", report);
|
||||||
panic!();
|
panic!();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue