Move ProtoClient to RPC crate, behind feature flag disabled in collab (#17908)

Max Brunsfeld created

This fixes a bug where we accidentally added a `gpui` transitive
dependency in `collab`.

Release Notes:

- N/A

Change summary

Cargo.lock                                   |  4 +---
crates/assistant/Cargo.toml                  |  1 +
crates/assistant/src/context_store.rs        |  2 +-
crates/channel/src/channel_buffer.rs         |  4 ++--
crates/channel/src/channel_chat.rs           |  2 +-
crates/client/Cargo.toml                     |  2 +-
crates/client/src/client.rs                  |  1 -
crates/project/src/buffer_store.rs           |  5 +----
crates/project/src/lsp_store.rs              |  2 +-
crates/project/src/project.rs                |  5 +----
crates/project/src/project_settings.rs       |  5 +----
crates/project/src/worktree_store.rs         |  4 ++--
crates/proto/Cargo.toml                      |  3 ---
crates/proto/src/proto.rs                    |  2 --
crates/remote/Cargo.toml                     |  2 +-
crates/remote/src/ssh_session.rs             |  6 +++---
crates/remote_server/src/headless_project.rs |  4 ++--
crates/rpc/Cargo.toml                        |  2 +-
crates/rpc/src/proto_client.rs               | 10 +++++-----
crates/rpc/src/rpc.rs                        |  5 +++++
crates/worktree/src/worktree.rs              |  2 +-
21 files changed, 31 insertions(+), 42 deletions(-)

Detailed changes

Cargo.lock 🔗

@@ -418,6 +418,7 @@ dependencies = [
  "regex",
  "release_channel",
  "rope",
+ "rpc",
  "schemars",
  "search",
  "semantic_index",
@@ -8553,9 +8554,6 @@ version = "0.1.0"
 dependencies = [
  "anyhow",
  "collections",
- "futures 0.3.30",
- "gpui",
- "parking_lot",
  "prost",
  "prost-build",
  "serde",

crates/assistant/Cargo.toml 🔗

@@ -65,6 +65,7 @@ proto.workspace = true
 regex.workspace = true
 release_channel.workspace = true
 rope.workspace = true
+rpc.workspace = true
 schemars.workspace = true
 search.workspace = true
 semantic_index.workspace = true

crates/assistant/src/context_store.rs 🔗

@@ -2,7 +2,6 @@ use crate::{
     prompts::PromptBuilder, Context, ContextEvent, ContextId, ContextOperation, ContextVersion,
     SavedContext, SavedContextMetadata,
 };
-use ::proto::AnyProtoClient;
 use anyhow::{anyhow, Context as _, Result};
 use client::{proto, telemetry::Telemetry, Client, TypedEnvelope};
 use clock::ReplicaId;
@@ -16,6 +15,7 @@ use language::LanguageRegistry;
 use paths::contexts_dir;
 use project::Project;
 use regex::Regex;
+use rpc::AnyProtoClient;
 use std::{
     cmp::Reverse,
     ffi::OsStr,

crates/channel/src/channel_buffer.rs 🔗

@@ -5,8 +5,8 @@ use collections::HashMap;
 use gpui::{AppContext, AsyncAppContext, Context, EventEmitter, Model, ModelContext, Task};
 use language::proto::serialize_version;
 use rpc::{
-    proto::{self, AnyProtoClient, PeerId},
-    TypedEnvelope,
+    proto::{self, PeerId},
+    AnyProtoClient, TypedEnvelope,
 };
 use std::{sync::Arc, time::Duration};
 use text::BufferId;

crates/channel/src/channel_chat.rs 🔗

@@ -11,7 +11,7 @@ use gpui::{
     AppContext, AsyncAppContext, Context, EventEmitter, Model, ModelContext, Task, WeakModel,
 };
 use rand::prelude::*;
-use rpc::proto::AnyProtoClient;
+use rpc::AnyProtoClient;
 use std::{
     ops::{ControlFlow, Range},
     sync::Arc,

crates/client/Cargo.toml 🔗

@@ -34,7 +34,7 @@ parking_lot.workspace = true
 postage.workspace = true
 rand.workspace = true
 release_channel.workspace = true
-rpc.workspace = true
+rpc = { workspace = true, features = ["gpui"] }
 schemars.workspace = true
 serde.workspace = true
 serde_json.workspace = true

crates/client/src/client.rs 🔗

@@ -22,7 +22,6 @@ use gpui::{actions, AppContext, AsyncAppContext, Global, Model, Task, WeakModel}
 use http_client::{AsyncBody, HttpClient, HttpClientWithUrl};
 use parking_lot::RwLock;
 use postage::watch;
-use proto::{AnyProtoClient, EntityMessageSubscriber, ProtoClient, ProtoMessageHandlerSet};
 use rand::prelude::*;
 use release_channel::{AppVersion, ReleaseChannel};
 use rpc::proto::{AnyTypedEnvelope, EnvelopedMessage, PeerId, RequestMessage};

crates/project/src/buffer_store.rs 🔗

@@ -17,10 +17,7 @@ use language::{
     proto::{deserialize_line_ending, deserialize_version, serialize_version, split_operations},
     Buffer, Capability, Event as BufferEvent, File as _, Language, Operation,
 };
-use rpc::{
-    proto::{self, AnyProtoClient},
-    ErrorExt as _, TypedEnvelope,
-};
+use rpc::{proto, AnyProtoClient, ErrorExt as _, TypedEnvelope};
 use smol::channel::Receiver;
 use std::{io, path::Path, str::FromStr as _, sync::Arc, time::Instant};
 use text::BufferId;

crates/project/src/lsp_store.rs 🔗

@@ -49,7 +49,7 @@ use parking_lot::{Mutex, RwLock};
 use postage::watch;
 use rand::prelude::*;
 
-use rpc::proto::AnyProtoClient;
+use rpc::AnyProtoClient;
 use serde::Serialize;
 use settings::{Settings, SettingsLocation, SettingsStore};
 use sha2::{Digest, Sha256};

crates/project/src/project.rs 🔗

@@ -62,10 +62,7 @@ use paths::{local_tasks_file_relative_path, local_vscode_tasks_file_relative_pat
 use prettier_support::{DefaultPrettier, PrettierInstance};
 use project_settings::{LspSettings, ProjectSettings, SettingsObserver};
 use remote::SshSession;
-use rpc::{
-    proto::{AnyProtoClient, SSH_PROJECT_ID},
-    ErrorCode,
-};
+use rpc::{proto::SSH_PROJECT_ID, AnyProtoClient, ErrorCode};
 use search::{SearchInputKind, SearchQuery, SearchResult};
 use search_history::SearchHistory;
 use settings::{watch_config_file, Settings, SettingsLocation, SettingsStore};

crates/project/src/project_settings.rs 🔗

@@ -2,10 +2,7 @@ use collections::HashMap;
 use fs::Fs;
 use gpui::{AppContext, AsyncAppContext, BorrowAppContext, Model, ModelContext};
 use paths::local_settings_file_relative_path;
-use rpc::{
-    proto::{self, AnyProtoClient},
-    TypedEnvelope,
-};
+use rpc::{proto, AnyProtoClient, TypedEnvelope};
 use schemars::JsonSchema;
 use serde::{Deserialize, Serialize};
 use settings::{Settings, SettingsSources, SettingsStore};

crates/project/src/worktree_store.rs 🔗

@@ -17,8 +17,8 @@ use gpui::{
 };
 use postage::oneshot;
 use rpc::{
-    proto::{self, AnyProtoClient, SSH_PROJECT_ID},
-    TypedEnvelope,
+    proto::{self, SSH_PROJECT_ID},
+    AnyProtoClient, TypedEnvelope,
 };
 use smol::{
     channel::{Receiver, Sender},

crates/proto/Cargo.toml 🔗

@@ -19,11 +19,8 @@ doctest = false
 [dependencies]
 anyhow.workspace = true
 collections.workspace = true
-futures.workspace = true
-parking_lot.workspace = true
 prost.workspace = true
 serde.workspace = true
-gpui.workspace = true
 
 [build-dependencies]
 prost-build.workspace = true

crates/proto/src/proto.rs 🔗

@@ -2,11 +2,9 @@
 
 pub mod error;
 mod macros;
-mod proto_client;
 mod typed_envelope;
 
 pub use error::*;
-pub use proto_client::*;
 pub use typed_envelope::*;
 
 use collections::HashMap;

crates/remote/Cargo.toml 🔗

@@ -26,7 +26,7 @@ gpui.workspace = true
 log.workspace = true
 parking_lot.workspace = true
 prost.workspace = true
-rpc.workspace = true
+rpc = { workspace = true, features = ["gpui"] }
 serde.workspace = true
 serde_json.workspace = true
 smol.workspace = true

crates/remote/src/ssh_session.rs 🔗

@@ -13,9 +13,9 @@ use futures::{
 };
 use gpui::{AppContext, AsyncAppContext, Model, SemanticVersion};
 use parking_lot::Mutex;
-use rpc::proto::{
-    self, build_typed_envelope, EntityMessageSubscriber, Envelope, EnvelopedMessage, PeerId,
-    ProtoClient, ProtoMessageHandlerSet, RequestMessage,
+use rpc::{
+    proto::{self, build_typed_envelope, Envelope, EnvelopedMessage, PeerId, RequestMessage},
+    EntityMessageSubscriber, ProtoClient, ProtoMessageHandlerSet,
 };
 use smol::{
     fs,

crates/remote_server/src/headless_project.rs 🔗

@@ -8,8 +8,8 @@ use project::{
 };
 use remote::SshSession;
 use rpc::{
-    proto::{self, AnyProtoClient, SSH_PEER_ID, SSH_PROJECT_ID},
-    TypedEnvelope,
+    proto::{self, SSH_PEER_ID, SSH_PROJECT_ID},
+    AnyProtoClient, TypedEnvelope,
 };
 use smol::stream::StreamExt;
 use std::{

crates/rpc/Cargo.toml 🔗

@@ -14,6 +14,7 @@ path = "src/rpc.rs"
 doctest = false
 
 [features]
+gpui = ["dep:gpui"]
 test-support = ["collections/test-support", "gpui/test-support", "proto/test-support"]
 
 [dependencies]
@@ -39,7 +40,6 @@ zstd = "0.11"
 [target.'cfg(target_os = "linux")'.dependencies]
 zstd = { version = "0.11", features = [ "pkg-config" ] }
 
-
 [dev-dependencies]
 collections = { workspace = true, features = ["test-support"] }
 env_logger.workspace = true

crates/proto/src/proto_client.rs → crates/rpc/src/proto_client.rs 🔗

@@ -1,7 +1,3 @@
-use crate::{
-    error::ErrorExt as _, AnyTypedEnvelope, EntityMessage, Envelope, EnvelopedMessage,
-    RequestMessage, TypedEnvelope,
-};
 use anyhow::anyhow;
 use collections::HashMap;
 use futures::{
@@ -9,7 +5,11 @@ use futures::{
     Future, FutureExt as _,
 };
 use gpui::{AnyModel, AnyWeakModel, AsyncAppContext, Model};
-pub use prost::Message;
+// pub use prost::Message;
+use proto::{
+    error::ErrorExt as _, AnyTypedEnvelope, EntityMessage, Envelope, EnvelopedMessage,
+    RequestMessage, TypedEnvelope,
+};
 use std::{any::TypeId, sync::Arc};
 
 #[derive(Clone)]

crates/rpc/src/rpc.rs 🔗

@@ -14,4 +14,9 @@ pub use peer::*;
 pub use proto::{error::*, Receipt, TypedEnvelope};
 mod macros;
 
+#[cfg(feature = "gpui")]
+mod proto_client;
+#[cfg(feature = "gpui")]
+pub use proto_client::*;
+
 pub const PROTOCOL_VERSION: u32 = 68;

crates/worktree/src/worktree.rs 🔗

@@ -36,7 +36,7 @@ use postage::{
     prelude::{Sink as _, Stream as _},
     watch,
 };
-use rpc::proto::{self, AnyProtoClient};
+use rpc::{proto, AnyProtoClient};
 pub use settings::WorktreeId;
 use settings::{Settings, SettingsLocation, SettingsStore};
 use smallvec::{smallvec, SmallVec};