diff --git a/spec/runtime/tree_spec.cc b/spec/runtime/tree_spec.cc index 5372b704..485352bc 100644 --- a/spec/runtime/tree_spec.cc +++ b/spec/runtime/tree_spec.cc @@ -91,10 +91,7 @@ describe("Tree", []() { AssertThat(children[0].offset.chars, Equals(0)); AssertThat(children[1].tree, Equals(tree2)); - AssertThat(children[1].offset.bytes, Equals( - tree1->size.bytes + tree2->padding.bytes)); - AssertThat(children[1].offset.chars, Equals( - tree1->size.chars + tree2->padding.chars)); + AssertThat(children[1].offset, Equals(ts_tree_total_size(tree1))); }); describe("when one of the child nodes is hidden", [&]() { @@ -128,16 +125,10 @@ describe("Tree", []() { AssertThat(children[0].offset.chars, Equals(0)); AssertThat(children[1].tree, Equals(tree2)); - AssertThat(children[1].offset.bytes, Equals( - tree1->size.bytes + tree2->padding.bytes)); - AssertThat(children[1].offset.chars, Equals( - tree1->size.chars + tree2->padding.chars)); + AssertThat(children[1].offset, Equals(ts_tree_total_size(tree1))); AssertThat(children[2].tree, Equals(tree3)); - AssertThat(children[2].offset.bytes, Equals( - tree1->size.bytes + tree2->padding.bytes + tree2->size.bytes + tree3->padding.bytes)); - AssertThat(children[2].offset.chars, Equals( - tree1->size.chars + tree2->padding.chars + tree2->size.chars + tree3->padding.chars)); + AssertThat(children[2].offset, Equals(ts_length_add(ts_tree_total_size(tree1), ts_tree_total_size(tree2)))); }); }); @@ -303,3 +294,7 @@ describe("Tree", []() { }); END_TEST + +bool operator==(TSLength left, TSLength right) { + return ts_length_eq(left, right); +} diff --git a/src/runtime/document.c b/src/runtime/document.c index f8989ef9..6f998fd8 100644 --- a/src/runtime/document.c +++ b/src/runtime/document.c @@ -63,7 +63,7 @@ void ts_document_set_input_string(TSDocument *document, const char *text) { TSNode ts_document_root_node(const TSDocument *document) { if (document->tree) - return ts_node_make(document->tree, document->tree->padding); + return ts_node_make(document->tree, ts_length_zero()); else return ts_node_null(); } diff --git a/src/runtime/node.c b/src/runtime/node.c index 4954cda3..6c38392d 100644 --- a/src/runtime/node.c +++ b/src/runtime/node.c @@ -13,7 +13,7 @@ static inline const TSTree *get_tree(TSNode this) { } TSLength ts_node_pos(TSNode this) { - return this.position; + return ts_length_add(this.position, get_tree(this)->padding); } TSLength ts_node_size(TSNode this) { @@ -41,7 +41,7 @@ typedef struct { static inline NodeWithIndex ts_node_parent_with_index(TSNode this) { const TSTree *tree = get_tree(this); size_t index = 0; - TSLength position = ts_length_sub(this.position, tree->padding); + TSLength position = this.position; do { TSTree *parent = tree->parent; @@ -64,9 +64,7 @@ static inline NodeWithIndex ts_node_parent_with_index(TSNode this) { tree = parent; } while (!ts_tree_is_visible(tree)); - return (NodeWithIndex){ - ts_node_make(tree, ts_length_add(position, tree->padding)), index - }; + return (NodeWithIndex){ ts_node_make(tree, position), index }; } TSNode ts_node_parent(TSNode this) { diff --git a/src/runtime/tree.c b/src/runtime/tree.c index de583265..ba71021b 100644 --- a/src/runtime/tree.c +++ b/src/runtime/tree.c @@ -101,9 +101,6 @@ TSTree *ts_tree_make_node(TSSymbol symbol, size_t child_count, TSTree *child = children[i]; child->parent = result; - if (i > 0) - offset = ts_length_add(offset, child->padding); - if (ts_tree_is_visible(child)) { visible_children[vis_i].tree = child; visible_children[vis_i].offset = offset; @@ -119,7 +116,7 @@ TSTree *ts_tree_make_node(TSSymbol symbol, size_t child_count, } } - offset = ts_length_add(offset, child->size); + offset = ts_length_add(offset, ts_tree_total_size(child)); } return result;