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