addes test to docs for function

This commit is contained in:
Anton-4 2021-10-15 15:02:37 +02:00
parent 428b4574ae
commit d3f2b95f7a
17 changed files with 136 additions and 578 deletions

View file

@ -4,7 +4,7 @@ use roc_ast::{
lang::{self, core::def::def_to_def2::def_to_def2},
mem_pool::pool::Pool,
};
use roc_code_markup::{markup::nodes::def2_to_markup, slow_pool::SlowPool};
use roc_code_markup::{markup::convert::from_def2::def2_to_markup, slow_pool::SlowPool};
use roc_module::symbol::{IdentIds, Interns, ModuleId, ModuleIds};
use roc_region::all::Region;
use roc_types::subs::VarStore;
@ -17,6 +17,7 @@ pub fn defs_to_html<'a>(
defs: Vec<roc_parse::ast::Def<'a>>,
env_module_id: ModuleId,
env_module_ids: &'a ModuleIds,
all_ident_ids: IdentIds,
interns: &Interns,
) {
let mut env_pool = Pool::with_capacity(1024);
@ -35,6 +36,7 @@ pub fn defs_to_html<'a>(
&mut var_store,
dep_idents,
env_module_ids,
all_ident_ids,
exposed_ident_ids,
);

View file

@ -5,7 +5,7 @@ use roc_ast::{
lang::{self, core::expr::expr_to_expr2::expr_to_expr2},
mem_pool::pool::Pool,
};
use roc_code_markup::{markup::nodes::expr2_to_markup, slow_pool::SlowPool};
use roc_code_markup::{markup::convert::from_expr2::expr2_to_markup, slow_pool::SlowPool};
use roc_module::symbol::{IdentIds, Interns, ModuleId, ModuleIds};
use roc_parse::ast::Expr;
use roc_region::all::Region;
@ -17,6 +17,7 @@ pub fn expr_to_html<'a>(
expr: Expr<'a>,
env_module_id: ModuleId,
env_module_ids: &'a ModuleIds,
all_ident_ids: IdentIds,
interns: &Interns,
) {
let mut env_pool = Pool::with_capacity(1024);
@ -33,6 +34,7 @@ pub fn expr_to_html<'a>(
&mut var_store,
dep_idents,
env_module_ids,
all_ident_ids,
exposed_ident_ids,
);
@ -63,6 +65,7 @@ fn write_expr_to_bump_str_html<'a, 'b>(
expr2_id,
&mut mark_node_pool,
interns,
0,
)?;
let expr2_markup_node = mark_node_pool.get(expr2_markup_id);

View file

@ -7,7 +7,7 @@ pub fn mark_node_to_html<'a>(
mark_node_pool: &SlowPool,
buf: &mut BumpString<'a>,
) {
let additional_newlines: usize;
let mut additional_newlines = 0;
match mark_node {
MarkupNode::Nested {
@ -33,12 +33,13 @@ pub fn mark_node_to_html<'a>(
Operator => "operator",
Comma => "comma",
String => "string",
FunctionName => "function_name",
FunctionName => "function-name",
FunctionArgName => "function-arg-name",
Type => "type",
Bracket => "bracket",
Number => "number",
PackageRelated => "package-related",
Variable => "variable",
Value => "value",
RecordField => "recordfield",
Import => "import",
Provides => "provides",
@ -62,6 +63,11 @@ pub fn mark_node_to_html<'a>(
additional_newlines = *newlines_at_end;
}
MarkupNode::Indent { .. } => {
let content_str = mark_node.get_content();
write_html_to_buf(&content_str, "indent", buf);
}
}
for _ in 0..additional_newlines {

View file

@ -127,6 +127,7 @@ pub fn syntax_highlight_expr<'a>(
code_str: &'a str,
env_module_id: ModuleId,
env_module_ids: &'a ModuleIds,
all_ident_ids: IdentIds,
interns: &Interns,
) -> Result<String, SyntaxError<'a>> {
let trimmed_code_str = code_str.trim_end().trim();
@ -134,7 +135,14 @@ pub fn syntax_highlight_expr<'a>(
match roc_parse::expr::test_parse_expr(0, arena, state) {
Ok(loc_expr) => {
expr_to_html(buf, loc_expr.value, env_module_id, env_module_ids, interns);
expr_to_html(
buf,
loc_expr.value,
env_module_id,
env_module_ids,
all_ident_ids,
interns,
);
Ok(buf.to_string())
}
@ -149,6 +157,7 @@ pub fn syntax_highlight_top_level_defs<'a>(
code_str: &'a str,
env_module_id: ModuleId,
env_module_ids: &'a ModuleIds,
all_ident_ids: IdentIds,
interns: &Interns,
) -> Result<String, SyntaxError<'a>> {
let trimmed_code_str = code_str.trim_end().trim();
@ -157,7 +166,14 @@ pub fn syntax_highlight_top_level_defs<'a>(
Ok(vec_loc_def) => {
let vec_def = vec_loc_def.iter().map(|loc| loc.value).collect();
defs_to_html(buf, vec_def, env_module_id, env_module_ids, interns);
defs_to_html(
buf,
vec_def,
env_module_id,
env_module_ids,
all_ident_ids,
interns,
);
Ok(buf.to_string())
}
@ -972,12 +988,21 @@ fn markdown_to_html(
let code_block_arena = Bump::new();
let mut code_block_buf = BumpString::new_in(&code_block_arena);
let all_ident_ids = loaded_module
.interns
.all_ident_ids
.get(&loaded_module.module_id)
.unwrap()
.clone(); //TODO remove unwrap
match syntax_highlight_expr(
&code_block_arena,
&mut code_block_buf,
code_str,
loaded_module.module_id,
&loaded_module.interns.module_ids,
all_ident_ids,
&loaded_module.interns
)
{