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