Integrate help view from vscode-R-help#433
Conversation
|
Regarding the implementation the custom help function in R I am not quite sure what the best solution is. In the normal case there are a number of functions involved when calling e.g. I think the cleanest approach would be to overwrite One problem with this approach might be that the vsc tools are loaded before the utils package and I don't know if loading the package manually (calling |
|
Maybe loading the 'utils' namespace and overwriting In the terminal: local({
ns <- loadNamespace("utils")
search()
# [1] ".GlobalEnv" "Autoloads" "package:base"
unlockBinding("print.help_files_with_topic", ns)
assign(
"print.help_files_with_topic",
function(x, ...) print.default("Ooops"),
envir = ns
)
lockBinding("print.help_files_with_topic", ns)
})
library(utils)
search()
# [1] ".GlobalEnv" "package:utils" "Autoloads" "package:base"
?mean
# [1] "Ooops" |
|
Thanks! That approach seems to work well. I just realized that a very similar function is already used in init.R, I guess we could use that function then. |
|
I tried finding a solution that does not involve modifying the package namespace of .First.sys <- function(){
base::.First.sys()
attach(list(print.help_files_with_topic = function(...) print('Ooops')))
rm('.First.sys', envir=globalenv())
}And checking the print method for help files seems to look good as well: But calling |
|
It looks like this help viewer starts a standalone R session to provide the help files? If one uses |
|
Yep, R is either called to continuously run a help server in the background, or "on demand" to retrieve the libPaths and parse .Rd files. Would it make sense to merge the settings in vscode-r, vscode-r-lsp, and vscode-r-debugger for this? Otherwise the user would have to specify their r path in three different config entries if it's not in a standard place... We could e.g. introduce a setting |
This is because See here for an old but helpful explanation. |
|
That would definitely make sense, if |
|
I think I've finally found a way to make this work: .First.sys <- function(){
base::.First.sys()
attach(list(
print.help_files_with_topic = function(...) print('Ooops')
))
### EDIT:
.S3method <- function(generic, class, method) {
method <- match.fun(method)
registerS3method(generic, class, method, envir = parent.frame())
invisible(NULL)
}
###
.S3method('print', 'help_files_with_topic', print.help_files_with_topic)
rm('.First.sys', envir = globalenv())
}The last call overwrites |
Yeah, this is due to some machinery with S3 method lookup. You are calling the generic first, not your particular custom method implementation. |
Ok, thanks for catching that. |
|
The code now uses javascript's integrated |
|
Thanks for the fix of cross-package hyperlinks. I'm wondering if it is possible that when the link points to a function in another package, if there's only one link, then it should jump directly to that link? |
When viewing the R help in a normal browser, the help server sends a redirect response (HTTP 302) after clicking a cross-package link, but when querying the site from within the extension, the help server returns that "forwarding page" with an Ok response (HTTP 200). The cleanest way to fix this would be to somehow indicate that we also want to receive the redirect response when querying the help site, not sure how this would be done. |
|
Btw, when using |
|
@ManuelHentschel FYI: after your new commits, cross-pkg hyperlinks, DESCRIPTION line breaks, forward/back buttons all work nicely on Linux. |
|
I tried Also, I navigate though different links around and sometimes clicking the "Index" at the bottom of the help page will result in a text page saying "Server error: invalid response from R". Another thing is that if I view |
Yup, the |
I haven't encountered this yet, so if you find a reproducible example, please share :) |
This might be a bit more complicated, since we receive the contents of the pdf file directly from the help server. Hence we do not know the location of these pdf files on disk for sure. We can take a guess using Since most of the documentation is provided as html, I wouldn't consider this a priority right now |
I could reproduce this on both Ubuntu and macOS.
|
Thanks that example works on windows as well. Does the last push fix the issue for you? |
|
It works nicely now. Thanks for the quick fix! |
|
If there aren't any more (known) bugs to fix, I would consider the remaining items on the to-do list "optional" improvements and propose merging the PR. |
renkun-ken
left a comment
There was a problem hiding this comment.
LGTM. Thanks for the great work!
I believe this PR is ok for merge. For the remaining items, we could always improve later.
@Ikuyadeu Any more comments?
|
LGTM, it is great. @ManuelHentschel If you have an interest in this extension, I want to invite you as a collaborator. |
Thanks! I'm definitely interested in this extension and would be happy to help where I can :) |
As mentioned in #432 I tried to integrate vscode-R-help here.
The main functionality seems to be working, simply use
help(...)in an R Terminal (opened by the extension!), or the commandsr.showHelp,r.showDocin VS Code's command palette.Here it can be configured, whether to look for help files using a custom function or to look for help files by querying an R instance running
help.start(). These should mostly behave the same, but there are different problems/difficulties with each, which need to be figured out.Remaining issues/questions include:
help(), since the tools from the extension are attached beforeutils(Implemented as proposed here)'Rserver'as helpProviderbase::colSums->complete.cases)doc/html/index.html)r.showHelp: implement fuzzy matching, autocomplete, simulation of?from command palette???I just added the code to get things to work, feel free to rearrange/reformat/rename to better match the rest of the project.
If you have suggestions, questions, comments, or find bugs, please let me know. All feedback or code contributions are welcome :)