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