Rebuild LSP service, socket, and client on reconnect #201
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Follow up to #193
I accidentally introduced a bug related to UI refreshes with
CMD + R
. If you run that with an active R session, then you should get a panic related to the LSP (something about unwrapping aNone
).It turns out that we can't move the LSP service, socket, and client to
start_kernel()
. That code will get run exactly 1 time per ark session lifetime, but thelsp_start()
method will get called every time the UI is refreshed (i.e.CMD + R
) (which prompts a newcomm_open
request). This means we really do need "fresh" instances of these objects after each refresh.Most of the code from #193 related to these objects is now reverted, moving their creation back into
start_lsp()
.However, we now also use an
r_task()
to ship theClient
over toRMain
after each refresh.R_MAIN
actually should be started up by the time we get here to call thisr_task()
, because theLsp::start()
method that callsstart_lsp()
will wait for thekernel_init_tx
notification that is sent out by the firstr_read_console()
iteration, andR_MAIN
exists at that point. I'm convinced that even if it didn't exist yet, thenr_task()
would correctly block until the channel for communicating with the main R thread was set up, due toget_tasks_tx()
.I did some testing and things like
usethis::edit_r_profile()
(which use theClient
stored inR_MAIN
) work as expected before and after aCMD + R
refresh, which makes me somewhat confident that the client is getting refreshed properly.