Skip to content

Commit

Permalink
Merge branch 'main' into type_tracing
Browse files Browse the repository at this point in the history
  • Loading branch information
dsherret committed Oct 26, 2023
2 parents ce697b6 + 6bd2d49 commit 3b65abf
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
6 changes: 4 additions & 2 deletions examples/ddoc/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,11 @@ async fn run() -> anyhow::Result<()> {
let matches = App::new("ddoc")
.arg(Arg::with_name("source_file").required(true))
.arg(Arg::with_name("filter"))
.arg(Arg::with_name("private").long("private"))
.get_matches();
let source_file = matches.value_of("source_file").unwrap();
let maybe_filter = matches.value_of("filter");
let private = matches.is_present("private");
let source_file =
ModuleSpecifier::from_directory_path(current_dir().unwrap())
.unwrap()
Expand All @@ -71,14 +73,14 @@ async fn run() -> anyhow::Result<()> {
},
)
.await;
let parser = DocParser::new(graph, false, analyzer.as_capturing_parser())?;
let parser = DocParser::new(graph, private, analyzer.as_capturing_parser())?;
let mut doc_nodes = parser.parse_with_reexports(&source_file)?;

doc_nodes.retain(|doc_node| doc_node.kind != DocNodeKind::Import);
if let Some(filter) = maybe_filter {
doc_nodes = find_nodes_by_name_recursively(doc_nodes, filter.to_string());
}
let result = DocPrinter::new(&doc_nodes, true, false);
let result = DocPrinter::new(&doc_nodes, true, private);
println!("{}", result);
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub struct ImportDef {
pub imported: Option<String>,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq)]
#[serde(rename_all = "camelCase")]
pub enum DeclarationKind {
Private,
Expand Down
30 changes: 23 additions & 7 deletions src/printer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use crate::display::Indent;
use crate::display::SliceDisplayer;
use crate::js_doc::JsDoc;
use crate::js_doc::JsDocTag;
use crate::node::DeclarationKind;
use crate::node::DocNode;
use crate::node::DocNodeKind;

Expand Down Expand Up @@ -491,8 +492,9 @@ impl<'a> DocPrinter<'a> {
}
write!(
w,
"{}{}{} {}",
"{}{}{}{} {}",
Indent(indent),
fmt_visibility(node.declaration_kind),
display_abstract(class_def.is_abstract),
colors::magenta("class"),
colors::bold(&node.name),
Expand Down Expand Up @@ -536,8 +538,9 @@ impl<'a> DocPrinter<'a> {
) -> FmtResult {
writeln!(
w,
"{}{} {}",
"{}{}{} {}",
Indent(indent),
fmt_visibility(node.declaration_kind),
colors::magenta("enum"),
colors::bold(&node.name)
)
Expand All @@ -554,8 +557,9 @@ impl<'a> DocPrinter<'a> {
if !has_overloads || !function_def.has_body {
write!(
w,
"{}{}{}{} {}",
"{}{}{}{}{} {}",
Indent(indent),
fmt_visibility(node.declaration_kind),
display_async(function_def.is_async),
colors::magenta("function"),
display_generator(function_def.is_generator),
Expand Down Expand Up @@ -590,8 +594,9 @@ impl<'a> DocPrinter<'a> {
let interface_def = node.interface_def.as_ref().unwrap();
write!(
w,
"{}{} {}",
"{}{}{} {}",
Indent(indent),
fmt_visibility(node.declaration_kind),
colors::magenta("interface"),
colors::bold(&node.name)
)?;
Expand Down Expand Up @@ -636,8 +641,9 @@ impl<'a> DocPrinter<'a> {
let type_alias_def = node.type_alias_def.as_ref().unwrap();
write!(
w,
"{}{} {}",
"{}{}{} {}",
Indent(indent),
fmt_visibility(node.declaration_kind),
colors::magenta("type"),
colors::bold(&node.name),
)?;
Expand All @@ -661,8 +667,9 @@ impl<'a> DocPrinter<'a> {
) -> FmtResult {
writeln!(
w,
"{}{} {}",
"{}{}{} {}",
Indent(indent),
fmt_visibility(node.declaration_kind),
colors::magenta("namespace"),
colors::bold(&node.name)
)
Expand All @@ -677,8 +684,9 @@ impl<'a> DocPrinter<'a> {
let variable_def = node.variable_def.as_ref().unwrap();
write!(
w,
"{}{} {}",
"{}{}{} {}",
Indent(indent),
fmt_visibility(node.declaration_kind),
colors::magenta(match variable_def.kind {
deno_ast::swc::ast::VarDeclKind::Const => "const",
deno_ast::swc::ast::VarDeclKind::Let => "let",
Expand All @@ -698,3 +706,11 @@ impl<'a> Display for DocPrinter<'a> {
self.format(f)
}
}

fn fmt_visibility(decl_kind: DeclarationKind) -> impl std::fmt::Display {
colors::italic_gray(if decl_kind == DeclarationKind::Private {
"private "
} else {
""
})
}

0 comments on commit 3b65abf

Please sign in to comment.