Skip to content

Commit

Permalink
fix(scanner): keep size of indents consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
amaanq committed Jan 7, 2025
1 parent bffb65a commit b4ba13f
Showing 1 changed file with 7 additions and 4 deletions.
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

0 comments on commit b4ba13f

Please # to comment.