diff --git a/zed-rpc/src/rest.rs b/zed-rpc/src/rest.rs index 1fdf313d6373b91f05bebf837fd20c02ad3da5b9..097f68ddc7330ba8ed62bc7d01694932f05512d4 100644 --- a/zed-rpc/src/rest.rs +++ b/zed-rpc/src/rest.rs @@ -1,7 +1,8 @@ use serde::{Deserialize, Serialize}; #[derive(Serialize, Deserialize)] -pub struct CreateWorktreeResponse { - pub worktree_id: i32, - pub rpc_address: String, +pub struct GetRpcAddressResponse { + pub address: String, } + +pub const GET_RPC_ADDRESS_PATH: &'static str = "/api/rpc-address"; diff --git a/zed/src/workspace.rs b/zed/src/workspace.rs index b2ea568f380be85b680bebd732a6ea4f835b10c5..085eeb11dba1cbc6a0f9fa7e5b3a2b5dfb91301e 100644 --- a/zed/src/workspace.rs +++ b/zed/src/workspace.rs @@ -31,7 +31,7 @@ use std::{ time::Duration, }; use surf::Url; -use zed_rpc::{proto, rest::CreateWorktreeResponse, Peer, TypedEnvelope}; +use zed_rpc::{proto, rest, Peer, TypedEnvelope}; pub fn init(cx: &mut MutableAppContext, rpc: Arc) { cx.add_global_action("workspace:open", open); @@ -672,24 +672,23 @@ impl Workspace { let (user_id, access_token) = login(zed_url.clone(), cx.platform(), cx.background_executor()).await?; - let mut response = surf::post(format!("{}/api/worktrees", &zed_url)) + let mut response = surf::get(format!("{}{}", &zed_url, &rest::GET_RPC_ADDRESS_PATH)) .header( "Authorization", http_auth_basic::Credentials::new(&user_id, &access_token).as_http_header(), ) .await - .context("")?; + .context("rpc address request failed")?; - let CreateWorktreeResponse { - worktree_id, - rpc_address, - } = response.body_json().await?; - - eprintln!("got worktree response: {:?} {:?}", worktree_id, rpc_address); + let rest::GetRpcAddressResponse { address } = response + .body_json() + .await + .context("failed to parse rpc address response")?; // TODO - If the `ZED_SERVER_URL` uses https, then wrap this stream in // a TLS stream using `native-tls`. - let stream = smol::net::TcpStream::connect(rpc_address).await?; + let stream = smol::net::TcpStream::connect(&address).await?; + log::info!("connected to rpc address {}", address); let connection_id = rpc.add_connection(stream).await; executor.spawn(rpc.handle_messages(connection_id)).detach(); @@ -702,7 +701,8 @@ impl Workspace { access_token, }, ) - .await?; + .await + .context("rpc auth request failed")?; if !auth_response.credentials_valid { Err(anyhow!("failed to authenticate with RPC server"))?; }