proto.rs

  1#![allow(non_snake_case)]
  2
  3pub mod error;
  4mod macros;
  5mod typed_envelope;
  6
  7pub use error::*;
  8pub use prost::{DecodeError, Message};
  9use std::{
 10    cmp,
 11    fmt::Debug,
 12    iter, mem,
 13    time::{Duration, SystemTime, UNIX_EPOCH},
 14};
 15pub use typed_envelope::*;
 16
 17include!(concat!(env!("OUT_DIR"), "/zed.messages.rs"));
 18
 19pub const SSH_PEER_ID: PeerId = PeerId { owner_id: 0, id: 0 };
 20pub const SSH_PROJECT_ID: u64 = 0;
 21
 22messages!(
 23    (AcceptTermsOfService, Foreground),
 24    (AcceptTermsOfServiceResponse, Foreground),
 25    (Ack, Foreground),
 26    (AckBufferOperation, Background),
 27    (AckChannelMessage, Background),
 28    (ActivateToolchain, Foreground),
 29    (ActiveToolchain, Foreground),
 30    (ActiveToolchainResponse, Foreground),
 31    (AddNotification, Foreground),
 32    (AddProjectCollaborator, Foreground),
 33    (AddWorktree, Foreground),
 34    (AddWorktreeResponse, Foreground),
 35    (AdvertiseContexts, Foreground),
 36    (ApplyCodeAction, Background),
 37    (ApplyCodeActionResponse, Background),
 38    (ApplyCompletionAdditionalEdits, Background),
 39    (ApplyCompletionAdditionalEditsResponse, Background),
 40    (BlameBuffer, Foreground),
 41    (BlameBufferResponse, Foreground),
 42    (BufferReloaded, Foreground),
 43    (BufferSaved, Foreground),
 44    (Call, Foreground),
 45    (CallCanceled, Foreground),
 46    (CancelCall, Foreground),
 47    (CancelLanguageServerWork, Foreground),
 48    (ChannelMessageSent, Foreground),
 49    (ChannelMessageUpdate, Foreground),
 50    (CloseBuffer, Foreground),
 51    (Commit, Background),
 52    (ComputeEmbeddings, Background),
 53    (ComputeEmbeddingsResponse, Background),
 54    (CopyProjectEntry, Foreground),
 55    (CountLanguageModelTokens, Background),
 56    (CountLanguageModelTokensResponse, Background),
 57    (CreateBufferForPeer, Foreground),
 58    (CreateChannel, Foreground),
 59    (CreateChannelResponse, Foreground),
 60    (CreateContext, Foreground),
 61    (CreateContextResponse, Foreground),
 62    (CreateProjectEntry, Foreground),
 63    (CreateRoom, Foreground),
 64    (CreateRoomResponse, Foreground),
 65    (DeclineCall, Foreground),
 66    (DeleteChannel, Foreground),
 67    (DeleteNotification, Foreground),
 68    (DeleteProjectEntry, Foreground),
 69    (EndStream, Foreground),
 70    (Error, Foreground),
 71    (ExpandProjectEntry, Foreground),
 72    (ExpandProjectEntryResponse, Foreground),
 73    (FindSearchCandidatesResponse, Background),
 74    (FindSearchCandidates, Background),
 75    (FlushBufferedMessages, Foreground),
 76    (ExpandAllForProjectEntry, Foreground),
 77    (ExpandAllForProjectEntryResponse, Foreground),
 78    (Follow, Foreground),
 79    (FollowResponse, Foreground),
 80    (ApplyCodeActionKind, Foreground),
 81    (ApplyCodeActionKindResponse, Foreground),
 82    (FormatBuffers, Foreground),
 83    (FormatBuffersResponse, Foreground),
 84    (FuzzySearchUsers, Foreground),
 85    (GetCachedEmbeddings, Background),
 86    (GetCachedEmbeddingsResponse, Background),
 87    (GetChannelMembers, Foreground),
 88    (GetChannelMembersResponse, Foreground),
 89    (GetChannelMessages, Background),
 90    (GetChannelMessagesById, Background),
 91    (GetChannelMessagesResponse, Background),
 92    (GetCodeActions, Background),
 93    (GetCodeActionsResponse, Background),
 94    (GetCompletions, Background),
 95    (GetCompletionsResponse, Background),
 96    (GetDeclaration, Background),
 97    (GetDeclarationResponse, Background),
 98    (GetDefinition, Background),
 99    (GetDefinitionResponse, Background),
100    (GetDocumentHighlights, Background),
101    (GetDocumentHighlightsResponse, Background),
102    (GetDocumentSymbols, Background),
103    (GetDocumentSymbolsResponse, Background),
104    (GetHover, Background),
105    (GetHoverResponse, Background),
106    (GetNotifications, Foreground),
107    (GetNotificationsResponse, Foreground),
108    (GetPanicFiles, Background),
109    (GetPanicFilesResponse, Background),
110    (GetPathMetadata, Background),
111    (GetPathMetadataResponse, Background),
112    (GetPermalinkToLine, Foreground),
113    (GetPermalinkToLineResponse, Foreground),
114    (GetPrivateUserInfo, Foreground),
115    (GetPrivateUserInfoResponse, Foreground),
116    (GetProjectSymbols, Background),
117    (GetProjectSymbolsResponse, Background),
118    (GetReferences, Background),
119    (GetReferencesResponse, Background),
120    (GetSignatureHelp, Background),
121    (GetSignatureHelpResponse, Background),
122    (GetSupermavenApiKey, Background),
123    (GetSupermavenApiKeyResponse, Background),
124    (GetTypeDefinition, Background),
125    (GetTypeDefinitionResponse, Background),
126    (GetImplementation, Background),
127    (GetImplementationResponse, Background),
128    (GetLlmToken, Background),
129    (GetLlmTokenResponse, Background),
130    (LanguageServerIdForName, Background),
131    (LanguageServerIdForNameResponse, Background),
132    (OpenUnstagedDiff, Foreground),
133    (OpenUnstagedDiffResponse, Foreground),
134    (OpenUncommittedDiff, Foreground),
135    (OpenUncommittedDiffResponse, Foreground),
136    (GetUsers, Foreground),
137    (GitGetBranches, Background),
138    (GitBranchesResponse, Background),
139    (Hello, Foreground),
140    (HideToast, Background),
141    (IncomingCall, Foreground),
142    (InlayHints, Background),
143    (InlayHintsResponse, Background),
144    (InstallExtension, Background),
145    (InviteChannelMember, Foreground),
146    (JoinChannel, Foreground),
147    (JoinChannelBuffer, Foreground),
148    (JoinChannelBufferResponse, Foreground),
149    (JoinChannelChat, Foreground),
150    (JoinChannelChatResponse, Foreground),
151    (JoinProject, Foreground),
152    (JoinProjectResponse, Foreground),
153    (JoinRoom, Foreground),
154    (JoinRoomResponse, Foreground),
155    (LanguageServerLog, Foreground),
156    (LanguageServerPromptRequest, Foreground),
157    (LanguageServerPromptResponse, Foreground),
158    (LeaveChannelBuffer, Background),
159    (LeaveChannelChat, Foreground),
160    (LeaveProject, Foreground),
161    (LeaveRoom, Foreground),
162    (LinkedEditingRange, Background),
163    (LinkedEditingRangeResponse, Background),
164    (ListRemoteDirectory, Background),
165    (ListRemoteDirectoryResponse, Background),
166    (ListToolchains, Foreground),
167    (ListToolchainsResponse, Foreground),
168    (LoadCommitDiff, Foreground),
169    (LoadCommitDiffResponse, Foreground),
170    (LspExtExpandMacro, Background),
171    (LspExtExpandMacroResponse, Background),
172    (LspExtOpenDocs, Background),
173    (LspExtOpenDocsResponse, Background),
174    (LspExtRunnables, Background),
175    (LspExtRunnablesResponse, Background),
176    (LspExtSwitchSourceHeader, Background),
177    (LspExtSwitchSourceHeaderResponse, Background),
178    (MarkNotificationRead, Foreground),
179    (MoveChannel, Foreground),
180    (MultiLspQuery, Background),
181    (MultiLspQueryResponse, Background),
182    (OnTypeFormatting, Background),
183    (OnTypeFormattingResponse, Background),
184    (OpenBufferById, Background),
185    (OpenBufferByPath, Background),
186    (OpenBufferForSymbol, Background),
187    (OpenBufferForSymbolResponse, Background),
188    (OpenBufferResponse, Background),
189    (OpenCommitMessageBuffer, Background),
190    (OpenContext, Foreground),
191    (OpenContextResponse, Foreground),
192    (OpenNewBuffer, Foreground),
193    (OpenServerSettings, Foreground),
194    (PerformRename, Background),
195    (PerformRenameResponse, Background),
196    (Ping, Foreground),
197    (PrepareRename, Background),
198    (PrepareRenameResponse, Background),
199    (ProjectEntryResponse, Foreground),
200    (RefreshInlayHints, Foreground),
201    (RefreshLlmToken, Background),
202    (RegisterBufferWithLanguageServers, Background),
203    (RejoinChannelBuffers, Foreground),
204    (RejoinChannelBuffersResponse, Foreground),
205    (RejoinRemoteProjects, Foreground),
206    (RejoinRemoteProjectsResponse, Foreground),
207    (RejoinRoom, Foreground),
208    (RejoinRoomResponse, Foreground),
209    (ReloadBuffers, Foreground),
210    (ReloadBuffersResponse, Foreground),
211    (RemoveChannelMember, Foreground),
212    (RemoveChannelMessage, Foreground),
213    (RemoveContact, Foreground),
214    (RemoveProjectCollaborator, Foreground),
215    (RemoveWorktree, Foreground),
216    (RenameChannel, Foreground),
217    (RenameChannelResponse, Foreground),
218    (RenameProjectEntry, Foreground),
219    (RequestContact, Foreground),
220    (ResolveCompletionDocumentation, Background),
221    (ResolveCompletionDocumentationResponse, Background),
222    (ResolveInlayHint, Background),
223    (ResolveInlayHintResponse, Background),
224    (RefreshCodeLens, Background),
225    (GetCodeLens, Background),
226    (GetCodeLensResponse, Background),
227    (RespondToChannelInvite, Foreground),
228    (RespondToContactRequest, Foreground),
229    (RestartLanguageServers, Foreground),
230    (StopLanguageServers, Background),
231    (RoomUpdated, Foreground),
232    (SaveBuffer, Foreground),
233    (SendChannelMessage, Background),
234    (SendChannelMessageResponse, Background),
235    (SetChannelMemberRole, Foreground),
236    (SetChannelVisibility, Foreground),
237    (SetRoomParticipantRole, Foreground),
238    (ShareProject, Foreground),
239    (ShareProjectResponse, Foreground),
240    (ShowContacts, Foreground),
241    (ShutdownRemoteServer, Foreground),
242    (Stage, Background),
243    (StartLanguageServer, Foreground),
244    (SubscribeToChannels, Foreground),
245    (SyncExtensions, Background),
246    (SyncExtensionsResponse, Background),
247    (BreakpointsForFile, Background),
248    (ToggleBreakpoint, Foreground),
249    (SynchronizeBuffers, Foreground),
250    (SynchronizeBuffersResponse, Foreground),
251    (SynchronizeContexts, Foreground),
252    (SynchronizeContextsResponse, Foreground),
253    (TaskContext, Background),
254    (TaskContextForLocation, Background),
255    (Test, Foreground),
256    (Toast, Background),
257    (Unfollow, Foreground),
258    (UnshareProject, Foreground),
259    (Unstage, Background),
260    (UpdateBuffer, Foreground),
261    (UpdateBufferFile, Foreground),
262    (UpdateChannelBuffer, Foreground),
263    (UpdateChannelBufferCollaborators, Foreground),
264    (UpdateChannelMessage, Foreground),
265    (UpdateChannels, Foreground),
266    (UpdateContacts, Foreground),
267    (UpdateContext, Foreground),
268    (UpdateDiagnosticSummary, Foreground),
269    (UpdateDiffBases, Foreground),
270    (UpdateFollowers, Foreground),
271    (UpdateGitBranch, Background),
272    (UpdateInviteInfo, Foreground),
273    (UpdateLanguageServer, Foreground),
274    (UpdateNotification, Foreground),
275    (UpdateParticipantLocation, Foreground),
276    (UpdateProject, Foreground),
277    (UpdateProjectCollaborator, Foreground),
278    (UpdateUserChannels, Foreground),
279    (UpdateUserPlan, Foreground),
280    (UpdateWorktree, Foreground),
281    (UpdateWorktreeSettings, Foreground),
282    (UpdateRepository, Foreground),
283    (RemoveRepository, Foreground),
284    (UsersResponse, Foreground),
285    (GitReset, Background),
286    (GitCheckoutFiles, Background),
287    (GitShow, Background),
288    (GitCommitDetails, Background),
289    (SetIndexText, Background),
290    (Push, Background),
291    (Fetch, Background),
292    (GetRemotes, Background),
293    (GetRemotesResponse, Background),
294    (Pull, Background),
295    (RemoteMessageResponse, Background),
296    (AskPassRequest, Background),
297    (AskPassResponse, Background),
298    (GitCreateBranch, Background),
299    (GitChangeBranch, Background),
300    (CheckForPushedCommits, Background),
301    (CheckForPushedCommitsResponse, Background),
302    (GitDiff, Background),
303    (GitDiffResponse, Background),
304    (GitInit, Background),
305);
306
307request_messages!(
308    (AcceptTermsOfService, AcceptTermsOfServiceResponse),
309    (ApplyCodeAction, ApplyCodeActionResponse),
310    (
311        ApplyCompletionAdditionalEdits,
312        ApplyCompletionAdditionalEditsResponse
313    ),
314    (Call, Ack),
315    (CancelCall, Ack),
316    (Commit, Ack),
317    (CopyProjectEntry, ProjectEntryResponse),
318    (ComputeEmbeddings, ComputeEmbeddingsResponse),
319    (CreateChannel, CreateChannelResponse),
320    (CreateProjectEntry, ProjectEntryResponse),
321    (CreateRoom, CreateRoomResponse),
322    (DeclineCall, Ack),
323    (DeleteChannel, Ack),
324    (DeleteProjectEntry, ProjectEntryResponse),
325    (ExpandProjectEntry, ExpandProjectEntryResponse),
326    (ExpandAllForProjectEntry, ExpandAllForProjectEntryResponse),
327    (Follow, FollowResponse),
328    (ApplyCodeActionKind, ApplyCodeActionKindResponse),
329    (FormatBuffers, FormatBuffersResponse),
330    (FuzzySearchUsers, UsersResponse),
331    (GetCachedEmbeddings, GetCachedEmbeddingsResponse),
332    (GetChannelMembers, GetChannelMembersResponse),
333    (GetChannelMessages, GetChannelMessagesResponse),
334    (GetChannelMessagesById, GetChannelMessagesResponse),
335    (GetCodeActions, GetCodeActionsResponse),
336    (GetCompletions, GetCompletionsResponse),
337    (GetDefinition, GetDefinitionResponse),
338    (GetDeclaration, GetDeclarationResponse),
339    (GetImplementation, GetImplementationResponse),
340    (GetDocumentHighlights, GetDocumentHighlightsResponse),
341    (GetDocumentSymbols, GetDocumentSymbolsResponse),
342    (GetHover, GetHoverResponse),
343    (GetLlmToken, GetLlmTokenResponse),
344    (GetNotifications, GetNotificationsResponse),
345    (GetPrivateUserInfo, GetPrivateUserInfoResponse),
346    (GetProjectSymbols, GetProjectSymbolsResponse),
347    (GetReferences, GetReferencesResponse),
348    (GetSignatureHelp, GetSignatureHelpResponse),
349    (OpenUnstagedDiff, OpenUnstagedDiffResponse),
350    (OpenUncommittedDiff, OpenUncommittedDiffResponse),
351    (GetSupermavenApiKey, GetSupermavenApiKeyResponse),
352    (GetTypeDefinition, GetTypeDefinitionResponse),
353    (LinkedEditingRange, LinkedEditingRangeResponse),
354    (ListRemoteDirectory, ListRemoteDirectoryResponse),
355    (GetUsers, UsersResponse),
356    (IncomingCall, Ack),
357    (InlayHints, InlayHintsResponse),
358    (GetCodeLens, GetCodeLensResponse),
359    (InviteChannelMember, Ack),
360    (JoinChannel, JoinRoomResponse),
361    (JoinChannelBuffer, JoinChannelBufferResponse),
362    (JoinChannelChat, JoinChannelChatResponse),
363    (JoinProject, JoinProjectResponse),
364    (JoinRoom, JoinRoomResponse),
365    (LeaveChannelBuffer, Ack),
366    (LeaveRoom, Ack),
367    (LoadCommitDiff, LoadCommitDiffResponse),
368    (MarkNotificationRead, Ack),
369    (MoveChannel, Ack),
370    (OnTypeFormatting, OnTypeFormattingResponse),
371    (OpenBufferById, OpenBufferResponse),
372    (OpenBufferByPath, OpenBufferResponse),
373    (OpenBufferForSymbol, OpenBufferForSymbolResponse),
374    (OpenCommitMessageBuffer, OpenBufferResponse),
375    (OpenNewBuffer, OpenBufferResponse),
376    (PerformRename, PerformRenameResponse),
377    (Ping, Ack),
378    (PrepareRename, PrepareRenameResponse),
379    (CountLanguageModelTokens, CountLanguageModelTokensResponse),
380    (RefreshInlayHints, Ack),
381    (RefreshCodeLens, Ack),
382    (RejoinChannelBuffers, RejoinChannelBuffersResponse),
383    (RejoinRoom, RejoinRoomResponse),
384    (ReloadBuffers, ReloadBuffersResponse),
385    (RemoveChannelMember, Ack),
386    (RemoveChannelMessage, Ack),
387    (UpdateChannelMessage, Ack),
388    (RemoveContact, Ack),
389    (RenameChannel, RenameChannelResponse),
390    (RenameProjectEntry, ProjectEntryResponse),
391    (RequestContact, Ack),
392    (
393        ResolveCompletionDocumentation,
394        ResolveCompletionDocumentationResponse
395    ),
396    (ResolveInlayHint, ResolveInlayHintResponse),
397    (RespondToChannelInvite, Ack),
398    (RespondToContactRequest, Ack),
399    (SaveBuffer, BufferSaved),
400    (Stage, Ack),
401    (FindSearchCandidates, FindSearchCandidatesResponse),
402    (SendChannelMessage, SendChannelMessageResponse),
403    (SetChannelMemberRole, Ack),
404    (SetChannelVisibility, Ack),
405    (ShareProject, ShareProjectResponse),
406    (SynchronizeBuffers, SynchronizeBuffersResponse),
407    (TaskContextForLocation, TaskContext),
408    (Test, Test),
409    (Unstage, Ack),
410    (UpdateBuffer, Ack),
411    (UpdateParticipantLocation, Ack),
412    (UpdateProject, Ack),
413    (UpdateWorktree, Ack),
414    (UpdateRepository, Ack),
415    (RemoveRepository, Ack),
416    (LanguageServerIdForName, LanguageServerIdForNameResponse),
417    (LspExtExpandMacro, LspExtExpandMacroResponse),
418    (LspExtOpenDocs, LspExtOpenDocsResponse),
419    (LspExtRunnables, LspExtRunnablesResponse),
420    (SetRoomParticipantRole, Ack),
421    (BlameBuffer, BlameBufferResponse),
422    (RejoinRemoteProjects, RejoinRemoteProjectsResponse),
423    (MultiLspQuery, MultiLspQueryResponse),
424    (RestartLanguageServers, Ack),
425    (StopLanguageServers, Ack),
426    (OpenContext, OpenContextResponse),
427    (CreateContext, CreateContextResponse),
428    (SynchronizeContexts, SynchronizeContextsResponse),
429    (LspExtSwitchSourceHeader, LspExtSwitchSourceHeaderResponse),
430    (AddWorktree, AddWorktreeResponse),
431    (ShutdownRemoteServer, Ack),
432    (RemoveWorktree, Ack),
433    (OpenServerSettings, OpenBufferResponse),
434    (GetPermalinkToLine, GetPermalinkToLineResponse),
435    (FlushBufferedMessages, Ack),
436    (LanguageServerPromptRequest, LanguageServerPromptResponse),
437    (GitGetBranches, GitBranchesResponse),
438    (UpdateGitBranch, Ack),
439    (ListToolchains, ListToolchainsResponse),
440    (ActivateToolchain, Ack),
441    (ActiveToolchain, ActiveToolchainResponse),
442    (GetPathMetadata, GetPathMetadataResponse),
443    (GetPanicFiles, GetPanicFilesResponse),
444    (CancelLanguageServerWork, Ack),
445    (SyncExtensions, SyncExtensionsResponse),
446    (InstallExtension, Ack),
447    (RegisterBufferWithLanguageServers, Ack),
448    (GitShow, GitCommitDetails),
449    (GitReset, Ack),
450    (GitCheckoutFiles, Ack),
451    (SetIndexText, Ack),
452    (Push, RemoteMessageResponse),
453    (Fetch, RemoteMessageResponse),
454    (GetRemotes, GetRemotesResponse),
455    (Pull, RemoteMessageResponse),
456    (AskPassRequest, AskPassResponse),
457    (GitCreateBranch, Ack),
458    (GitChangeBranch, Ack),
459    (CheckForPushedCommits, CheckForPushedCommitsResponse),
460    (GitDiff, GitDiffResponse),
461    (GitInit, Ack),
462    (ToggleBreakpoint, Ack),
463);
464
465entity_messages!(
466    {project_id, ShareProject},
467    AddProjectCollaborator,
468    AddWorktree,
469    ApplyCodeAction,
470    ApplyCompletionAdditionalEdits,
471    BlameBuffer,
472    BufferReloaded,
473    BufferSaved,
474    CloseBuffer,
475    Commit,
476    CopyProjectEntry,
477    CreateBufferForPeer,
478    CreateProjectEntry,
479    DeleteProjectEntry,
480    ExpandProjectEntry,
481    ExpandAllForProjectEntry,
482    FindSearchCandidates,
483    ApplyCodeActionKind,
484    FormatBuffers,
485    GetCodeActions,
486    GetCodeLens,
487    GetCompletions,
488    GetDefinition,
489    GetDeclaration,
490    GetImplementation,
491    GetDocumentHighlights,
492    GetDocumentSymbols,
493    GetHover,
494    GetProjectSymbols,
495    GetReferences,
496    GetSignatureHelp,
497    OpenUnstagedDiff,
498    OpenUncommittedDiff,
499    GetTypeDefinition,
500    InlayHints,
501    JoinProject,
502    LeaveProject,
503    LinkedEditingRange,
504    LoadCommitDiff,
505    MultiLspQuery,
506    RestartLanguageServers,
507    StopLanguageServers,
508    OnTypeFormatting,
509    OpenNewBuffer,
510    OpenBufferById,
511    OpenBufferByPath,
512    OpenBufferForSymbol,
513    OpenCommitMessageBuffer,
514    PerformRename,
515    PrepareRename,
516    RefreshInlayHints,
517    RefreshCodeLens,
518    ReloadBuffers,
519    RemoveProjectCollaborator,
520    RenameProjectEntry,
521    ResolveCompletionDocumentation,
522    ResolveInlayHint,
523    SaveBuffer,
524    Stage,
525    StartLanguageServer,
526    SynchronizeBuffers,
527    TaskContextForLocation,
528    UnshareProject,
529    Unstage,
530    UpdateBuffer,
531    UpdateBufferFile,
532    UpdateDiagnosticSummary,
533    UpdateDiffBases,
534    UpdateLanguageServer,
535    UpdateProject,
536    UpdateProjectCollaborator,
537    UpdateWorktree,
538    UpdateRepository,
539    RemoveRepository,
540    UpdateWorktreeSettings,
541    LspExtExpandMacro,
542    LspExtOpenDocs,
543    LspExtRunnables,
544    AdvertiseContexts,
545    OpenContext,
546    CreateContext,
547    UpdateContext,
548    SynchronizeContexts,
549    LspExtSwitchSourceHeader,
550    LanguageServerLog,
551    Toast,
552    HideToast,
553    OpenServerSettings,
554    GetPermalinkToLine,
555    LanguageServerPromptRequest,
556    LanguageServerIdForName,
557    GitGetBranches,
558    UpdateGitBranch,
559    ListToolchains,
560    ActivateToolchain,
561    ActiveToolchain,
562    GetPathMetadata,
563    CancelLanguageServerWork,
564    RegisterBufferWithLanguageServers,
565    GitShow,
566    GitReset,
567    GitCheckoutFiles,
568    SetIndexText,
569
570    Push,
571    Fetch,
572    GetRemotes,
573    Pull,
574    AskPassRequest,
575    GitChangeBranch,
576    GitCreateBranch,
577    CheckForPushedCommits,
578    GitDiff,
579    GitInit,
580    BreakpointsForFile,
581    ToggleBreakpoint,
582);
583
584entity_messages!(
585    {channel_id, Channel},
586    ChannelMessageSent,
587    ChannelMessageUpdate,
588    RemoveChannelMessage,
589    UpdateChannelMessage,
590    UpdateChannelBuffer,
591    UpdateChannelBufferCollaborators,
592);
593
594impl From<Timestamp> for SystemTime {
595    fn from(val: Timestamp) -> Self {
596        UNIX_EPOCH
597            .checked_add(Duration::new(val.seconds, val.nanos))
598            .unwrap()
599    }
600}
601
602impl From<SystemTime> for Timestamp {
603    fn from(time: SystemTime) -> Self {
604        let duration = time.duration_since(UNIX_EPOCH).unwrap();
605        Self {
606            seconds: duration.as_secs(),
607            nanos: duration.subsec_nanos(),
608        }
609    }
610}
611
612impl From<u128> for Nonce {
613    fn from(nonce: u128) -> Self {
614        let upper_half = (nonce >> 64) as u64;
615        let lower_half = nonce as u64;
616        Self {
617            upper_half,
618            lower_half,
619        }
620    }
621}
622
623impl From<Nonce> for u128 {
624    fn from(nonce: Nonce) -> Self {
625        let upper_half = (nonce.upper_half as u128) << 64;
626        let lower_half = nonce.lower_half as u128;
627        upper_half | lower_half
628    }
629}
630
631#[cfg(any(test, feature = "test-support"))]
632pub const MAX_WORKTREE_UPDATE_MAX_CHUNK_SIZE: usize = 2;
633#[cfg(not(any(test, feature = "test-support")))]
634pub const MAX_WORKTREE_UPDATE_MAX_CHUNK_SIZE: usize = 256;
635
636pub fn split_worktree_update(mut message: UpdateWorktree) -> impl Iterator<Item = UpdateWorktree> {
637    let mut done = false;
638
639    iter::from_fn(move || {
640        if done {
641            return None;
642        }
643
644        let updated_entries_chunk_size = cmp::min(
645            message.updated_entries.len(),
646            MAX_WORKTREE_UPDATE_MAX_CHUNK_SIZE,
647        );
648        let updated_entries: Vec<_> = message
649            .updated_entries
650            .drain(..updated_entries_chunk_size)
651            .collect();
652
653        let removed_entries_chunk_size = cmp::min(
654            message.removed_entries.len(),
655            MAX_WORKTREE_UPDATE_MAX_CHUNK_SIZE,
656        );
657        let removed_entries = message
658            .removed_entries
659            .drain(..removed_entries_chunk_size)
660            .collect();
661
662        let mut updated_repositories = Vec::new();
663        let mut limit = MAX_WORKTREE_UPDATE_MAX_CHUNK_SIZE;
664        while let Some(repo) = message.updated_repositories.first_mut() {
665            let updated_statuses_limit = cmp::min(repo.updated_statuses.len(), limit);
666            let removed_statuses_limit = cmp::min(repo.removed_statuses.len(), limit);
667
668            updated_repositories.push(RepositoryEntry {
669                repository_id: repo.repository_id,
670                branch_summary: repo.branch_summary.clone(),
671                updated_statuses: repo
672                    .updated_statuses
673                    .drain(..updated_statuses_limit)
674                    .collect(),
675                removed_statuses: repo
676                    .removed_statuses
677                    .drain(..removed_statuses_limit)
678                    .collect(),
679                current_merge_conflicts: repo.current_merge_conflicts.clone(),
680            });
681            if repo.removed_statuses.is_empty() && repo.updated_statuses.is_empty() {
682                message.updated_repositories.remove(0);
683            }
684            limit = limit.saturating_sub(removed_statuses_limit + updated_statuses_limit);
685            if limit == 0 {
686                break;
687            }
688        }
689
690        done = message.updated_entries.is_empty()
691            && message.removed_entries.is_empty()
692            && message.updated_repositories.is_empty();
693
694        let removed_repositories = if done {
695            mem::take(&mut message.removed_repositories)
696        } else {
697            Default::default()
698        };
699
700        Some(UpdateWorktree {
701            project_id: message.project_id,
702            worktree_id: message.worktree_id,
703            root_name: message.root_name.clone(),
704            abs_path: message.abs_path.clone(),
705            updated_entries,
706            removed_entries,
707            scan_id: message.scan_id,
708            is_last_update: done && message.is_last_update,
709            updated_repositories,
710            removed_repositories,
711        })
712    })
713}
714
715pub fn split_repository_update(
716    mut update: UpdateRepository,
717) -> impl Iterator<Item = UpdateRepository> {
718    let mut updated_statuses_iter = mem::take(&mut update.updated_statuses).into_iter().fuse();
719    let mut removed_statuses_iter = mem::take(&mut update.removed_statuses).into_iter().fuse();
720    std::iter::from_fn({
721        let update = update.clone();
722        move || {
723            let updated_statuses = updated_statuses_iter
724                .by_ref()
725                .take(MAX_WORKTREE_UPDATE_MAX_CHUNK_SIZE)
726                .collect::<Vec<_>>();
727            let removed_statuses = removed_statuses_iter
728                .by_ref()
729                .take(MAX_WORKTREE_UPDATE_MAX_CHUNK_SIZE)
730                .collect::<Vec<_>>();
731            if updated_statuses.is_empty() && removed_statuses.is_empty() {
732                return None;
733            }
734            Some(UpdateRepository {
735                updated_statuses,
736                removed_statuses,
737                is_last_update: false,
738                ..update.clone()
739            })
740        }
741    })
742    .chain([UpdateRepository {
743        updated_statuses: Vec::new(),
744        removed_statuses: Vec::new(),
745        is_last_update: true,
746        ..update
747    }])
748}
749
750#[cfg(test)]
751mod tests {
752    use super::*;
753
754    #[test]
755    fn test_converting_peer_id_from_and_to_u64() {
756        let peer_id = PeerId {
757            owner_id: 10,
758            id: 3,
759        };
760        assert_eq!(PeerId::from_u64(peer_id.as_u64()), peer_id);
761        let peer_id = PeerId {
762            owner_id: u32::MAX,
763            id: 3,
764        };
765        assert_eq!(PeerId::from_u64(peer_id.as_u64()), peer_id);
766        let peer_id = PeerId {
767            owner_id: 10,
768            id: u32::MAX,
769        };
770        assert_eq!(PeerId::from_u64(peer_id.as_u64()), peer_id);
771        let peer_id = PeerId {
772            owner_id: u32::MAX,
773            id: u32::MAX,
774        };
775        assert_eq!(PeerId::from_u64(peer_id.as_u64()), peer_id);
776    }
777
778    #[test]
779    #[cfg(target_os = "windows")]
780    fn test_proto() {
781        use std::path::PathBuf;
782
783        fn generate_proto_path(path: PathBuf) -> PathBuf {
784            let proto = path.to_proto();
785            PathBuf::from_proto(proto)
786        }
787
788        let path = PathBuf::from("C:\\foo\\bar");
789        assert_eq!(path, generate_proto_path(path.clone()));
790
791        let path = PathBuf::from("C:/foo/bar/");
792        assert_eq!(path, generate_proto_path(path.clone()));
793
794        let path = PathBuf::from("C:/foo\\bar\\");
795        assert_eq!(path, generate_proto_path(path.clone()));
796    }
797}