Skip to content

Commit

Permalink
fix(fuzzyhelp): broken addin
Browse files Browse the repository at this point in the history
  • Loading branch information
atusy committed Mar 28, 2024
1 parent a237c82 commit d6a479f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
21 changes: 16 additions & 5 deletions R/fuzzyhelp.R
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ create_server <- function(method = c("fzf", "lv")) {
#' @param background Whether to run a shiny gadget in a background process.
#' The default value is `TRUE` and can be changed by
#' `option(fuzzyhelp.background = FALSE)`.
#' @inheritParams shiny::runGadget
#'
#' @note
#' The default fuzzy match algorithm is a simplified version of
Expand All @@ -397,13 +398,14 @@ create_server <- function(method = c("fzf", "lv")) {
fuzzyhelp <- function(
query = "",
method = getOption("fuzzyhelp.method", "fzf"),
background = getOption("fuzzyhelp.background", TRUE)) {
background = getOption("fuzzyhelp.background", TRUE),
viewer = shiny::paneViewer()) {
app <- create_ui(query)
server <- create_server(method)

# Create new gadget on foreground
if (!background) {
shiny::runGadget(app, server)
shiny::runGadget(app, server, viewer = viewer)
return(invisible(NULL))
}

Expand All @@ -427,17 +429,26 @@ fuzzyhelp <- function(

# Create new gadget on background
.env$fuzzyhelp <- callr::r_bg(
function(..., .env) {
function(..., .env, base_viewer) {
viewer <- function(url) {
writeLines(url, .env$fuzzyhelp_url)
shiny::paneViewer()(url)
base_viewer(url)
}
shiny::runGadget(..., viewer = viewer)
},
args = list(app = app, server = server, .env = .env),
args = list(app = app, server = server, .env = .env, base_viewer = viewer),
env = Sys.getenv(),
package = TRUE
)

return(.env$fuzzyhelp)
}

fuzzyhelp_addin <- function() {
script <- tempfile()
writeLines(
"felp::fuzzyhelp(background = FALSE, viewer = rstudioapi::viewer)",
script
)
rstudioapi::jobRunScript(script, name = "fuzzyhelp")
}
2 changes: 1 addition & 1 deletion inst/rstudio/addins.dcf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Name: Fuzzy Search on R Help
Description: Search and view help files with fuzzy queries.
Binding: fuzzyhelp
Binding: fuzzyhelp_addin
Interactive: true
7 changes: 6 additions & 1 deletion man/fuzzyhelp.Rd

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

0 comments on commit d6a479f

Please sign in to comment.