Hover code suggestion not work in box and R6 package
Hover suggestion not work in box and R6 package, The example in box package as follows:
'R/run_diff.R' file includes many functions such as calculate_diff, plot_diff and so on. the codes as follows:
box::use(R/run_diff)
run_diff$calculate_diff(object, ...)
When I hover my mouse on run_diff$calculate_diff(), no function pamameter suggestiong is shown.
When I use source("R/run_diff.R"), it works well that the function pamameter suggestion is shown.
R6 and box bring new OOB framework that isimilar to python into R, it may be a trend in future in R.
As the author of the ‘box’ package I’d be happy to assist with adding support for this; however, I currently don’t know enough about the ‘languageserver’ package to do this on my own.
You could check https://github.com/REditorSupport/languageserver/blob/master/R/document.R#L228 to see how the parser hooks work.
As the author of the ‘box’ package I’d be happy to assist with adding support for this; however, I currently don’t know enough about the ‘languageserver’ package to do this on my own.
@klmr I have did some reseach and I don't know if I am right:
- in
languageserverpackage, there is aparser_hookslist allow user to do some customize parsing, the logic of implmentingboxsupport should occur there. related lines. and there is anenvinlanguageserverwhich is different from the R environment,envis wherelanguageserverstores the metadata about the document allow for completion and hover support and so on. the importing of box should be reflected inenvby update it. - in
box, module import are handled here. - the import process of
boxcan be considered (bylanguageserver) as assign a new environment to the module name, and attach exported objects (declared in box module), handle document parsing (roxygendocuments in box module). - so I think the implementation can be something like:
on box side, we need a "import list" describing what should be imported, and parse the roxygen comments with this to get hovering documentation support in languagerserver. the resulted import list and documents should be placed into the languageserver env functions signatures and documents by similar action like action$assign.
I was planning to implement this on my own but I overestimated my power, I can't even read box and languageserver code (but I really want this feature, modular R import is something I've been waiting for so looong). I don't know if this helps.
@TTTPOB Thanks, this is a good analysis. On the ‘box’ side I will have to export some functions that return the parsed ‘use’ specification and load information (probably related to klmr/box#179). I’m still not entirely sure how to extract and assign the required definitions without actually loading the module. We might have to satisfy us with a heuristic that misses dynamically defined names inside a module.
What I’m missing in parse_hooks (and in general anywhere in ‘languageserver’) is the handling of source calls. Presumably these are handled somewhere, right? If I could use this as a template it would make adding
an implementation for box::use much easier.
@klmr to my knowledge r languageserver do not handle source calls... for example if you have a file structure like this, if you only opened main.r in vscode editor, you won't get name completion of the a_long_variable_name.

instead, languageserver choose to link all opened files. that is to say, if you open main.r and fake_dir/fake_source.r at the same time, you will get completion from the other file (bidirectional), even without the source call.
