Skip to content

Commit

Permalink
feat(spans-visual): spans visual defaults to hiding newline spans
Browse files Browse the repository at this point in the history
  • Loading branch information
grantlemons committed Dec 30, 2024
1 parent 487484d commit 153c17a
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions harper-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ enum Args {
Spans {
/// The file you wish to display the spans.
file: PathBuf,
/// Include newlines in the output
#[arg(short, long)]
include_newlines: bool,
},
/// Emit decompressed, line-separated list of words in Harper's dictionary.
Words,
Expand Down Expand Up @@ -89,7 +92,10 @@ fn main() -> anyhow::Result<()> {

Ok(())
}
Args::Spans { file } => {
Args::Spans {
file,
include_newlines,
} => {
let (doc, source) = load_file(&file)?;

let primary_color = Color::Blue;
Expand All @@ -103,7 +109,11 @@ fn main() -> anyhow::Result<()> {
let mut report_builder =
Report::build(ReportKind::Custom("Spans", primary_color), &filename, 0);
let mut color = primary_color;
for token in doc.tokens() {

for token in doc.tokens().filter(|t| {
include_newlines
|| !matches!(t.kind, TokenKind::Newline(_) | TokenKind::ParagraphBreak)
}) {
report_builder = report_builder.with_label(
Label::new((&filename, token.span.into()))
.with_message(format!("[{}, {})", token.span.start, token.span.end))
Expand Down

0 comments on commit 153c17a

Please sign in to comment.