Repository navigation
Keep map of RRuntime objects in extension, use in r.packageInstall command - #1292
Conversation
juliasilge
left a comment
There was a problem hiding this comment.
I do think eventually we will want to rip this out again and wait for executeCode() to return something we can parse. Given how much variety there is in R .libPaths() (which is more than I even expected TBH) I now believe this, acting at the RRuntime level, is a decent option for now.
| const runtime = runtimes.get(runningRuntimes[0].runtimeId); | ||
| if (runtime) { | ||
| runtime.execute('devtools::install()', | ||
| randomUUID(), |
There was a problem hiding this comment.
@jmcphers you mentioned something today about using this ID to make sure we are waiting for the right code to finish, but this execute is synchronous so I think we're OK like this. Let me know if I am misunderstanding!
There was a problem hiding this comment.
Unfortunately this execute is not synchronous. It might appear so because the restart command can't make any progress until the execute command finishes, but we probably shouldn't bet on it because there's no guarantee the restart won't take priority (now or in the future).
What I'd suggest is:
- first generate the UUID
- then establish a listener to language runtime messages; it should listen for an idle
LanguageRuntimeStatemessage whose parent ID is the UUID - then perform the execution request
- then wait for the idle message to arrive
When an idle message arrives whose parent ID is the UUID you gave to execute(), you'll know the code is done running.
| if (runtimeState === positron.RuntimeState.Starting) { | ||
| await delay(500); |
There was a problem hiding this comment.
After playing around with this, I think this works the best and will be the least likely to end up in a bad situation:
- Kick off the restart
- Start a listener that waits for
Starting, then waits a smidge more, then executes the second piece of code
| const runtime = runtimes.get(runningRuntimes[0].runtimeId); | ||
| if (runtime) { | ||
| runtime.execute('devtools::install()', | ||
| randomUUID(), |
There was a problem hiding this comment.
Unfortunately this execute is not synchronous. It might appear so because the restart command can't make any progress until the execute command finishes, but we probably shouldn't bet on it because there's no guarantee the restart won't take priority (now or in the future).
What I'd suggest is:
- first generate the UUID
- then establish a listener to language runtime messages; it should listen for an idle
LanguageRuntimeStatemessage whose parent ID is the UUID - then perform the execution request
- then wait for the idle message to arrive
When an idle message arrives whose parent ID is the UUID you gave to execute(), you'll know the code is done running.
| runtime.onDidReceiveRuntimeMessage(runtimeMessage => { | ||
| if (runtimeMessage.parent_id === id && | ||
| runtimeMessage.type === positron.LanguageRuntimeMessageType.State) { | ||
| const runtimeMessageState = runtimeMessage as positron.LanguageRuntimeState; |
There was a problem hiding this comment.
Is this the right way to do this? i.e. get from a plain message to a message that is specifically about state as positron.LanguageRuntimeState?
There was a problem hiding this comment.
Yep, that's the right idea! Make sure that the event handler is unregistered after you get a match.
jmcphers
left a comment
There was a problem hiding this comment.
LGTM, I think this'll work until we get a better API for awaitable execution!
Addresses #1091 by ripping out the "watch for DESCRIPTION file change" piece and replace it with keeping a map of
RRuntimeobjects in the R extension that we canexecuteand watch for events with. This is basically like this option I outlined in #1279:However, this probably isn't a final version because we would like to know if the installation failed or not, to early return and not restart and
library(package_name).