Skip to content

Commit

Permalink
minimal viable addin
Browse files Browse the repository at this point in the history
registration and keybindings are as in clipal, related to simonpcouch#6
  • Loading branch information
simonpcouch committed Oct 4, 2024
1 parent 992f525 commit 7022723
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 24 deletions.
24 changes: 13 additions & 11 deletions R/addin.R
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
rs_update_selection <- function(
context = rstudioapi::getActiveDocumentContext(),
id = "cli"
) {
rs_update_selection <- function(context, role) {
# see if the user has run `pal()` successfully already
if (exists(paste0(".last_pal_", id))) {
pal <- get(paste0(".last_pal_", id))
} else if (exists(".last_pal")) {
pal <- .last_pal
if (exists(paste0(".last_pal_", role))) {
pal <- get(paste0(".last_pal_", role))
} else {
tryCatch(
pal <- pal(id),
pal <- pal(role),
error = function(e) {
rstudioapi::showDialog("Error", "Unable to create a pal. See `?pal()`.")
}
Expand All @@ -25,8 +20,7 @@ rs_update_selection <- function(
}

tryCatch({
output_str <- pal_chat(selection_text, pal)
output_str <- rlang::call2(.pal)
output_str <- .pal_chat(pal, selection_text)

rstudioapi::modifyRange(
selection$range,
Expand All @@ -41,3 +35,11 @@ rs_update_selection <- function(
rstudioapi::showDialog("Error", paste("The pal ran into an issue: ", e$message))
})
}

rs_pal_cli <- function(context = rstudioapi::getActiveDocumentContext()) {
rs_update_selection(context = context, role = "cli")
}

rs_pal_testthat <- function(context = rstudioapi::getActiveDocumentContext()) {
rs_update_selection(context = context, role = "testthat")
}
7 changes: 6 additions & 1 deletion inst/rstudio/addins.dcf
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
Name: Convert to cli
Description: Replaces selected erroring code with a version adapted to cli
Binding: rs_.pal_cli
Binding: rs_pal_cli
Interactive: false

Name: Convert to testthat
Description: Replaces selected unit testing code with a version adapted to testthat 3
Binding: rs_pal_testthat
Interactive: false
33 changes: 21 additions & 12 deletions man/pal_cli.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7022723

Please sign in to comment.