SshLspAdapterDelegate (#17965)

Release Notes:

- N/A
This commit is contained in:
Conrad Irwin 2024-09-17 14:13:37 -06:00 committed by GitHub
parent 7814dd0301
commit 8cc6df573c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 268 additions and 148 deletions

View file

@ -15,7 +15,7 @@ use gpui::{AppContext, AsyncAppContext, Model, SemanticVersion};
use parking_lot::Mutex;
use rpc::{
proto::{self, build_typed_envelope, Envelope, EnvelopedMessage, PeerId, RequestMessage},
EntityMessageSubscriber, ProtoClient, ProtoMessageHandlerSet,
EntityMessageSubscriber, ProtoClient, ProtoMessageHandlerSet, RpcError,
};
use smol::{
fs,
@ -157,8 +157,9 @@ impl SshSession {
let mut remote_server_child = socket
.ssh_command(format!(
"RUST_LOG={} {:?} run",
"RUST_LOG={} RUST_BACKTRACE={} {:?} run",
std::env::var("RUST_LOG").unwrap_or_default(),
std::env::var("RUST_BACKTRACE").unwrap_or_default(),
remote_binary_path,
))
.spawn()
@ -349,7 +350,7 @@ impl SshSession {
}
Err(error) => {
log::error!(
"error handling message. type:{type_name}, error:{error:?}",
"error handling message. type:{type_name}, error:{error}",
);
}
}
@ -371,7 +372,7 @@ impl SshSession {
payload: T,
) -> impl 'static + Future<Output = Result<T::Response>> {
log::debug!("ssh request start. name:{}", T::NAME);
let response = self.request_dynamic(payload.into_envelope(0, None, None), "");
let response = self.request_dynamic(payload.into_envelope(0, None, None), T::NAME);
async move {
let response = response.await?;
log::debug!("ssh request finish. name:{}", T::NAME);
@ -388,7 +389,7 @@ impl SshSession {
pub fn request_dynamic(
&self,
mut envelope: proto::Envelope,
_request_type: &'static str,
type_name: &'static str,
) -> impl 'static + Future<Output = Result<proto::Envelope>> {
envelope.id = self.next_message_id.fetch_add(1, SeqCst);
let (tx, rx) = oneshot::channel();
@ -396,7 +397,13 @@ impl SshSession {
response_channels_lock.insert(MessageId(envelope.id), tx);
drop(response_channels_lock);
self.outgoing_tx.unbounded_send(envelope).ok();
async move { Ok(rx.await.context("connection lost")?.0) }
async move {
let response = rx.await.context("connection lost")?.0;
if let Some(proto::envelope::Payload::Error(error)) = &response.payload {
return Err(RpcError::from_proto(error, type_name));
}
Ok(response)
}
}
pub fn send_dynamic(&self, mut envelope: proto::Envelope) -> Result<()> {