Skip to content

Commit 2ee7ae2

Browse files
committed
Fix end coverage of chunks
1 parent 87d389e commit 2ee7ae2

4 files changed

+4
-33
lines changed

crates/ark/src/lsp/folding_range.rs

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ fn parse_ts_node(
125125
}
126126
// End of node handling
127127
end_node_handler(
128-
document,
129128
folding_ranges,
130129
end.row + 1,
131130
&mut child_comment_stack,
@@ -214,15 +213,6 @@ fn get_line_text(
214213
line[start_idx..end_idx].to_string()
215214
}
216215

217-
fn find_last_non_empty_line(document: &Document, start_line: usize, end_line: usize) -> usize {
218-
for idx in (start_line..=end_line).rev() {
219-
if !get_line_text(document, idx, None, None).trim().is_empty() {
220-
return idx;
221-
}
222-
}
223-
start_line
224-
}
225-
226216
fn count_leading_whitespaces(document: &Document, line_num: usize) -> usize {
227217
let line_text = get_line_text(document, line_num, None, None);
228218
line_text.chars().take_while(|c| c.is_whitespace()).count()
@@ -371,7 +361,6 @@ fn cell_processor(
371361
}
372362

373363
fn end_node_handler(
374-
document: &Document,
375364
folding_ranges: &mut Vec<FoldingRange>,
376365
line_idx: usize,
377366
comment_stack: &mut Vec<Vec<(usize, usize)>>,
@@ -402,10 +391,7 @@ fn end_node_handler(
402391
// End cell Handling
403392
if let Some(cell_start) = cell_marker {
404393
// For the last cell, include the current line in the folding range
405-
let folding_range = comment_range(
406-
*cell_start,
407-
find_last_non_empty_line(document, *cell_start, line_idx),
408-
);
394+
let folding_range = comment_range(*cell_start, line_idx - 1);
409395
folding_ranges.push(folding_range);
410396
*cell_marker = None;
411397
}
@@ -776,21 +762,6 @@ function() {
776762
}
777763
}
778764

779-
// Test for correct last non-empty line detection
780-
#[test]
781-
fn test_find_last_non_empty_line() {
782-
let doc = Document::new("\nline1\nline2\n\nline3\n", None);
783-
784-
assert_eq!(find_last_non_empty_line(&doc, 1, 5), 4);
785-
assert_eq!(find_last_non_empty_line(&doc, 1, 2), 2);
786-
assert_eq!(find_last_non_empty_line(&doc, 3, 5), 4);
787-
assert_eq!(find_last_non_empty_line(&doc, 5, 5), 5);
788-
789-
// Test with empty document
790-
let empty_doc = Document::new("\n\n", None);
791-
assert_eq!(find_last_non_empty_line(&empty_doc, 1, 2), 1);
792-
}
793-
794765
// Test for whitespace counting
795766
#[test]
796767
fn test_count_leading_whitespaces() {

crates/ark/src/lsp/snapshots/ark__lsp__folding_range__tests__folding_section_chunks_with_section_in_middle.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ expression: "test_folding_range(\"\n#+ Cell\na\n\n# Section ----\nb\n\n#+ Other
2626
FoldingRange {
2727
start_line: 7,
2828
start_character: None,
29-
end_line: 8,
29+
end_line: 9,
3030
end_character: None,
3131
kind: Some(
3232
Region,

crates/ark/src/lsp/snapshots/ark__lsp__folding_range__tests__folding_section_chunks_with_sections.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ expression: "test_folding_range(\"\n# Section ----\na\n\n#+ Cell\nb\n\n# Section
3636
FoldingRange {
3737
start_line: 10,
3838
start_character: None,
39-
end_line: 11,
39+
end_line: 12,
4040
end_character: None,
4141
kind: Some(
4242
Region,

crates/ark/src/lsp/snapshots/ark__lsp__folding_range__tests__folding_section_comments_basic.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ expression: "test_folding_range(\"\n# First section ----\na\nb\n\n# Second secti
3636
FoldingRange {
3737
start_line: 13,
3838
start_character: None,
39-
end_line: 16,
39+
end_line: 17,
4040
end_character: None,
4141
kind: Some(
4242
Region,

0 commit comments

Comments
 (0)