Skip to content

Auto-refresh help topics #854

@renkun-ken

Description

@renkun-ken

Currently, it looks like help topics could be properly shown if getAliases.R is run with the latest installed packages.

As reported in #661, #853, if a new package is installed but getAliases.R is not run, the cache is out of date and thus both "Open help for selection" and "hover" will not work with the newly installed packages. Manually clicking "Clear Cached Index Files & Restart Help Server" could refresh the aliases but it seems possible to make it more automatic.

@ManuelHentschel what if we make some changes to helpServer.R to periodically detect changes of installed packages and write the aliases json once there are changes, and getAliases.R will be no longer needed.

# get values from extension-set env values
lim <- Sys.getenv("VSCR_LIM")

cat(
    lim,
    tools::startDynamicHelp(),
    lim,
    sep = ""
)

pkgs <- character()
while (TRUE) {
    cur_pkgs <- .packages(all.available = TRUE)
    if (!identical(pkgs, cur_pkgs)) {
        ip <- installed.packages()

        ord <- order(ip[, "Priority"])
        ip <- ip[ord, c("LibPath", "Package")]

        ret <- lapply(rownames(ip), function(row) {
            libPath <- ip[row, "LibPath"]
            pkg <- ip[row, "Package"]
            filename <- file.path(libPath, pkg, "help", "aliases.rds")
            info <- list(
                package = pkg,
                libPath = libPath,
                aliasFile = filename,
                aliases = NULL
            )
            if (file.exists(filename)) {
                info[["aliases"]] <- as.list(readRDS(filename))
            }
            info
        })
        names(ret) <- rownames(ip)
        json <- jsonlite::toJSON(ret, auto_unbox = TRUE)
        cat(lim, json, lim, "\n", sep = "")
        pkgs <- cur_pkgs
    }
    Sys.sleep(1)
}

Whenever a new package installed, the latest aliases will be written to stdout, or otherwise it is checking every second, which should not be expensive.

And the help manager should handle both output accordingly. One is help server port message, and the other is aliases json message.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions