mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 14:24:45 +00:00
Fixed problems with docs failing to render and included test to validate that behavior
This commit is contained in:
parent
1c06e280b0
commit
62d5633546
8 changed files with 120 additions and 79 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -3139,6 +3139,7 @@ dependencies = [
|
|||
"roc_load",
|
||||
"roc_module",
|
||||
"roc_region",
|
||||
"roc_types",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
|
@ -20,7 +20,7 @@ use roc_types::types::Alias;
|
|||
pub struct Module {
|
||||
pub module_id: ModuleId,
|
||||
pub exposed_imports: MutMap<Symbol, Variable>,
|
||||
pub exposed_symbols: Vec<Symbol>,
|
||||
pub exposed_symbols: MutSet<Symbol>,
|
||||
pub references: MutSet<Symbol>,
|
||||
pub aliases: MutMap<Symbol, Alias>,
|
||||
pub rigid_variables: MutMap<Variable, Lowercase>,
|
||||
|
@ -50,7 +50,7 @@ pub fn canonicalize_module_defs<'a, F>(
|
|||
dep_idents: MutMap<ModuleId, IdentIds>,
|
||||
aliases: MutMap<Symbol, Alias>,
|
||||
exposed_imports: MutMap<Ident, (Symbol, Region)>,
|
||||
exposed_symbols: &Vec<Symbol>,
|
||||
exposed_symbols: &MutSet<Symbol>,
|
||||
var_store: &mut VarStore,
|
||||
look_up_builtin: F,
|
||||
) -> Result<ModuleOutput, RuntimeError>
|
||||
|
@ -203,11 +203,7 @@ where
|
|||
// we can see if there were any
|
||||
// exposed symbols which did not have
|
||||
// corresponding defs.
|
||||
if let Some(index) =
|
||||
exposed_but_not_defined.iter().position(|s| *s == *symbol)
|
||||
{
|
||||
exposed_but_not_defined.remove(index);
|
||||
}
|
||||
exposed_but_not_defined.remove(symbol);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -220,11 +216,7 @@ where
|
|||
// we can see if there were any
|
||||
// exposed symbols which did not have
|
||||
// corresponding defs.
|
||||
if let Some(index) =
|
||||
exposed_but_not_defined.iter().position(|s| *s == *symbol)
|
||||
{
|
||||
exposed_but_not_defined.remove(index);
|
||||
}
|
||||
exposed_but_not_defined.remove(symbol);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -252,9 +244,7 @@ where
|
|||
// we can see if there were any
|
||||
// exposed symbols which did not have
|
||||
// corresponding defs.
|
||||
if let Some(index) = exposed_but_not_defined.iter().position(|s| *s == symbol) {
|
||||
exposed_but_not_defined.remove(index);
|
||||
}
|
||||
exposed_but_not_defined.remove(&symbol);
|
||||
|
||||
aliases.insert(symbol, alias);
|
||||
}
|
||||
|
|
|
@ -123,7 +123,10 @@ fn detached_docs_from_comments_and_new_lines<'a>(
|
|||
}
|
||||
|
||||
CommentOrNewline::LineComment(_) | CommentOrNewline::Newline => {
|
||||
if !docs.is_empty() {
|
||||
detached_docs.push(docs.clone());
|
||||
}
|
||||
|
||||
docs = String::new();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ pub fn build_effect_builtins(
|
|||
scope: &mut Scope,
|
||||
effect_symbol: Symbol,
|
||||
var_store: &mut VarStore,
|
||||
exposed_symbols: &mut Vec<Symbol>,
|
||||
exposed_symbols: &mut MutSet<Symbol>,
|
||||
declarations: &mut Vec<Declaration>,
|
||||
) {
|
||||
for (_, f) in BUILTIN_EFFECT_FUNCTIONS.iter() {
|
||||
|
@ -60,7 +60,7 @@ pub fn build_effect_builtins(
|
|||
var_store,
|
||||
);
|
||||
|
||||
exposed_symbols.push(symbol);
|
||||
exposed_symbols.insert(symbol);
|
||||
declarations.push(Declaration::Declare(def));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -487,9 +487,7 @@ fn start_phase<'a>(
|
|||
let exposed_symbols = state
|
||||
.exposed_symbols_by_module
|
||||
.remove(&module_id)
|
||||
.expect("Could not find listener ID in exposed_symbols_by_module")
|
||||
.into_iter()
|
||||
.collect::<Vec<Symbol>>();
|
||||
.expect("Could not find listener ID in exposed_symbols_by_module");
|
||||
|
||||
let mut aliases = MutMap::default();
|
||||
|
||||
|
@ -974,7 +972,7 @@ enum BuildTask<'a> {
|
|||
parsed: ParsedModule<'a>,
|
||||
module_ids: ModuleIds,
|
||||
dep_idents: MutMap<ModuleId, IdentIds>,
|
||||
exposed_symbols: Vec<Symbol>,
|
||||
exposed_symbols: MutSet<Symbol>,
|
||||
aliases: MutMap<Symbol, Alias>,
|
||||
},
|
||||
Solve {
|
||||
|
@ -3503,8 +3501,8 @@ fn fabricate_effects_module<'a>(
|
|||
|
||||
let mut declarations = Vec::new();
|
||||
|
||||
let exposed_symbols: Vec<Symbol> = {
|
||||
let mut exposed_symbols = Vec::new();
|
||||
let exposed_symbols: MutSet<Symbol> = {
|
||||
let mut exposed_symbols = MutSet::default();
|
||||
|
||||
{
|
||||
for (ident, ann) in effect_entries {
|
||||
|
@ -3536,8 +3534,7 @@ fn fabricate_effects_module<'a>(
|
|||
&mut var_store,
|
||||
annotation,
|
||||
);
|
||||
|
||||
exposed_symbols.push(symbol);
|
||||
exposed_symbols.insert(symbol);
|
||||
|
||||
declarations.push(Declaration::Declare(def));
|
||||
}
|
||||
|
@ -3651,7 +3648,7 @@ fn canonicalize_and_constrain<'a, F>(
|
|||
arena: &'a Bump,
|
||||
module_ids: &ModuleIds,
|
||||
dep_idents: MutMap<ModuleId, IdentIds>,
|
||||
exposed_symbols: Vec<Symbol>,
|
||||
exposed_symbols: MutSet<Symbol>,
|
||||
aliases: MutMap<Symbol, Alias>,
|
||||
parsed: ParsedModule<'a>,
|
||||
look_up_builtins: F,
|
||||
|
|
|
@ -14,6 +14,7 @@ roc_builtins = { path = "../compiler/builtins" }
|
|||
roc_can = { path = "../compiler/can" }
|
||||
roc_module = { path = "../compiler/module" }
|
||||
roc_region = { path = "../compiler/region" }
|
||||
roc_types = { path = "../compiler/types" }
|
||||
roc_collections = { path = "../compiler/collections" }
|
||||
bumpalo = { version = "3.2", features = ["collections"] }
|
||||
|
||||
|
|
|
@ -163,9 +163,8 @@ fn render_main_content(
|
|||
}
|
||||
}
|
||||
DocEntry::DetachedDoc(docs) => {
|
||||
buf.push_str(
|
||||
markdown_to_html(&mut module.scope, interns, docs.to_string()).as_str(),
|
||||
);
|
||||
let markdown = markdown_to_html(&mut module.scope, interns, docs.to_string());
|
||||
buf.push_str(markdown.as_str());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -526,7 +525,7 @@ fn type_annotation_to_html(indent_level: usize, buf: &mut String, type_ann: &Typ
|
|||
}
|
||||
}
|
||||
|
||||
fn insert_doc_links(scope: &mut Scope, interns: &Interns, markdown: String) -> String {
|
||||
pub fn insert_doc_links(scope: &mut Scope, interns: &Interns, markdown: String) -> String {
|
||||
let buf = &markdown;
|
||||
let mut result = String::new();
|
||||
|
||||
|
@ -572,8 +571,12 @@ fn insert_doc_links(scope: &mut Scope, interns: &Interns, markdown: String) -> S
|
|||
}
|
||||
}
|
||||
|
||||
if chomping_from == None {
|
||||
markdown
|
||||
} else {
|
||||
result
|
||||
}
|
||||
}
|
||||
|
||||
fn make_doc_link(scope: &mut Scope, interns: &Interns, doc_item: &str) -> String {
|
||||
match scope.lookup(&doc_item.into(), Region::zero()) {
|
||||
|
@ -619,7 +622,8 @@ fn markdown_to_html(scope: &mut Scope, interns: &Interns, markdown: String) -> S
|
|||
let mut docs_parser = vec![];
|
||||
let (_, _) = pulldown_cmark::Parser::new_ext(&markdown_with_links, markdown_options).fold(
|
||||
(0, 0),
|
||||
|(start_quote_count, end_quote_count), event| match event {
|
||||
|(start_quote_count, end_quote_count), event| {
|
||||
match event {
|
||||
// Replace this sequence (`>>>` syntax):
|
||||
// Start(BlockQuote)
|
||||
// Start(BlockQuote)
|
||||
|
@ -671,10 +675,12 @@ fn markdown_to_html(scope: &mut Scope, interns: &Interns, markdown: String) -> S
|
|||
docs_parser.push(event);
|
||||
(0, 0)
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
let mut docs_html = String::new();
|
||||
|
||||
pulldown_cmark::html::push_html(&mut docs_html, docs_parser.into_iter());
|
||||
|
||||
docs_html
|
||||
|
|
43
docs/tests/insert_links.rs
Normal file
43
docs/tests/insert_links.rs
Normal file
|
@ -0,0 +1,43 @@
|
|||
#[macro_use]
|
||||
extern crate pretty_assertions;
|
||||
|
||||
#[cfg(test)]
|
||||
mod insert_doc_links {
|
||||
use roc_can::env::Env;
|
||||
use roc_can::scope::Scope;
|
||||
use roc_collections::all::MutMap;
|
||||
use roc_docs::insert_doc_links;
|
||||
use roc_module::symbol::{IdentIds, Interns, ModuleIds};
|
||||
use roc_types::subs::VarStore;
|
||||
|
||||
#[test]
|
||||
fn no_doc_links() {
|
||||
let home = ModuleIds::default().get_or_insert(&"Test".into());
|
||||
|
||||
let module_ids = ModuleIds::default();
|
||||
|
||||
let dep_idents = IdentIds::exposed_builtins(0);
|
||||
|
||||
let env = Env::new(home, dep_idents, &module_ids, IdentIds::default());
|
||||
|
||||
let all_ident_ids = MutMap::default();
|
||||
|
||||
let interns = Interns {
|
||||
module_ids: env.module_ids.clone(),
|
||||
all_ident_ids,
|
||||
};
|
||||
|
||||
let var_store = &mut VarStore::default();
|
||||
let scope = &mut Scope::new(home, var_store);
|
||||
|
||||
let markdown = r#"
|
||||
# Hello
|
||||
Hello thanks for using my package
|
||||
"#;
|
||||
|
||||
assert_eq!(
|
||||
markdown,
|
||||
insert_doc_links(scope, &interns, markdown.to_string()),
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue