diff --git a/spec/runtime/document_spec.cc b/spec/runtime/document_spec.cc index c3df9651..033f3b54 100644 --- a/spec/runtime/document_spec.cc +++ b/spec/runtime/document_spec.cc @@ -131,6 +131,26 @@ describe("Document", [&]() { }); }); + describe("editing text inside a node containing a ubiquitous token", [&]() { + before_each([&]() { + ts_document_set_language(doc, ts_language_javascript()); + + delete reader; + reader = new SpyReader("{\nx;\n}", 3); + + ts_document_set_input(doc, reader->input); + AssertThat(string(ts_node_string(ts_document_root_node(doc))), Equals( + "(DOCUMENT (program (statement_block (expression_statement (identifier)))))")); + + }); + + it("updates the parse tree", [&]() { + insert_text(strlen("{\nx"), "y"); + AssertThat(string(ts_node_string(ts_document_root_node(doc))), Equals( + "(DOCUMENT (program (statement_block (expression_statement (identifier)))))")); + }); + }); + describe("deleting an important part of a token", [&]() { it("updates the parse tree, creating an error", [&]() { delete_text(strlen("{ \"key"), 1); diff --git a/src/runtime/parser.c b/src/runtime/parser.c index ed5a3093..8a55cf63 100644 --- a/src/runtime/parser.c +++ b/src/runtime/parser.c @@ -44,8 +44,10 @@ static size_t breakdown_stack(TSParser *parser, TSInputEdit *edit) { for (size_t i = 0; i < child_count && position < edit->position; i++) { TSTree *child = children[i]; TSStateId state = ts_stack_top_state(stack); - TSStateId next_state = - action_for(parser->language, state, child->symbol).data.to_state; + TSParseAction action = action_for(parser->language, state, child->symbol); + TSStateId next_state = action.type == TSParseActionTypeShift ? + action.data.to_state : + state; ts_stack_push(stack, next_state, child); ts_tree_retain(child); position += ts_tree_total_size(child);