diff --git a/include/tree_sitter/runtime.h b/include/tree_sitter/runtime.h index 6a3d5a36..502ffd4b 100644 --- a/include/tree_sitter/runtime.h +++ b/include/tree_sitter/runtime.h @@ -47,6 +47,7 @@ void ts_document_set_language(TSDocument *, const TSLanguage *); void ts_document_set_input(TSDocument *, TSInput); void ts_document_set_input_string(TSDocument *, const char *); void ts_document_edit(TSDocument *, TSInputEdit); +void ts_document_set_debug(TSDocument *, int); TSNode *ts_document_root_node(const TSDocument *); #define ts_builtin_sym_error 0 diff --git a/spec/runtime/document_spec.cc b/spec/runtime/document_spec.cc index ec970c49..299a47a3 100644 --- a/spec/runtime/document_spec.cc +++ b/spec/runtime/document_spec.cc @@ -291,6 +291,7 @@ describe("Document", [&]() { describe("when the error is an empty string", [&]() { it("computes the error node's size and position correctly", [&]() { ts_document_set_input_string(doc, " [123, , true]"); + AssertThat(ts_node_string(ts_document_root_node(doc)), Equals( "(DOCUMENT (array (number) (ERROR ',') (true)))")); diff --git a/src/runtime/document.c b/src/runtime/document.c index 8712c3aa..b0db7a1f 100644 --- a/src/runtime/document.c +++ b/src/runtime/document.c @@ -7,6 +7,7 @@ struct TSDocument { TSParser parser; TSInput input; TSNode *node; + int debug; }; TSDocument *ts_document_make() { return calloc(sizeof(TSDocument), 1); } @@ -35,9 +36,15 @@ void ts_document_set_language(TSDocument *document, const TSLanguage *language) { ts_parser_destroy(&document->parser); document->parser = ts_parser_make(language); + document->parser.debug = document->debug; reparse(document, NULL); } +void ts_document_set_debug(TSDocument *document, int debug) { + document->debug = debug; + document->parser.debug = debug; +} + void ts_document_set_input(TSDocument *document, TSInput input) { document->input = input; reparse(document, NULL);