Skip to content

Commit

Permalink
add function signatures to box-attached functions
Browse files Browse the repository at this point in the history
  • Loading branch information
radbasa committed Aug 13, 2024
1 parent 3000e3e commit d28e338
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: box.lsp
Title: What the Package Does (One Line, Title Case)
Version: 0.0.0.9003
Version: 0.0.0.9004
Authors@R:
c(
person("Ricardo Rodrigo", "Basa", role = c("aut", "cre"), email = "[email protected]"),
Expand Down
13 changes: 11 additions & 2 deletions R/box_lsp.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,20 @@ box_use_parser <- function(expr, action) {
# nolint start
# action$assign(symbol = names(x) %>% purrr::keep(~. != ""), value = NULL)
# nolint end

# for box::use(dplyr[a, b, c])
lapply(as.character(x)[-c(1, 2)], function(y) {
if (y != "...") {
action$assign(symbol = as.character(y), value = NULL)
namespaced_function <- paste0(as.character(x[[2]]), "::", as.character(y))

tmp_name <- "temp_func"
signature <- deparse(eval(parse(text = namespaced_function, keep.source = TRUE)))[[1]]
empty <- "{ }"
tmp_sig <- paste(tmp_name, "<-", signature, empty)
func_sig <- parse(text = tmp_sig, keep.source = TRUE)[[1]]


action$assign(symbol = as.character(y), value = func_sig[[3L]])
action$parse(func_sig[[3L]])
}
})

Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,15 @@ action <- list(
},
update = function(packages) {
cat(paste("Packages: ", packages, "\n"))
},
parse = function(expr) {
cat(paste("Parse: ", expr, "\n"))
}
)

content <- c("box::use(stringr, dplyr[alias = filter, mutate], xml2[...])", "filt", "stringr$str_c")
expr <- parse(text = content, keep.source = TRUE)
box_use_parser(expr, action)
box_use_parser(expr[[1]], action)
```

### Dev work on completion
Expand Down

0 comments on commit d28e338

Please sign in to comment.