From 591e066226524ff1237525e87ceb0c97ad52def3 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Tue, 17 Mar 2020 12:05:09 -0700 Subject: [PATCH] tags: Make cli output more human readable --- cli/src/tags.rs | 16 +++++++++++++--- tags/src/lib.rs | 19 ++++++++----------- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/cli/src/tags.rs b/cli/src/tags.rs index de9eac1c..86eb2e33 100644 --- a/cli/src/tags.rs +++ b/cli/src/tags.rs @@ -32,17 +32,27 @@ pub fn generate_tags(loader: &Loader, scope: Option<&str>, paths: &[String]) -> }; if let Some(tags_config) = language_config.tags_config(language)? { + let path_str = format!("{:?}", path); + writeln!(&mut stdout, "{}", &path_str[1..path_str.len() - 1])?; + let source = fs::read(path)?; for tag in context.generate_tags(tags_config, &source) { - writeln!( + write!( &mut stdout, - "{}\t{}\t{} - {}\tdocs:{}", + " {:<8}\t{:<40}\t{:>9}-{:<9}", tag.kind, str::from_utf8(&source[tag.name_range]).unwrap_or(""), tag.span.start, tag.span.end, - tag.docs.unwrap_or(String::new()), )?; + if let Some(docs) = tag.docs { + if docs.len() > 120 { + write!(&mut stdout, "\t{:?}...", &docs[0..120])?; + } else { + write!(&mut stdout, "\t{:?}", &docs)?; + } + } + writeln!(&mut stdout, "")?; } } else { eprintln!("No tags config found for path {:?}", path); diff --git a/tags/src/lib.rs b/tags/src/lib.rs index 89eafa14..8e3625e5 100644 --- a/tags/src/lib.rs +++ b/tags/src/lib.rs @@ -335,17 +335,14 @@ where impl fmt::Display for TagKind { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!( - f, - "{}", - match self { - TagKind::Call => "Call", - TagKind::Module => "Module", - TagKind::Class => "Class", - TagKind::Method => "Method", - TagKind::Function => "Function", - } - ) + match self { + TagKind::Call => "Call", + TagKind::Module => "Module", + TagKind::Class => "Class", + TagKind::Method => "Method", + TagKind::Function => "Function", + } + .fmt(f) } }