Offline, privacy-first grammar checker. Fast, open-source, Rust-powered
fix: only condense adjacent spaces
Grant Lemons1d0b9728875b
diff --git a/harper-core/src/document.rs b/harper-core/src/document.rsindex c6adce902..80e7f2b05 100644--- a/harper-core/src/document.rs+++ b/harper-core/src/document.rs@@ -284,11 +284,17 @@ impl Document {}let child_tok = ©[cursor];- if let TokenKind::Space(n) = child_tok.kind {- *start_count += n;- start_tok.span.end = child_tok.span.end;- remove_these.push_back(cursor);- cursor += 1;++ // Only condense adjacent spans+ if start_tok.span.end == child_tok.span.start {+ if let TokenKind::Space(n) = child_tok.kind {+ *start_count += n;+ start_tok.span.end = child_tok.span.end;+ remove_these.push_back(cursor);+ cursor += 1;+ } else {+ break;+ }} else {break;};diff --git a/harper-core/src/parsers/typst.rs b/harper-core/src/parsers/typst.rsindex 0a8efce45..a58f89d8c 100644--- a/harper-core/src/parsers/typst.rs+++ b/harper-core/src/parsers/typst.rs@@ -274,10 +274,11 @@ impl<'a> ParseHelper<'a> {}Expr::Str(text) => {let offset = offset.push_to_span(text.span()).char + 1;- let text = text.to_untyped().text().to_string();+ let string = text.to_untyped().text().to_string();+Some(self.parser- .parse_str(&text[1..text.len() - 1])+ .parse_str(&string[1..string.len() - 1]).into_iter().map(|mut t| {t.span.push_by(offset);@@ -562,6 +563,29 @@ mod tests {))}+ #[test]+ fn non_adjacent_spaces_not_condensed() {+ let source = r#"#authors_slice.join(", ", last: ", and ") "#;++ let token_kinds = Typst.parse_str(source).iter().map(|t| t.kind).collect_vec();+ dbg!(&token_kinds);++ assert!(matches!(+ &token_kinds.as_slice(),+ &[+ TokenKind::Unlintable, // authors_slice.join+ TokenKind::Punctuation(Punctuation::Comma),+ TokenKind::Space(1),+ TokenKind::Unlintable, // Ident+ TokenKind::Punctuation(Punctuation::Comma),+ TokenKind::Space(1),+ TokenKind::Word(_), // and+ TokenKind::Space(1),+ TokenKind::Space(1)+ ]+ ))+ }+#[test]fn header_parsing() {let source = r"= Header