-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generator object should provide completions for instances of the class #47
Comments
Just to set the stage -- we want to get the set of completions valid for the various binary operators, e.g. We could have a function like Does that sound appropriate? Are there other contexts where we might want R6 completions for an instance object, or other 'special symbols' in R6 we might want to provide completions for (e.g. It would be excellent if the returned completions could also give the type of object returned -- in RStudio, we have icons that denote the 'type' of completion and if we were to query completions in this manner it would be good to get those types as well. We have this in RStudio: https://github.com/rstudio/rstudio/blob/master/src/cpp/session/modules/SessionRCompletions.R#L38-L69, but we could also just simply convert whatever type R6 returns to that set of types. |
@kevinushey A tangential issue for completions: A generator object has a method called For example, to get the set of useful completions for |
I was just playing around with library(R6)
MyClass <- R6Class("MyClass",
public = list(x = 1, y = 2, z = 3)
)
.DollarNames.MyClass <- function(x, pattern = "") {
all_names <- ls(x, all.names, pattern = pattern)
# Filter out "z"
setdiff(all_names, "z")
}
m <- MyClass$new()
# Press tab after typing the following:
m$
# In R at the terminal, it prints "m$clone m$x m$y"
# In RStudio, it shows clone, x, y, z, and .__enclos_env__ @kevinushey Do you know why it's not working in RStudio? |
I think you can close this issue in favour of #122 |
@hadley This is slightly different, I think. The issue is when you want to have completions for an object that's not actually instantiated yet. For example, in Shiny, the session object is only instantiated when you run an app, but it would still be useful to have completions when working on the code (and the app isn't running). |
How would you declare that the yet-to-be-created |
Shiny's a bit of a special case -- RStudio would just know that a But in the general case, it would be nice to have completions for this when you're editing code but not running it: A <- mypkg::MyClass$new()
A$ <tab> |
@wch I already get completions for that case |
For this to work, RStudio would need someway to recognise that @kevinushey is there any existing support for this sort of inference? (it would also be straightforward to implement for S4 slot. Implementing for S3 would require some sort of annotation.) |
Unfortunately no, this is not supported yet. |
As discussed in rstudio/shiny#657, it would be helpful if a generator object had a way of providing completions for instances of the class.
@kevinushey if you have any recommendations for the interface, please let me know.
The text was updated successfully, but these errors were encountered: