DavisVaughan / r-tree-sitter

https://davisvaughan.github.io/r-tree-sitter/
Other
31 stars 2 forks source link

Set `text` in a tree to `NULL` after a `tree_edit()` #8

Closed DavisVaughan closed 4 months ago

DavisVaughan commented 5 months ago

Editing the tree bounds results in altered start/stop bounds that no longer match the text, so we should unset the text field and have special support in the print method for this case.

We should also add checks in some of the tree_ functions to check if we have valid text or not before proceeding.

This should be easier now because trees are immutable, so we don't need to worry about modifying a tree that has state that is also captured inside of an existing node

Run this and try and print out tree, it will error right now

#' language <- treesitter.r::language()
#' parser <- parser(language)
#'
#' text <- "1 + foo"
#' tree <- parser_parse(parser, text)
#' tree
#'
#' text <- "1 + bar(foo)"
#' tree <- tree_edit(
#'   tree,
#'   start_byte = 4,
#'   start_point = point(0, 4),
#'   old_end_byte = 7,
#'   old_end_point = point(0, 7),
#'   new_end_byte = 12,
#'   new_end_point = point(0, 12)
#' )