872 lines · 26.6 KB · Rust
RawDownload
#![allow(non_snake_case)] pub mod error;mod macros;mod typed_envelope; pub use error::*;pub use typed_envelope::*; pub use prost::{DecodeError, Message};use serde::Serialize;use std::{    any::{Any, TypeId},    cmp,    fmt::{self, Debug},    iter, mem,    path::{Path, PathBuf},    sync::Arc,    time::{Duration, SystemTime, UNIX_EPOCH},}; include!(concat!(env!("OUT_DIR"), "/zed.messages.rs")); pub const SSH_PEER_ID: PeerId = PeerId { owner_id: 0, id: 0 };pub const SSH_PROJECT_ID: u64 = 0; pub trait EnvelopedMessage: Clone + Debug + Serialize + Sized + Send + Sync + 'static {    const NAME: &'static str;    const PRIORITY: MessagePriority;    fn into_envelope(        self,        id: u32,        responding_to: Option<u32>,        original_sender_id: Option<PeerId>,    ) -> Envelope;    fn from_envelope(envelope: Envelope) -> Option<Self>;} pub trait EntityMessage: EnvelopedMessage {    type Entity;    fn remote_entity_id(&self) -> u64;} pub trait RequestMessage: EnvelopedMessage {    type Response: EnvelopedMessage;} pub trait AnyTypedEnvelope: 'static + Send + Sync {    fn payload_type_id(&self) -> TypeId;    fn payload_type_name(&self) -> &'static str;    fn as_any(&self) -> &dyn Any;    fn into_any(self: Box<Self>) -> Box<dyn Any + Send + Sync>;    fn is_background(&self) -> bool;    fn original_sender_id(&self) -> Option<PeerId>;    fn sender_id(&self) -> PeerId;    fn message_id(&self) -> u32;} pub enum MessagePriority {    Foreground,    Background,} impl<T: EnvelopedMessage> AnyTypedEnvelope for TypedEnvelope<T> {    fn payload_type_id(&self) -> TypeId {        TypeId::of::<T>()    }     fn payload_type_name(&self) -> &'static str {        T::NAME    }     fn as_any(&self) -> &dyn Any {        self    }     fn into_any(self: Box<Self>) -> Box<dyn Any + Send + Sync> {        self    }     fn is_background(&self) -> bool {        matches!(T::PRIORITY, MessagePriority::Background)    }     fn original_sender_id(&self) -> Option<PeerId> {        self.original_sender_id    }     fn sender_id(&self) -> PeerId {        self.sender_id    }     fn message_id(&self) -> u32 {        self.message_id    }} impl PeerId {    pub fn from_u64(peer_id: u64) -> Self {        let owner_id = (peer_id >> 32) as u32;        let id = peer_id as u32;        Self { owner_id, id }    }     pub fn as_u64(self) -> u64 {        ((self.owner_id as u64) << 32) | (self.id as u64)    }} impl Copy for PeerId {} impl Eq for PeerId {} impl Ord for PeerId {    fn cmp(&self, other: &Self) -> cmp::Ordering {        self.owner_id            .cmp(&other.owner_id)            .then_with(|| self.id.cmp(&other.id))    }} impl PartialOrd for PeerId {    fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> {        Some(self.cmp(other))    }} impl std::hash::Hash for PeerId {    fn hash<H: std::hash::Hasher>(&self, state: &mut H) {        self.owner_id.hash(state);        self.id.hash(state);    }} impl fmt::Display for PeerId {    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {        write!(f, "{}/{}", self.owner_id, self.id)    }} pub trait FromProto {    fn from_proto(proto: String) -> Self;} pub trait ToProto {    fn to_proto(self) -> String;} impl FromProto for PathBuf {    #[cfg(target_os = "windows")]    fn from_proto(proto: String) -> Self {        proto.split("/").collect()    }     #[cfg(not(target_os = "windows"))]    fn from_proto(proto: String) -> Self {        PathBuf::from(proto)    }} impl FromProto for Arc<Path> {    fn from_proto(proto: String) -> Self {        PathBuf::from_proto(proto).into()    }} impl ToProto for PathBuf {    #[cfg(target_os = "windows")]    fn to_proto(self) -> String {        self.components()            .map(|comp| comp.as_os_str().to_string_lossy().to_string())            .collect::<Vec<_>>()            .join("/")    }     #[cfg(not(target_os = "windows"))]    fn to_proto(self) -> String {        self.to_string_lossy().to_string()    }} impl ToProto for &Path {    #[cfg(target_os = "windows")]    fn to_proto(self) -> String {        self.components()            .map(|comp| comp.as_os_str().to_string_lossy().to_string())            .collect::<Vec<_>>()            .join("/")    }     #[cfg(not(target_os = "windows"))]    fn to_proto(self) -> String {        self.to_string_lossy().to_string()    }} messages!(    (AcceptTermsOfService, Foreground),    (AcceptTermsOfServiceResponse, Foreground),    (Ack, Foreground),    (AckBufferOperation, Background),    (AckChannelMessage, Background),    (AddNotification, Foreground),    (AddProjectCollaborator, Foreground),    (ApplyCodeAction, Background),    (ApplyCodeActionResponse, Background),    (ApplyCompletionAdditionalEdits, Background),    (ApplyCompletionAdditionalEditsResponse, Background),    (BufferReloaded, Foreground),    (BufferSaved, Foreground),    (Call, Foreground),    (CallCanceled, Foreground),    (CancelCall, Foreground),    (ChannelMessageSent, Foreground),    (ChannelMessageUpdate, Foreground),    (Commit, Background),    (ComputeEmbeddings, Background),    (ComputeEmbeddingsResponse, Background),    (CopyProjectEntry, Foreground),    (CreateBufferForPeer, Foreground),    (CreateChannel, Foreground),    (CreateChannelResponse, Foreground),    (CreateProjectEntry, Foreground),    (CreateRoom, Foreground),    (CreateRoomResponse, Foreground),    (DeclineCall, Foreground),    (DeleteChannel, Foreground),    (DeleteNotification, Foreground),    (UpdateNotification, Foreground),    (DeleteProjectEntry, Foreground),    (EndStream, Foreground),    (Error, Foreground),    (ExpandProjectEntry, Foreground),    (ExpandProjectEntryResponse, Foreground),    (ExpandAllForProjectEntry, Foreground),    (ExpandAllForProjectEntryResponse, Foreground),    (Follow, Foreground),    (FollowResponse, Foreground),    (FormatBuffers, Foreground),    (FormatBuffersResponse, Foreground),    (FuzzySearchUsers, Foreground),    (GetCachedEmbeddings, Background),    (GetCachedEmbeddingsResponse, Background),    (GetChannelMembers, Foreground),    (GetChannelMembersResponse, Foreground),    (GetChannelMessages, Background),    (GetChannelMessagesById, Background),    (GetChannelMessagesResponse, Background),    (GetCodeActions, Background),    (GetCodeActionsResponse, Background),    (GetCompletions, Background),    (GetCompletionsResponse, Background),    (GetDefinition, Background),    (GetDefinitionResponse, Background),    (GetDeclaration, Background),    (GetDeclarationResponse, Background),    (GetDocumentHighlights, Background),    (GetDocumentHighlightsResponse, Background),    (GetHover, Background),    (GetHoverResponse, Background),    (GetNotifications, Foreground),    (GetNotificationsResponse, Foreground),    (GetPrivateUserInfo, Foreground),    (GetPrivateUserInfoResponse, Foreground),    (GetProjectSymbols, Background),    (GetProjectSymbolsResponse, Background),    (GetReferences, Background),    (GetReferencesResponse, Background),    (GetSignatureHelp, Background),    (GetSignatureHelpResponse, Background),    (GetSupermavenApiKey, Background),    (GetSupermavenApiKeyResponse, Background),    (GetTypeDefinition, Background),    (GetTypeDefinitionResponse, Background),    (GetImplementation, Background),    (GetImplementationResponse, Background),    (GetLlmToken, Background),    (GetLlmTokenResponse, Background),    (OpenUnstagedDiff, Foreground),    (OpenUnstagedDiffResponse, Foreground),    (OpenUncommittedDiff, Foreground),    (OpenUncommittedDiffResponse, Foreground),    (GetUsers, Foreground),    (Hello, Foreground),    (IncomingCall, Foreground),    (InlayHints, Background),    (InlayHintsResponse, Background),    (InviteChannelMember, Foreground),    (JoinChannel, Foreground),    (JoinChannelBuffer, Foreground),    (JoinChannelBufferResponse, Foreground),    (JoinChannelChat, Foreground),    (JoinChannelChatResponse, Foreground),    (JoinProject, Foreground),    (JoinProjectResponse, Foreground),    (JoinRoom, Foreground),    (JoinRoomResponse, Foreground),    (LeaveChannelBuffer, Background),    (LeaveChannelChat, Foreground),    (LeaveProject, Foreground),    (LeaveRoom, Foreground),    (MarkNotificationRead, Foreground),    (MoveChannel, Foreground),    (OnTypeFormatting, Background),    (OnTypeFormattingResponse, Background),    (OpenBufferById, Background),    (OpenBufferByPath, Background),    (OpenBufferForSymbol, Background),    (OpenBufferForSymbolResponse, Background),    (OpenBufferResponse, Background),    (OpenCommitMessageBuffer, Background),    (PerformRename, Background),    (PerformRenameResponse, Background),    (Ping, Foreground),    (PrepareRename, Background),    (PrepareRenameResponse, Background),    (ProjectEntryResponse, Foreground),    (CountLanguageModelTokens, Background),    (CountLanguageModelTokensResponse, Background),    (RefreshLlmToken, Background),    (RefreshInlayHints, Foreground),    (RejoinChannelBuffers, Foreground),    (RejoinChannelBuffersResponse, Foreground),    (RejoinRoom, Foreground),    (RejoinRoomResponse, Foreground),    (ReloadBuffers, Foreground),    (ReloadBuffersResponse, Foreground),    (RemoveChannelMember, Foreground),    (RemoveChannelMessage, Foreground),    (UpdateChannelMessage, Foreground),    (RemoveContact, Foreground),    (RemoveProjectCollaborator, Foreground),    (RenameChannel, Foreground),    (RenameChannelResponse, Foreground),    (RenameProjectEntry, Foreground),    (RequestContact, Foreground),    (ResolveCompletionDocumentation, Background),    (ResolveCompletionDocumentationResponse, Background),    (ResolveInlayHint, Background),    (ResolveInlayHintResponse, Background),    (RespondToChannelInvite, Foreground),    (RespondToContactRequest, Foreground),    (RoomUpdated, Foreground),    (SaveBuffer, Foreground),    (SetChannelMemberRole, Foreground),    (SetChannelVisibility, Foreground),    (SendChannelMessage, Background),    (SendChannelMessageResponse, Background),    (ShareProject, Foreground),    (ShareProjectResponse, Foreground),    (ShowContacts, Foreground),    (Stage, Background),    (StartLanguageServer, Foreground),    (SubscribeToChannels, Foreground),    (SynchronizeBuffers, Foreground),    (SynchronizeBuffersResponse, Foreground),    (TaskContextForLocation, Background),    (TaskContext, Background),    (Test, Foreground),    (Unfollow, Foreground),    (UnshareProject, Foreground),    (Unstage, Background),    (UpdateBuffer, Foreground),    (UpdateBufferFile, Foreground),    (UpdateChannelBuffer, Foreground),    (UpdateChannelBufferCollaborators, Foreground),    (UpdateChannels, Foreground),    (UpdateUserChannels, Foreground),    (UpdateContacts, Foreground),    (UpdateDiagnosticSummary, Foreground),    (UpdateDiffBases, Foreground),    (UpdateFollowers, Foreground),    (UpdateInviteInfo, Foreground),    (UpdateLanguageServer, Foreground),    (UpdateParticipantLocation, Foreground),    (UpdateProject, Foreground),    (UpdateProjectCollaborator, Foreground),    (UpdateUserPlan, Foreground),    (UpdateWorktree, Foreground),    (UpdateWorktreeSettings, Foreground),    (UsersResponse, Foreground),    (LspExtExpandMacro, Background),    (LspExtExpandMacroResponse, Background),    (LspExtOpenDocs, Background),    (LspExtOpenDocsResponse, Background),    (SetRoomParticipantRole, Foreground),    (BlameBuffer, Foreground),    (BlameBufferResponse, Foreground),    (RejoinRemoteProjects, Foreground),    (RejoinRemoteProjectsResponse, Foreground),    (MultiLspQuery, Background),    (MultiLspQueryResponse, Background),    (ListRemoteDirectory, Background),    (ListRemoteDirectoryResponse, Background),    (OpenNewBuffer, Foreground),    (RestartLanguageServers, Foreground),    (LinkedEditingRange, Background),    (LinkedEditingRangeResponse, Background),    (AdvertiseContexts, Foreground),    (OpenContext, Foreground),    (OpenContextResponse, Foreground),    (CreateContext, Foreground),    (CreateContextResponse, Foreground),    (UpdateContext, Foreground),    (SynchronizeContexts, Foreground),    (SynchronizeContextsResponse, Foreground),    (LspExtSwitchSourceHeader, Background),    (LspExtSwitchSourceHeaderResponse, Background),    (AddWorktree, Foreground),    (AddWorktreeResponse, Foreground),    (FindSearchCandidates, Background),    (FindSearchCandidatesResponse, Background),    (CloseBuffer, Foreground),    (ShutdownRemoteServer, Foreground),    (RemoveWorktree, Foreground),    (LanguageServerLog, Foreground),    (Toast, Background),    (HideToast, Background),    (OpenServerSettings, Foreground),    (GetPermalinkToLine, Foreground),    (GetPermalinkToLineResponse, Foreground),    (FlushBufferedMessages, Foreground),    (LanguageServerPromptRequest, Foreground),    (LanguageServerPromptResponse, Foreground),    (GitBranches, Background),    (GitBranchesResponse, Background),    (UpdateGitBranch, Background),    (ListToolchains, Foreground),    (ListToolchainsResponse, Foreground),    (ActivateToolchain, Foreground),    (ActiveToolchain, Foreground),    (ActiveToolchainResponse, Foreground),    (GetPathMetadata, Background),    (GetPathMetadataResponse, Background),    (GetPanicFiles, Background),    (GetPanicFilesResponse, Background),    (CancelLanguageServerWork, Foreground),    (SyncExtensions, Background),    (SyncExtensionsResponse, Background),    (InstallExtension, Background),    (RegisterBufferWithLanguageServers, Background),    (GitReset, Background),    (GitCheckoutFiles, Background),    (GitShow, Background),    (GitCommitDetails, Background),    (SetIndexText, Background),    (Push, Background),    (Fetch, Background),    (GetRemotes, Background),    (GetRemotesResponse, Background),    (Pull, Background),); request_messages!(    (AcceptTermsOfService, AcceptTermsOfServiceResponse),    (ApplyCodeAction, ApplyCodeActionResponse),    (        ApplyCompletionAdditionalEdits,        ApplyCompletionAdditionalEditsResponse    ),    (Call, Ack),    (CancelCall, Ack),    (Commit, Ack),    (CopyProjectEntry, ProjectEntryResponse),    (ComputeEmbeddings, ComputeEmbeddingsResponse),    (CreateChannel, CreateChannelResponse),    (CreateProjectEntry, ProjectEntryResponse),    (CreateRoom, CreateRoomResponse),    (DeclineCall, Ack),    (DeleteChannel, Ack),    (DeleteProjectEntry, ProjectEntryResponse),    (ExpandProjectEntry, ExpandProjectEntryResponse),    (ExpandAllForProjectEntry, ExpandAllForProjectEntryResponse),    (Follow, FollowResponse),    (FormatBuffers, FormatBuffersResponse),    (FuzzySearchUsers, UsersResponse),    (GetCachedEmbeddings, GetCachedEmbeddingsResponse),    (GetChannelMembers, GetChannelMembersResponse),    (GetChannelMessages, GetChannelMessagesResponse),    (GetChannelMessagesById, GetChannelMessagesResponse),    (GetCodeActions, GetCodeActionsResponse),    (GetCompletions, GetCompletionsResponse),    (GetDefinition, GetDefinitionResponse),    (GetDeclaration, GetDeclarationResponse),    (GetImplementation, GetImplementationResponse),    (GetDocumentHighlights, GetDocumentHighlightsResponse),    (GetHover, GetHoverResponse),    (GetLlmToken, GetLlmTokenResponse),    (GetNotifications, GetNotificationsResponse),    (GetPrivateUserInfo, GetPrivateUserInfoResponse),    (GetProjectSymbols, GetProjectSymbolsResponse),    (GetReferences, GetReferencesResponse),    (GetSignatureHelp, GetSignatureHelpResponse),    (OpenUnstagedDiff, OpenUnstagedDiffResponse),    (OpenUncommittedDiff, OpenUncommittedDiffResponse),    (GetSupermavenApiKey, GetSupermavenApiKeyResponse),    (GetTypeDefinition, GetTypeDefinitionResponse),    (LinkedEditingRange, LinkedEditingRangeResponse),    (ListRemoteDirectory, ListRemoteDirectoryResponse),    (GetUsers, UsersResponse),

Lines 1–500 of 872.