cli: start to extract a generic rpc interface (#171299)

I want to use the rpc interface for communication via stdin/out in wsl,
but currently RPC is tightly coupled to the control server. The control
server also speaks msgpack instead of JSON, since it deals with binary
messages. WSL won't, and we'll want to use JSON to interact with VS
Code, so some separation is needed.

This pulls out a base set of RPC types for use in both scenarios.
Currently these are only 'helper' structs that don't actually do any
i/o, but once I figure out the model I would like to have a cleaner way
to do i/o in a unified way as well.

For the control server, previously we basically handled all methods in
one big `switch` block with nasty macros, whereas now there's
nicer `register_a/sync` functions.

Some additional small refactors were needed to preserve the strict
ordering of server messages, since they need to be order else we get
decompression errors. This is the `start_bridge_write_loop`. As a small
benefit, this means we can avoid the relatively expensive async Tokio
mutex that we were using, and instead use the standard library mutex.
This commit is contained in:
Connor Peet
2023-01-16 21:43:41 -08:00
committed by GitHub
parent 1379f03754
commit 4d882322ca
6 changed files with 627 additions and 383 deletions

View File

@@ -248,15 +248,6 @@ impl std::fmt::Display for NoAttachedServerError {
}
}
#[derive(Debug)]
pub struct ServerWriteError();
impl std::fmt::Display for ServerWriteError {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "Error writing to the server, it should be restarted")
}
}
#[derive(Debug)]
pub struct RefreshTokenNotAvailableError();
@@ -379,6 +370,15 @@ impl std::fmt::Display for WindowsNeedsElevation {
}
}
#[derive(Debug)]
pub struct InvalidRpcDataError(pub String);
impl std::fmt::Display for InvalidRpcDataError {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "parse error: {}", self.0)
}
}
#[derive(Debug)]
pub struct CorruptDownload(pub String);
@@ -491,7 +491,6 @@ makeAnyError!(
ExtensionInstallFailed,
MismatchedLaunchModeError,
NoAttachedServerError,
ServerWriteError,
UnsupportedPlatformError,
RefreshTokenNotAvailableError,
NoInstallInUserProvidedPath,
@@ -505,7 +504,8 @@ makeAnyError!(
CorruptDownload,
MissingHomeDirectory,
CommandFailed,
OAuthError
OAuthError,
InvalidRpcDataError
);
impl From<reqwest::Error> for AnyError {