mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 14:24:45 +00:00
Render label only record fields as they appear in the code
This commit is contained in:
parent
8f0dfa8091
commit
be557d6147
2 changed files with 37 additions and 17 deletions
|
@ -1,8 +1,8 @@
|
|||
extern crate pulldown_cmark;
|
||||
use roc_builtins::std::StdLib;
|
||||
use roc_can::builtins::builtin_defs_map;
|
||||
use roc_load::docs::ModuleDocumentation;
|
||||
use roc_load::docs::TypeAnnotation;
|
||||
use roc_load::docs::{ModuleDocumentation, RecordField};
|
||||
use roc_load::file::LoadingProblem;
|
||||
|
||||
use std::fs;
|
||||
|
@ -352,13 +352,30 @@ fn type_annotation_to_html(indent_level: usize, buf: &mut String, type_ann: &Typ
|
|||
let next_indent_level = record_indent + 1;
|
||||
for (index, field) in fields.iter().enumerate() {
|
||||
indent(buf, next_indent_level);
|
||||
buf.push_str(field.name.as_str());
|
||||
|
||||
let separator = if field.optional { " ? " } else { " : " };
|
||||
let fields_name = match field {
|
||||
RecordField::RecordField { name, .. } => name,
|
||||
RecordField::OptionalField { name, .. } => name,
|
||||
RecordField::LabelOnly { name } => name,
|
||||
};
|
||||
|
||||
buf.push_str(separator);
|
||||
buf.push_str(fields_name.as_str());
|
||||
|
||||
type_annotation_to_html(next_indent_level, buf, &field.type_annotation);
|
||||
match field {
|
||||
RecordField::RecordField {
|
||||
type_annotation, ..
|
||||
} => {
|
||||
buf.push_str(" : ");
|
||||
type_annotation_to_html(next_indent_level, buf, type_annotation);
|
||||
}
|
||||
RecordField::OptionalField {
|
||||
type_annotation, ..
|
||||
} => {
|
||||
buf.push_str(" ? ");
|
||||
type_annotation_to_html(next_indent_level, buf, type_annotation);
|
||||
}
|
||||
RecordField::LabelOnly { .. } => {}
|
||||
}
|
||||
|
||||
if index < (fields.len() - 1) {
|
||||
buf.push(',');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue