-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Completion] Configurable Completers
Improve configurability of completers: 1. Completers can be selectively enabled and disabled. `snippet` and `keywords` completers source completions from Ace's language mode definition. `text` completer completes with local words. 1. R language completer now receives full text in addition to the current line buffer due to full text lags due to debouncing. 1. R language completer now provides full completion object such that fields can be customized: name, value, description and meta.
- Loading branch information
Forest Fang
committed
Apr 5, 2018
1 parent
d04ae51
commit e0a06b4
Showing
5 changed files
with
92 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,40 @@ | ||
#' Enable Code Completion for an Ace Code Input | ||
#' | ||
#' | ||
#' This function dynamically auto complete R code pieces using built-in function | ||
#' \code{utils:::.win32consoleCompletion}. Please see \code{\link[utils]{rcompgen}} for details. | ||
#' | ||
#' | ||
#' @details | ||
#' You can implement your own code completer by listening to \code{input$shinyAce_<editorId>_hint} | ||
#' where <editorId> is the \code{aceEditor} id. The input contains | ||
#' \itemize{ | ||
#' \item \code{linebuffer}: Code/Text at current editing line | ||
#' \item \code{cursorPosition}: Current cursor position at this line | ||
#' } | ||
#' | ||
#' | ||
#' @param inputId The id of the input object | ||
#' @param session The \code{session} object passed to function given to shinyServer | ||
#' @return An observer reference class object that is responsible for offering code completion. | ||
#' See \code{\link[shiny]{observe}} for more details. You can use \code{suspend} or \code{destroy} | ||
#' to pause to stop dynamic code completion. | ||
#' @export | ||
#' @export | ||
aceAutocomplete <- function(inputId, session = shiny::getDefaultReactiveDomain()) { | ||
shiny::observe({ | ||
value <- session$input[[paste0("shinyAce_", inputId, "_hint")]] | ||
if(is.null(value)) return(NULL) | ||
if (is.null(value)) return(NULL) | ||
|
||
utilEnv <- environment(utils::alarm) | ||
w32 <- get(".win32consoleCompletion", utilEnv) | ||
|
||
comps <- list(id = inputId, | ||
codeCompletions = w32(value$linebuffer, value$cursorPosition)$comps) | ||
|
||
codeCompletions <- w32(value$linebuffer, value$cursorPosition$col)$comps | ||
codeCompletions <- strsplit(codeCompletions, " ", fixed = TRUE)[[1]] | ||
codeCompletions <- lapply(codeCompletions, function(completion) { | ||
list(name = completion, value = completion, meta = "R") | ||
}) | ||
|
||
comps <- list( | ||
id = inputId, | ||
codeCompletions = jsonlite::toJSON(codeCompletions, auto_unbox = TRUE) | ||
) | ||
|
||
session$sendCustomMessage('shinyAce', comps) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters