Skip to content

Commit

Permalink
fix: issue #96
Browse files Browse the repository at this point in the history
  • Loading branch information
elijah-potter committed Jul 6, 2024
1 parent 080dc40 commit 8eac6bc
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 3 deletions.
15 changes: 13 additions & 2 deletions harper-comments/src/tree_sitter_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 })
));
}
}
Expand Down
1 change: 1 addition & 0 deletions harper-comments/tests/language_support.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
15 changes: 15 additions & 0 deletions harper-comments/tests/language_support_sources/issue_96.lua
Original file line number Diff line number Diff line change
@@ -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
}
15 changes: 15 additions & 0 deletions harper-comments/tests/language_support_sources/issue_96.rb
Original file line number Diff line number Diff line change
@@ -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
]
2 changes: 1 addition & 1 deletion harper-core/src/char_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 8eac6bc

Please sign in to comment.