mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 22:34:45 +00:00
reference TypeAnnotation from ast as ast::TypeAnnotation so that the name TypeAnnotation can be reused in roc_load::docs
This commit is contained in:
parent
e168fb201d
commit
406860f121
2 changed files with 28 additions and 28 deletions
|
@ -1,8 +1,8 @@
|
|||
use crate::docs::DocTypeAnnotation::{Apply, BoundVariable, TagUnion};
|
||||
use crate::docs::TypeAnnotation::{Apply, BoundVariable, TagUnion};
|
||||
use inlinable_string::InlinableString;
|
||||
use roc_module::ident::ModuleName;
|
||||
use roc_module::symbol::IdentIds;
|
||||
use roc_parse::ast::{Def, Tag, TypeAnnotation};
|
||||
use roc_parse::ast;
|
||||
use roc_region::all::Located;
|
||||
|
||||
// Documentation generation requirements
|
||||
|
@ -26,33 +26,33 @@ pub struct ModuleDocumentation {
|
|||
pub struct DocEntry {
|
||||
pub name: String,
|
||||
pub type_vars: Vec<String>,
|
||||
pub type_annotation: Option<DocTypeAnnotation>,
|
||||
pub type_annotation: Option<TypeAnnotation>,
|
||||
pub docs: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum DocTypeAnnotation {
|
||||
pub enum TypeAnnotation {
|
||||
TagUnion {
|
||||
tags: Vec<DocTag>,
|
||||
extension: Option<Box<DocTypeAnnotation>>,
|
||||
tags: Vec<Tag>,
|
||||
extension: Option<Box<TypeAnnotation>>,
|
||||
},
|
||||
BoundVariable(String),
|
||||
Apply {
|
||||
name: String,
|
||||
parts: Vec<DocTypeAnnotation>,
|
||||
parts: Vec<TypeAnnotation>,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct DocTag {
|
||||
pub struct Tag {
|
||||
pub name: String,
|
||||
pub values: Vec<DocTypeAnnotation>,
|
||||
pub values: Vec<TypeAnnotation>,
|
||||
}
|
||||
|
||||
pub fn generate_module_docs<'a>(
|
||||
module_name: ModuleName,
|
||||
exposed_ident_ids: &'a IdentIds,
|
||||
parsed_defs: &'a [Located<Def<'a>>],
|
||||
parsed_defs: &'a [Located<ast::Def<'a>>],
|
||||
) -> ModuleDocumentation {
|
||||
let (entries, _) =
|
||||
parsed_defs
|
||||
|
@ -72,7 +72,7 @@ fn generate_module_doc<'a>(
|
|||
exposed_ident_ids: &'a IdentIds,
|
||||
mut acc: Vec<DocEntry>,
|
||||
before_comments_or_new_lines: Option<&'a [roc_parse::ast::CommentOrNewline<'a>]>,
|
||||
def: &'a Def<'a>,
|
||||
def: &'a ast::Def<'a>,
|
||||
) -> (
|
||||
Vec<DocEntry>,
|
||||
Option<&'a [roc_parse::ast::CommentOrNewline<'a>]>,
|
||||
|
@ -162,14 +162,14 @@ fn generate_module_doc<'a>(
|
|||
}
|
||||
}
|
||||
|
||||
fn type_to_docs(type_annotation: TypeAnnotation) -> Option<DocTypeAnnotation> {
|
||||
fn type_to_docs(type_annotation: ast::TypeAnnotation) -> Option<TypeAnnotation> {
|
||||
match type_annotation {
|
||||
TypeAnnotation::TagUnion {
|
||||
ast::TypeAnnotation::TagUnion {
|
||||
tags,
|
||||
ext,
|
||||
final_comments: _,
|
||||
} => {
|
||||
let mut tags_to_render: Vec<DocTag> = Vec::new();
|
||||
let mut tags_to_render: Vec<Tag> = Vec::new();
|
||||
|
||||
let mut any_tags_are_private = false;
|
||||
|
||||
|
@ -204,8 +204,8 @@ fn type_to_docs(type_annotation: TypeAnnotation) -> Option<DocTypeAnnotation> {
|
|||
})
|
||||
}
|
||||
}
|
||||
TypeAnnotation::BoundVariable(var_name) => Some(BoundVariable(var_name.to_string())),
|
||||
TypeAnnotation::Apply(module_name, type_name, type_ann_parts) => {
|
||||
ast::TypeAnnotation::BoundVariable(var_name) => Some(BoundVariable(var_name.to_string())),
|
||||
ast::TypeAnnotation::Apply(module_name, type_name, type_ann_parts) => {
|
||||
let mut name = String::new();
|
||||
|
||||
if !module_name.is_empty() {
|
||||
|
@ -215,7 +215,7 @@ fn type_to_docs(type_annotation: TypeAnnotation) -> Option<DocTypeAnnotation> {
|
|||
|
||||
name.push_str(type_name);
|
||||
|
||||
let mut parts: Vec<DocTypeAnnotation> = Vec::new();
|
||||
let mut parts: Vec<TypeAnnotation> = Vec::new();
|
||||
|
||||
for type_ann_part in type_ann_parts {
|
||||
if let Some(part) = type_to_docs(type_ann_part.value) {
|
||||
|
@ -235,9 +235,9 @@ fn type_to_docs(type_annotation: TypeAnnotation) -> Option<DocTypeAnnotation> {
|
|||
|
||||
// The Option here represents if it is private. Private tags
|
||||
// evaluate to `None`.
|
||||
fn tag_to_doc(tag: Tag) -> Option<DocTag> {
|
||||
fn tag_to_doc(tag: ast::Tag) -> Option<Tag> {
|
||||
match tag {
|
||||
Tag::Global { name, args } => Some(DocTag {
|
||||
ast::Tag::Global { name, args } => Some(Tag {
|
||||
name: name.value.to_string(),
|
||||
values: {
|
||||
let mut type_vars = Vec::new();
|
||||
|
@ -257,10 +257,10 @@ fn tag_to_doc(tag: Tag) -> Option<DocTag> {
|
|||
type_vars
|
||||
},
|
||||
}),
|
||||
Tag::Private { .. } => None,
|
||||
Tag::SpaceBefore(&sub_tag, _) => tag_to_doc(sub_tag),
|
||||
Tag::SpaceAfter(&sub_tag, _) => tag_to_doc(sub_tag),
|
||||
Tag::Malformed(_) => None,
|
||||
ast::Tag::Private { .. } => None,
|
||||
ast::Tag::SpaceBefore(&sub_tag, _) => tag_to_doc(sub_tag),
|
||||
ast::Tag::SpaceAfter(&sub_tag, _) => tag_to_doc(sub_tag),
|
||||
ast::Tag::Malformed(_) => None,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
extern crate pulldown_cmark;
|
||||
use roc_builtins::std::StdLib;
|
||||
use roc_can::builtins::builtin_defs_map;
|
||||
use roc_load::docs::DocTypeAnnotation;
|
||||
use roc_load::docs::ModuleDocumentation;
|
||||
use roc_load::docs::TypeAnnotation;
|
||||
use roc_load::file::LoadingProblem;
|
||||
|
||||
use std::fs;
|
||||
|
@ -291,9 +291,9 @@ fn indent(buf: &mut String, times: usize) {
|
|||
}
|
||||
}
|
||||
|
||||
fn type_annotation_to_html(indent_level: usize, buf: &mut String, type_ann: &DocTypeAnnotation) {
|
||||
fn type_annotation_to_html(indent_level: usize, buf: &mut String, type_ann: &TypeAnnotation) {
|
||||
match type_ann {
|
||||
DocTypeAnnotation::TagUnion { tags, extension } => {
|
||||
TypeAnnotation::TagUnion { tags, extension } => {
|
||||
buf.push_str("<br>");
|
||||
|
||||
let tag_union_indent = indent_level + 1;
|
||||
|
@ -336,10 +336,10 @@ fn type_annotation_to_html(indent_level: usize, buf: &mut String, type_ann: &Doc
|
|||
type_annotation_to_html(indent_level, buf, ext);
|
||||
}
|
||||
}
|
||||
DocTypeAnnotation::BoundVariable(var_name) => {
|
||||
TypeAnnotation::BoundVariable(var_name) => {
|
||||
buf.push_str(var_name);
|
||||
}
|
||||
DocTypeAnnotation::Apply { name, parts } => {
|
||||
TypeAnnotation::Apply { name, parts } => {
|
||||
if parts.is_empty() {
|
||||
buf.push_str(name);
|
||||
} else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue