Skip to content

Offline, privacy-first grammar checker. Fast, open-source, Rust-powered

feat(spans-visual): spans visual defaults to hiding newline spans

Grant Lemons153c17a90a59
diff --git a/harper-cli/src/main.rs b/harper-cli/src/main.rs
index 79293ad2e..21655852e 100644
--- a/harper-cli/src/main.rs
+++ b/harper-cli/src/main.rs
@@ -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,
@@ -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;
@@ -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))