1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-23 07:44:48 -05:00
denoland-deno/cli/doc/mod.rs
Valentin Anger 3374c73fba
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
2020-07-12 14:16:33 +02:00

74 lines
1.6 KiB
Rust

// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
pub mod class;
mod display;
pub mod r#enum;
pub mod function;
pub mod interface;
pub mod module;
pub mod namespace;
mod node;
pub mod params;
pub mod parser;
pub mod printer;
pub mod ts_type;
pub mod ts_type_param;
pub mod type_alias;
pub mod variable;
pub use node::DocNode;
pub use node::DocNodeKind;
pub use node::Location;
pub use params::ParamDef;
pub use parser::DocParser;
pub use printer::DocPrinter;
#[cfg(test)]
mod tests;
pub fn find_nodes_by_name_recursively(
doc_nodes: Vec<DocNode>,
name: String,
) -> Vec<DocNode> {
let mut parts = name.splitn(2, '.');
let name = parts.next();
let leftover = parts.next();
if name.is_none() {
return doc_nodes;
}
let name = name.unwrap();
let doc_nodes = find_nodes_by_name(doc_nodes, name.to_string());
let mut found: Vec<DocNode> = vec![];
match leftover {
Some(leftover) => {
for node in doc_nodes {
let children = find_children_by_name(node, leftover.to_string());
found.extend(children);
}
found
}
None => doc_nodes,
}
}
fn find_nodes_by_name(doc_nodes: Vec<DocNode>, name: String) -> Vec<DocNode> {
let mut found: Vec<DocNode> = vec![];
for node in doc_nodes {
if node.name == name {
found.push(node);
}
}
found
}
fn find_children_by_name(node: DocNode, name: String) -> Vec<DocNode> {
match node.kind {
DocNodeKind::Namespace => {
let namespace_def = node.namespace_def.unwrap();
find_nodes_by_name_recursively(namespace_def.elements, name)
}
// TODO(#4516) handle class, interface etc...
_ => vec![],
}
}