Effectful function in docs

This commit is contained in:
Agus Zubiaga 2024-10-17 22:38:23 -03:00
parent 28f35edb2c
commit 8a65617704
No known key found for this signature in database
2 changed files with 19 additions and 8 deletions

View file

@ -4,8 +4,8 @@ use roc_can::scope::Scope;
use roc_collections::VecSet;
use roc_module::ident::ModuleName;
use roc_module::symbol::{IdentIds, ModuleId, ModuleIds, Symbol};
use roc_parse::ast::AssignedField;
use roc_parse::ast::{self, ExtractSpaces, TypeHeader};
use roc_parse::ast::{AssignedField, FunctionArrow};
use roc_parse::ast::{CommentOrNewline, TypeDef, ValueDef};
// Documentation generation requirements
@ -53,6 +53,7 @@ pub enum TypeAnnotation {
},
Function {
args: Vec<TypeAnnotation>,
arrow: FunctionArrow,
output: Box<TypeAnnotation>,
},
ObscuredTagUnion,
@ -615,8 +616,7 @@ fn type_to_docs(in_func_type_ann: bool, type_annotation: ast::TypeAnnotation) ->
ast::TypeAnnotation::SpaceAfter(&sub_type_ann, _) => {
type_to_docs(in_func_type_ann, sub_type_ann)
}
ast::TypeAnnotation::Function(ast_arg_anns, _arrow, output_ann) => {
// [purity-inference] TODO: arrow
ast::TypeAnnotation::Function(ast_arg_anns, arrow, output_ann) => {
let mut doc_arg_anns = Vec::new();
for ast_arg_ann in ast_arg_anns {
@ -625,6 +625,7 @@ fn type_to_docs(in_func_type_ann: bool, type_annotation: ast::TypeAnnotation) ->
Function {
args: doc_arg_anns,
arrow,
output: Box::new(type_to_docs(true, output_ann.value)),
}
}

View file

@ -10,6 +10,7 @@ use roc_load::docs::{ModuleDocumentation, RecordField};
use roc_load::{ExecutionMode, LoadConfig, LoadedModule, LoadingProblem, Threading};
use roc_module::symbol::{Interns, ModuleId, Symbol};
use roc_packaging::cache::{self, RocCacheDir};
use roc_parse::ast::FunctionArrow;
use roc_parse::ident::{parse_ident, Accessor, Ident};
use roc_parse::keyword;
use roc_parse::state::State;
@ -827,7 +828,11 @@ fn type_annotation_to_html(
type_annotation_to_html(indent_level, buf, extension, true);
}
TypeAnnotation::Function { args, output } => {
TypeAnnotation::Function {
args,
arrow,
output,
} => {
let mut paren_is_open = false;
let mut peekable_args = args.iter().peekable();
@ -858,7 +863,10 @@ fn type_annotation_to_html(
buf.push(' ');
}
buf.push_str("-> ");
match arrow {
FunctionArrow::Effectful => buf.push_str("=> "),
FunctionArrow::Pure => buf.push_str("-> "),
}
let mut next_indent_level = indent_level;
@ -1029,9 +1037,11 @@ fn should_be_multiline(type_ann: &TypeAnnotation) -> bool {
.iter()
.any(|tag| tag.values.iter().any(should_be_multiline))
}
TypeAnnotation::Function { args, output } => {
args.len() > 2 || should_be_multiline(output) || args.iter().any(should_be_multiline)
}
TypeAnnotation::Function {
args,
arrow: _,
output,
} => args.len() > 2 || should_be_multiline(output) || args.iter().any(should_be_multiline),
TypeAnnotation::ObscuredTagUnion => false,
TypeAnnotation::ObscuredRecord => false,
TypeAnnotation::BoundVariable(_) => false,