From 3374c73fba3a96df22d0c04e6c17078ca8cce45b Mon Sep 17 00:00:00 2001 From: Valentin Anger Date: Sun, 12 Jul 2020 14:16:33 +0200 Subject: feat(doc): Improve terminal printer (#6594) - Add more support for generics - Add the --private flag - displays documentation for not exported and private nodes - Display more attributes like abstract, static and readonly - Display type aliases - Refactor module to use the Display trait - Use a bit more color --- cli/doc/parser.rs | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) (limited to 'cli/doc/parser.rs') diff --git a/cli/doc/parser.rs b/cli/doc/parser.rs index 3746e3dfb..59fa2b734 100644 --- a/cli/doc/parser.rs +++ b/cli/doc/parser.rs @@ -44,13 +44,15 @@ pub trait DocFileLoader { pub struct DocParser { pub ast_parser: AstParser, pub loader: Box, + pub private: bool, } impl DocParser { - pub fn new(loader: Box) -> Self { + pub fn new(loader: Box, private: bool) -> Self { DocParser { loader, ast_parser: AstParser::new(), + private, } } @@ -70,7 +72,7 @@ impl DocParser { self.get_doc_nodes_for_module_body(module.body.clone()); let reexports = self.get_reexports_for_module_body(module.body); let module_doc = ModuleDoc { - exports: doc_entries, + definitions: doc_entries, reexports, }; Ok(module_doc) @@ -90,7 +92,7 @@ impl DocParser { source_code: &str, ) -> Result, ErrBox> { let module_doc = self.parse_module(file_name, &source_code)?; - Ok(module_doc.exports) + Ok(module_doc.definitions) } async fn flatten_reexports( @@ -187,10 +189,10 @@ impl DocParser { let mut flattenned_reexports = self .flatten_reexports(&module_doc.reexports, file_name) .await?; - flattenned_reexports.extend(module_doc.exports); + flattenned_reexports.extend(module_doc.definitions); flattenned_reexports } else { - module_doc.exports + module_doc.definitions }; Ok(flattened_docs) @@ -231,8 +233,10 @@ impl DocParser { } } DefaultDecl::Fn(fn_expr) => { - let function_def = - crate::doc::function::function_to_function_def(&fn_expr.function); + let function_def = crate::doc::function::function_to_function_def( + self, + &fn_expr.function, + ); DocNode { kind: DocNodeKind::Function, name, @@ -292,7 +296,7 @@ impl DocParser { pub fn get_doc_node_for_decl(&self, decl: &Decl) -> Option { match decl { Decl::Class(class_decl) => { - if !class_decl.declare { + if !self.private && !class_decl.declare { return None; } let (name, class_def) = @@ -313,11 +317,11 @@ impl DocParser { }) } Decl::Fn(fn_decl) => { - if !fn_decl.declare { + if !self.private && !fn_decl.declare { return None; } let (name, function_def) = - super::function::get_doc_for_fn_decl(fn_decl); + super::function::get_doc_for_fn_decl(self, fn_decl); let (js_doc, location) = self.details_for_span(fn_decl.function.span); Some(DocNode { kind: DocNodeKind::Function, @@ -334,7 +338,7 @@ impl DocParser { }) } Decl::Var(var_decl) => { - if !var_decl.declare { + if !self.private && !var_decl.declare { return None; } let (name, var_def) = super::variable::get_doc_for_var_decl(var_decl); @@ -354,7 +358,7 @@ impl DocParser { }) } Decl::TsInterface(ts_interface_decl) => { - if !ts_interface_decl.declare { + if !self.private && !ts_interface_decl.declare { return None; } let (name, interface_def) = @@ -378,7 +382,7 @@ impl DocParser { }) } Decl::TsTypeAlias(ts_type_alias) => { - if !ts_type_alias.declare { + if !self.private && !ts_type_alias.declare { return None; } let (name, type_alias_def) = @@ -402,7 +406,7 @@ impl DocParser { }) } Decl::TsEnum(ts_enum) => { - if !ts_enum.declare { + if !self.private && !ts_enum.declare { return None; } let (name, enum_def) = @@ -423,7 +427,7 @@ impl DocParser { }) } Decl::TsModule(ts_module) => { - if !ts_module.declare { + if !self.private && !ts_module.declare { return None; } let (name, namespace_def) = -- cgit v1.2.3