Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix(scanner): keep size of indents consistent #294

Merged
merged 1 commit into from
Jan 7, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/scanner.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ bool tree_sitter_python_external_scanner_scan(void *payload, TSLexer *lexer, con
lexer->mark_end(lexer);

bool found_end_of_line = false;
uint32_t indent_length = 0;
uint16_t indent_length = 0;
int32_t first_comment_indent_length = -1;
for (;;) {
if (lexer->lookahead == '\n') {
Expand Down Expand Up @@ -380,7 +380,9 @@ unsigned tree_sitter_python_external_scanner_serialize(void *payload, char *buff

uint32_t iter = 1;
for (; iter < scanner->indents.size && size < TREE_SITTER_SERIALIZATION_BUFFER_SIZE; ++iter) {
buffer[size++] = (char)*array_get(&scanner->indents, iter);
uint16_t indent_value = *array_get(&scanner->indents, iter);
buffer[size++] = (char)(indent_value & 0xFF);
buffer[size++] = (char)((indent_value >> 8) & 0xFF);
}

return size;
Expand All @@ -406,8 +408,9 @@ void tree_sitter_python_external_scanner_deserialize(void *payload, const char *
size += delimiter_count;
}

for (; size < length; size++) {
array_push(&scanner->indents, (unsigned char)buffer[size]);
for (; size + 1 < length; size += 2) {
uint16_t indent_value = (unsigned char)buffer[size] | ((unsigned char)buffer[size + 1] << 8);
array_push(&scanner->indents, indent_value);
}
}
}
Expand Down
Loading