From e9aafd4650da0fb274f1ee3a0c35a166fc34139e Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Sat, 25 Jul 2020 13:20:47 +0200 Subject: [PATCH] Add more log messages As I noticed when trying to debug an issue with a very large HTML file, we still need more log messages that indicate what is currently going on in rusty-man. This patch adds some more log messages. --- src/doc.rs | 5 +++++ src/parser.rs | 10 ++++++++-- src/source.rs | 8 ++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/doc.rs b/src/doc.rs index d69deec..2b4d917 100644 --- a/src/doc.rs +++ b/src/doc.rs @@ -387,6 +387,7 @@ impl Crate { } pub fn find_item(&self, name: &Fqn) -> anyhow::Result> { + log::info!("Searching item '{}' in crate '{}'", name, self.name); if self.name == name.krate() { if let Some(local_name) = name.rest() { if let Some(path) = parser::find_item(self.path.join("all.html"), local_name)? { @@ -405,6 +406,7 @@ impl Crate { } pub fn find_module(&self, name: &Fqn) -> Option { + log::info!("Searching module '{}' in crate '{}'", name, self.name); if self.name == name.krate() { let module_path = if let Some(rest) = name.rest() { rest.split("::").fold(path::PathBuf::new(), |mut p, s| { @@ -426,6 +428,7 @@ impl Crate { } pub fn find_member(&self, name: &Fqn) -> Option { + log::info!("Searching member '{}' in crate '{}'", name, self.name); if let Some(parent) = name.parent() { // TODO: error self.find_item(&parent) @@ -443,6 +446,7 @@ impl Item { } pub fn load_doc(&self) -> anyhow::Result { + log::info!("Loading documentation for '{}'", self.name); match self.ty { ItemType::TyMethod | ItemType::Method @@ -456,6 +460,7 @@ impl Item { } pub fn find_member(&self, name: &Fqn) -> Option { + log::info!("Searching member '{}' in item '{}'", name, self.name); // TODO: error handling parser::find_member(&self.path, name).unwrap() } diff --git a/src/parser.rs b/src/parser.rs index 8c81115..e0582f0 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -22,10 +22,13 @@ use crate::doc; fn parse_file>(path: P) -> anyhow::Result { use kuchiki::traits::TendrilSink; - kuchiki::parse_html() + log::info!("Reading HTML from file '{}'", path.as_ref().display()); + let result = kuchiki::parse_html() .from_utf8() .from_file(path) - .context("Could not read HTML file") + .context("Could not read HTML file"); + log::info!("HTML file parsed successfully"); + result } fn parse_string(s: impl Into) -> anyhow::Result { @@ -108,6 +111,7 @@ fn get_example(node: &kuchiki::NodeRef) -> doc::Example { } pub fn parse_item_doc(item: &doc::Item) -> anyhow::Result { + log::info!("Parsing item documentation for '{}'", item.name); let document = parse_file(&item.path)?; let definition_selector = if item.ty == doc::ItemType::Function { "pre.fn" @@ -162,6 +166,7 @@ const MODULE_MEMBER_TYPES: &[doc::ItemType] = &[ ]; pub fn parse_module_doc(item: &doc::Item) -> anyhow::Result { + log::info!("Parsing module documentation for '{}'", item.name); let document = parse_file(&item.path)?; let description = select_first(&document, ".docblock")?; @@ -178,6 +183,7 @@ pub fn parse_module_doc(item: &doc::Item) -> anyhow::Result { } pub fn parse_member_doc(item: &doc::Item) -> anyhow::Result { + log::info!("Parsing member documentation for '{}'", item.name); let document = parse_file(&item.path)?; let member = get_member(&document, item.name.last())? .with_context(|| format!("Could not find member {}", &item.name))?; diff --git a/src/source.rs b/src/source.rs index 2572df7..518740b 100644 --- a/src/source.rs +++ b/src/source.rs @@ -36,15 +36,23 @@ impl DirSource { impl Source for DirSource { fn find_crate(&self, name: &str) -> Option { + log::info!( + "Searching crate '{}' in dir source '{}'", + name, + self.path.display() + ); let crate_path = self.path.join(name.replace('-', "_")); if crate_path.join("all.html").is_file() { + log::info!("Found crate '{}': '{}'", name, crate_path.display()); Some(doc::Crate::new(name.to_owned(), crate_path)) } else { + log::info!("Did not find crate '{}' in '{}'", name, self.path.display()); None } } fn load_index(&self) -> anyhow::Result> { + log::info!("Searching search index for '{}'", self.path.display()); // use the first file that matches the pattern search-index*.js for entry in fs::read_dir(&self.path)? { let entry = entry?;