From 01bb10f5186deb69db6120ac1572bed4fb69b55d Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Mon, 16 Sep 2024 14:50:30 -0700 Subject: [PATCH] Move ProtoClient to RPC crate, behind feature flag disabled in collab (#17908) This fixes a bug where we accidentally added a `gpui` transitive dependency in `collab`. Release Notes: - N/A --- 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/{proto => 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(-) rename crates/{proto => rpc}/src/proto_client.rs (99%) diff --git a/Cargo.lock b/Cargo.lock index a6d351099b..d0af85057d 100644 --- a/Cargo.lock +++ b/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", diff --git a/crates/assistant/Cargo.toml b/crates/assistant/Cargo.toml index d2b5aed9bd..b700702062 100644 --- a/crates/assistant/Cargo.toml +++ b/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 diff --git a/crates/assistant/src/context_store.rs b/crates/assistant/src/context_store.rs index b6e1650c41..867d906791 100644 --- a/crates/assistant/src/context_store.rs +++ b/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, diff --git a/crates/channel/src/channel_buffer.rs b/crates/channel/src/channel_buffer.rs index bf32185b22..2041b16a6d 100644 --- a/crates/channel/src/channel_buffer.rs +++ b/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; diff --git a/crates/channel/src/channel_chat.rs b/crates/channel/src/channel_chat.rs index 7cbc362ff3..286eb46a91 100644 --- a/crates/channel/src/channel_chat.rs +++ b/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, diff --git a/crates/client/Cargo.toml b/crates/client/Cargo.toml index 72ca8ffc24..82237ebaa5 100644 --- a/crates/client/Cargo.toml +++ b/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 diff --git a/crates/client/src/client.rs b/crates/client/src/client.rs index 8787e2ed96..6e1362c43e 100644 --- a/crates/client/src/client.rs +++ b/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}; diff --git a/crates/project/src/buffer_store.rs b/crates/project/src/buffer_store.rs index 9bbc2f4358..403b53745a 100644 --- a/crates/project/src/buffer_store.rs +++ b/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; diff --git a/crates/project/src/lsp_store.rs b/crates/project/src/lsp_store.rs index 668bdae4dc..854915e82d 100644 --- a/crates/project/src/lsp_store.rs +++ b/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}; diff --git a/crates/project/src/project.rs b/crates/project/src/project.rs index f67423b073..8fca2ea686 100644 --- a/crates/project/src/project.rs +++ b/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}; diff --git a/crates/project/src/project_settings.rs b/crates/project/src/project_settings.rs index 70b2eccf23..2eeb840896 100644 --- a/crates/project/src/project_settings.rs +++ b/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}; diff --git a/crates/project/src/worktree_store.rs b/crates/project/src/worktree_store.rs index 6e03e614da..8b620de43e 100644 --- a/crates/project/src/worktree_store.rs +++ b/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}, diff --git a/crates/proto/Cargo.toml b/crates/proto/Cargo.toml index e1d111366c..eca020a92d 100644 --- a/crates/proto/Cargo.toml +++ b/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 diff --git a/crates/proto/src/proto.rs b/crates/proto/src/proto.rs index 7af66a6a6b..a1853ed4a3 100644 --- a/crates/proto/src/proto.rs +++ b/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; diff --git a/crates/remote/Cargo.toml b/crates/remote/Cargo.toml index 2e96d8062e..5c291b59d3 100644 --- a/crates/remote/Cargo.toml +++ b/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 diff --git a/crates/remote/src/ssh_session.rs b/crates/remote/src/ssh_session.rs index 5ff11fe099..4762a785db 100644 --- a/crates/remote/src/ssh_session.rs +++ b/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, diff --git a/crates/remote_server/src/headless_project.rs b/crates/remote_server/src/headless_project.rs index c8ec49cc1e..08723daa01 100644 --- a/crates/remote_server/src/headless_project.rs +++ b/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::{ diff --git a/crates/rpc/Cargo.toml b/crates/rpc/Cargo.toml index 79cb811afa..f664085f04 100644 --- a/crates/rpc/Cargo.toml +++ b/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 diff --git a/crates/proto/src/proto_client.rs b/crates/rpc/src/proto_client.rs similarity index 99% rename from crates/proto/src/proto_client.rs rename to crates/rpc/src/proto_client.rs index edcb6417d8..4a990a8433 100644 --- a/crates/proto/src/proto_client.rs +++ b/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)] diff --git a/crates/rpc/src/rpc.rs b/crates/rpc/src/rpc.rs index 2e8b1ef6b7..9c62238733 100644 --- a/crates/rpc/src/rpc.rs +++ b/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; diff --git a/crates/worktree/src/worktree.rs b/crates/worktree/src/worktree.rs index 584524a1d7..776c01c49c 100644 --- a/crates/worktree/src/worktree.rs +++ b/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};