Skip to content

Commit

Permalink
Avoid re-calculation of xml parse data for lsp use (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
dgkf authored Aug 29, 2024
1 parent 82d164e commit 1d4a809
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
20 changes: 17 additions & 3 deletions R/ast.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,33 @@ parse_xml <- function(info) {
read_xml(xml_text)
}

parse_info <- function(file = "", text = NULL, lines = NULL) {
parse_info <- function(file = "", text = NULL, lines = NULL, xml = NULL) {
if (!is_null(text)) {
lines <- as_lines(text)
}
list(
file = file,
lines = lines
lines = lines,
xml = xml
)
}

parse_info_complete <- function(info) {
if (is.null(info$lines)) {
info$lines <- readLines(info$file)
}

if (is.null(info$xml)) {
info$xml <- parse_xml(info)
}

info
}

is_info <- function(x) {
is.list(x) && all(c("file", "lines") %in% names(x))
is.list(x) && all(c("file", "lines", "xml") %in% names(x))
}

check_info <- function(info,
arg = caller_arg(info),
call = caller_env()) {
Expand Down
5 changes: 2 additions & 3 deletions R/reshape.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ can_reshape <- function(data) {
}

reshape_info <- function(line, col, ..., info, to = NULL) {
xml <- parse_xml(info)

call <- find_function_call(line, col, data = xml)
info <- parse_info_complete(info)
call <- find_function_call(line, col, data = info$xml)
if (is_null(call)) {
return()
}
Expand Down

0 comments on commit 1d4a809

Please sign in to comment.