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