Skip to content

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

fix: issue #96

Elijah Potter8eac6bcf08d9
diff --git a/harper-comments/src/tree_sitter_parser.rs b/harper-comments/src/tree_sitter_parser.rs
index d1354c351..926a02c64 100644
--- a/harper-comments/src/tree_sitter_parser.rs
+++ b/harper-comments/src/tree_sitter_parser.rs
@@ -162,7 +162,9 @@ impl Parser for TreeSitterParser {
let mut tokens = Vec::new();
- for span in comments_spans.iter() {
+ let mut span_iter = comments_spans.iter().peekable();
+
+ while let Some(span) = span_iter.next() {
let mut new_tokens = self.comment_parser.parse(span.get_content(source));
new_tokens
@@ -181,9 +183,18 @@ impl Parser for TreeSitterParser {
// Insert a newline manually since we didn't pass the last one (if it existed)
// to the comment parser.
if let Some(last) = tokens.last() {
+ let is_terminating = if let Some(next_span) = span_iter.peek() {
+ Span::new(last.span.end, next_span.start)
+ .get_content(source)
+ .iter()
+ .any(|c| !c.is_whitespace())
+ } else {
+ false
+ };
+
tokens.push(Token::new(
Span::new_with_len(last.span.end, 1),
- TokenKind::Newline(1)
+ TokenKind::Newline(if is_terminating { 2 } else { 1 })
));
}
}
diff --git a/harper-comments/tests/language_support.rs b/harper-comments/tests/language_support.rs
index 0810a2d1c..180a864f6 100644
--- a/harper-comments/tests/language_support.rs
+++ b/harper-comments/tests/language_support.rs
@@ -39,3 +39,4 @@ create_test!(multiline_comments.cpp, 3);
create_test!(multiline_comments.ts, 3);
create_test!(clean.rs, 0);
create_test!(jsdoc.ts, 2);
+create_test!(issue_96.lua, 0);
diff --git a/harper-comments/tests/language_support_sources/issue_96.lua b/harper-comments/tests/language_support_sources/issue_96.lua
new file mode 100644
index 000000000..58da089b0
--- /dev/null
+++ b/harper-comments/tests/language_support_sources/issue_96.lua
@@ -0,0 +1,15 @@
+-- Below, we have situation where the line terminates and should end the sentence.
+
+local alphabet = {
+ [1] = "a", -- This is a test
+ [2] = "b", -- This is a test
+ [3] = "c", -- This is a test
+ [4] = "d", -- This is a test
+ [5] = "e", -- This is a test
+ [6] = "f", -- This is a test
+ [7] = "g", -- This is a test
+ [8] = "h", -- This is a test
+ [9] = "i", -- This is a test
+ [10] = "j", -- This is a test
+ [11] = "k", -- This is a test
+}
diff --git a/harper-comments/tests/language_support_sources/issue_96.rb b/harper-comments/tests/language_support_sources/issue_96.rb
new file mode 100644
index 000000000..d2dbee230
--- /dev/null
+++ b/harper-comments/tests/language_support_sources/issue_96.rb
@@ -0,0 +1,15 @@
+# Below, we have situation where the line terminates and should end the sentence.
+
+alphabet = [
+ "a", # This is a test
+ "b", # This is a test
+ "c", # This is a test
+ "d", # This is a test
+ "e", # This is a test
+ "f", # This is a test
+ "g", # This is a test
+ "h", # This is a test
+ "i", # This is a test
+= "j", # This is a test
+= "k", # This is a test
+]
diff --git a/harper-core/src/char_ext.rs b/harper-core/src/char_ext.rs
index 2d1c7b1ce..1c4110456 100644
--- a/harper-core/src/char_ext.rs
+++ b/harper-core/src/char_ext.rs
@@ -29,7 +29,7 @@ impl CharExt for char {
unicode_blocks::EMOTICONS,
unicode_blocks::MISCELLANEOUS_SYMBOLS,
unicode_blocks::VARIATION_SELECTORS,
- unicode_blocks::SUPPLEMENTAL_SYMBOLS_AND_PICTOGRAPHS,
+ unicode_blocks::SUPPLEMENTAL_SYMBOLS_AND_PICTOGRAPHS
];
blocks.contains(&block)