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