diff --git a/NAMESPACE b/NAMESPACE index 9abe891..bacd0fd 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -16,6 +16,7 @@ export(.vsc.preBreakpoint) export(.vsc.preDebugSourceBreakpoint) export(.vsc.print) export(.vsc.print.help_files_with_topic) +export(.vsc.print.hsearch) export(.vsc.refreshBreakpoints) export(.vsc.str) useDynLib(vscDebugger,c_get_ppid) diff --git a/R/defaultVarInfo.R b/R/defaultVarInfo.R index 297cc2f..8727527 100644 --- a/R/defaultVarInfo.R +++ b/R/defaultVarInfo.R @@ -78,6 +78,7 @@ getDefaultVarInfos <- function() { name = '.Random.seed', doesApply = function(v) !is.null(v) && identical(v, get0(".Random.seed", globalenv())), childVars = list(), + evaluateName = '.Random.seed', nChildVars = 0 ), # R6 (TODO: display public/private properties etc.) diff --git a/R/evaluate.R b/R/evaluate.R index 3672ecf..1e46293 100644 --- a/R/evaluate.R +++ b/R/evaluate.R @@ -53,7 +53,10 @@ evaluateRequest <- function(response, args, request){ if( valueAndVisible$visible && context != 'watch' - && identical(class(valueAndVisible$value), 'help_files_with_topic') + && ( + identical(class(valueAndVisible$value), 'help_files_with_topic') + || identical(class(valueAndVisible$value), 'hsearch') + ) ){ valueAndVisible$visible <- FALSE base::print(valueAndVisible$value) diff --git a/R/flow.R b/R/flow.R index 0d6b53d..896b533 100644 --- a/R/flow.R +++ b/R/flow.R @@ -242,6 +242,13 @@ sessionFinalizer <- function(...){ session$print_help_files_with_topic_0 ))) } + if(session$supportsHelpViewer && !is.null(session$print_hsearch_0)){ + try(suppressWarnings(.S3method( + "print", + "hsearch", + session$print_hsearch_0 + ))) + } try(detach(session$rStrings$attachName, character.only = TRUE), silent = TRUE) try(sendExitedEvent(), silent = TRUE) try(sendTerminatedEvent(), silent = TRUE) diff --git a/R/getStack.R b/R/getStack.R index 8e5eb79..2fc640a 100644 --- a/R/getStack.R +++ b/R/getStack.R @@ -38,7 +38,7 @@ stackTraceRequest <- function(response, args, request){ # return: response[['body']] <- list( stackFrames = stackFrames, - totalFrames = length(frameIdsR) + totalFrames = max(length(frameIdsR), 1) ) sendResponse(response) } diff --git a/R/global.R b/R/global.R index 08bbec0..7d262c7 100644 --- a/R/global.R +++ b/R/global.R @@ -1,3 +1,21 @@ + + + + +#' vscDebugger +#' +#' Implementation of the Debug Adapter Protocol for R +#' +#' @docType package +#' @name vscDebugger-package +#' +#' @aliases vscDebugger2 +#' +NULL + + + + # create environment for global data used by package functions session <- local({ # settings: @@ -94,6 +112,7 @@ session <- local({ sourceBreakpointsList <- list() sources <- list() print_help_files_with_topic_0 <- NULL + print_hsearch_0 <- NULL breakpointEnvironments <- list() diff --git a/R/launch.R b/R/launch.R index 8386657..0f59800 100644 --- a/R/launch.R +++ b/R/launch.R @@ -318,6 +318,12 @@ configurationDoneRequest <- function(response, args, request){ "help_files_with_topic", .vsc.print.help_files_with_topic )) + session$print_hsearch_0 <- getS3method('print', 'hsearch') + suppressWarnings(.S3method( + "print", + "hsearch", + .vsc.print.hsearch + )) } # disable just-in-time compilation (messes with source info etc.) diff --git a/R/overwrites.R b/R/overwrites.R index a9afb10..5c85274 100644 --- a/R/overwrites.R +++ b/R/overwrites.R @@ -165,8 +165,8 @@ printToVsc <- function(ret, skipCalls=0, category="stdout", showSource=TRUE){ #' @export .vsc.print.help_files_with_topic <- function(h, ...) { - success <- FALSE - if (length(h) >= 1 && is.character(h)) { + viewer <- getOption("vsc.helpPanel", "Two") + if (!identical(FALSE, viewer) && length(h) >= 1 && is.character(h)) { file <- h[1] path <- dirname(file) dirpath <- dirname(path) @@ -178,12 +178,54 @@ printToVsc <- function(ret, skipCalls=0, category="stdout", showSource=TRUE){ basename(file), ".html" ) - success <- sendCustomEvent('viewHelp', list(requestPath = requestPath)) + success <- sendCustomEvent('viewHelp', list(requestPath = requestPath, viewer = viewer)) + } else{ + utils:::print.help_files_with_topic(h, ...) } invisible(h) } +#' @export +.vsc.print.hsearch <- function(x, ...){ + viewer <- getOption("vsc.helpPanel", "Two") + if (!identical(FALSE, viewer) && length(x) >= 1) { + requestPath <- paste0( + "/doc/html/Search?pattern=", + tools:::escapeAmpersand(x$pattern), + paste0("&fields.", x$fields, "=1", + collapse = "" + ), + if (!is.null(x$agrep)) paste0("&agrep=", x$agrep), + if (!x$ignore.case) "&ignore.case=0", + if (!identical( + x$types, + getOption("help.search.types") + )) { + paste0("&types.", x$types, "=1", + collapse = "" + ) + }, + if (!is.null(x$package)) { + paste0( + "&package=", + paste(x$package, collapse = ";") + ) + }, + if (!identical(x$lib.loc, .libPaths())) { + paste0( + "&lib.loc=", + paste(x$lib.loc, collapse = ";") + ) + } + ) + success <- sendCustomEvent('viewHelp', list(requestPath = requestPath, viewer = viewer)) + } else{ + utils:::print.hsearch(x, ...) + } + invisible(x) +} + #' Refresh Breakpoints #' #' Refresh breakpoints known to the debugger diff --git a/d.ts/global.d.ts b/d.ts/global.d.ts index c051445..3d31b20 100644 --- a/d.ts/global.d.ts +++ b/d.ts/global.d.ts @@ -120,6 +120,7 @@ export interface Session { sourceBreakpointsList: Breakpoints.SourceBreakpoints[]; sources: InternalSource[]; print_help_files_with_topic_0: RFunction | null; + print_hsearch_0: RFunction | null; breakpointEnvironments: REnvironment[]; } diff --git a/man/vscDebugger-package.Rd b/man/vscDebugger-package.Rd new file mode 100644 index 0000000..d0c51ec --- /dev/null +++ b/man/vscDebugger-package.Rd @@ -0,0 +1,10 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/global.R +\docType{package} +\name{vscDebugger-package} +\alias{vscDebugger-package} +\alias{vscDebugger2} +\title{vscDebugger} +\description{ +Implementation of the Debug Adapter Protocol for R +}