update set_included_ranges to modify extent if the current position is at the very beginning of the included range

This commit is contained in:
Cameron Forbis 2021-06-17 16:42:25 -07:00
parent 0fea8c02ee
commit 9182ebef86
2 changed files with 43 additions and 1 deletions

View file

@ -872,6 +872,48 @@ fn test_parsing_with_multiple_included_ranges() {
);
}
#[test]
fn test_parsing_with_included_range_at_the_beginning_of_file() {
let source_code = "<div>test</div>{_ignore_this_part_}";
let mut parser = Parser::new();
parser.set_language(get_language("html")).unwrap();
let end_byte = source_code.find("{_ignore_this_part_").unwrap();
let range_to_parse = Range {
start_byte: 0,
start_point: Point {
row: 10,
column: 12,
},
end_byte,
end_point: Point {
row: 10,
column: 12 + end_byte,
},
};
parser.set_included_ranges(&[range_to_parse]).unwrap();
let mut callback = |offset, _point| {
if offset == 0 {
source_code.as_bytes()
} else {
&[]
}
};
let html_tree = parser.parse_with(&mut callback, None).unwrap();
assert_eq!(html_tree.root_node().range(), range_to_parse,);
assert_eq!(
html_tree.root_node().to_sexp(),
"(fragment (element (start_tag (tag_name)) (text) (end_tag (tag_name))))"
);
}
#[test]
fn test_parsing_error_in_invalid_included_ranges() {
let mut parser = Parser::new();

View file

@ -110,7 +110,7 @@ static void ts_lexer_goto(Lexer *self, Length position) {
for (unsigned i = 0; i < self->included_range_count; i++) {
TSRange *included_range = &self->included_ranges[i];
if (included_range->end_byte > position.bytes) {
if (included_range->start_byte > position.bytes) {
if (included_range->start_byte >= position.bytes) {
self->current_position = (Length) {
.bytes = included_range->start_byte,
.extent = included_range->start_point,