-
Notifications
You must be signed in to change notification settings - Fork 93
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
Implement back end -> front end comm messages #218
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall LGTM; only concern is around rustfmt
noise.
|
||
fn target_name(&self) -> String { | ||
"lsp".to_string() | ||
pub fn msg_rx(&self) -> Sender<CommChannelMsg> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function is called msg_rx
but appears to return msg_tx
; is that intentional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm also confused how this would be used since we're just throwing away the created receiver.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I've clarified the name and added a comment explaining this. In short, the LSP is sort of a dummy comm -- it has the same lifecycle (so we can start/stop/query it like a regular comm) but because it has its own TCP connection it doesn't send or receive messages over the Jupyter protocol.
@@ -274,10 +275,10 @@ fn test_kernel() { | |||
info!("Received execute reply: {:?}", reply); | |||
assert_eq!(reply.content.status, Status::Ok); | |||
assert_eq!(reply.content.execution_count, 2); | |||
} | |||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These trailing commas are kind of noisy; can we configure rustfmt
to skip this sort of change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(That is, I think either form is fine -- we should ask rustfmt
to accept both has-trailing-comma and no-trailing-comma forms)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternatively, can we configure rustfmt
to only run on regions of the file that we've explicitly modified?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's possible for rustfmt
to accept either one -- it is supposed to be opinionated. Nor is it possible to get it to run only on changed lines.
@@ -248,32 +251,38 @@ export class LanguageRuntimeAdapter | |||
* Creates a new client instance. | |||
* | |||
* @param type The type of client to create | |||
* @param params The parameters for the client; the format of this object is |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there any restrictions on this type (e.g. it must be a JavaScript object? it must be parsable as JSON?) I'm just wondering if there's something mildly more typed than any
that we could use. But any
is probably fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good question. I checked the spec and it says that data
is a dict, so I think that implies it has to be an object
of some kind. I've updated the relevant types.
Merge pull request #218 from posit-dev/feature/force-quit Add force quit method -------------------- Commit message for posit-dev/positron-python@b06f70d: add force quit method Authored-by: Jonathan McPherson <jonathan@rstudio.com> Signed-off-by: Jonathan McPherson <jonathan@rstudio.com>
Merge pull request #218 from posit-dev/feature/force-quit Add force quit method -------------------- Commit message for posit-dev/positron-python@b06f70d: add force quit method Authored-by: Jonathan McPherson <jonathan@rstudio.com> Signed-off-by: Jonathan McPherson <jonathan@rstudio.com>
This change fleshes out a previously unimplemented part of the language runtime framework: specifically, it makes it possible for "comms" (client instances, such as the Environment pane) to send messages to the front end.
It also dramatically simplifies the code needed to implement a comm. Formerly, you had to provide a Rust struct that could be sent across threads (
Send
) and implemented a trait. After this change, the contract just gives you aSender<Value>
(whereValue
is any JSON data). Sending data to the channel causes it to be forwarded to the front end.It works something like this:
That is: each comm gets its own unique
Sender
channel which has a uniqueReceiver
channel. A dedicated thread runs aSelect
that waits for any of the comms to emit data. When aReceiver
emits data, we look up the metadata associated with the comm and amend the message with the comm's ID. This gets further wrapped up with Jupyter headers and delivered to the front end via ZeroMQ.Unit tests are included for the above that test sending data to and receiving data from a comm; the tests use a dummy comm implementation that just echoes any data sent to it. This implementation is also a useful reference for the simplest possible comm.
Finally, this change also adds retry logic to the R Language Pack's server connectivity. For now this is borrowed from the Python Language Pack, but we should have something more robust here (will file an issue).