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    (GetCrashFiles, Background),
103    (GetCrashFilesResponse, Background),
104    (GetPathMetadata, Background),
105    (GetPathMetadataResponse, Background),
106    (GetPermalinkToLine, Foreground),
107    (GetPermalinkToLineResponse, Foreground),
108    (GetProjectSymbols, Background),
109    (GetProjectSymbolsResponse, Background),
110    (GetReferences, Background),
111    (GetReferencesResponse, Background),
112    (GetSignatureHelp, Background),
113    (GetSignatureHelpResponse, Background),
114    (GetSupermavenApiKey, Background),
115    (GetSupermavenApiKeyResponse, Background),
116    (GetTypeDefinition, Background),
117    (GetTypeDefinitionResponse, Background),
118    (GetImplementation, Background),
119    (GetImplementationResponse, Background),
120    (OpenUnstagedDiff, Foreground),
121    (OpenUnstagedDiffResponse, Foreground),
122    (OpenUncommittedDiff, Foreground),
123    (OpenUncommittedDiffResponse, Foreground),
124    (GetUsers, Foreground),
125    (GitGetBranches, Background),
126    (GitBranchesResponse, Background),
127    (Hello, Foreground),
128    (HideToast, Background),
129    (IncomingCall, Foreground),
130    (InlayHints, Background),
131    (InlayHintsResponse, Background),
132    (InstallExtension, Background),
133    (InviteChannelMember, Foreground),
134    (JoinChannel, Foreground),
135    (JoinChannelBuffer, Foreground),
136    (JoinChannelBufferResponse, Foreground),
137    (JoinChannelChat, Foreground),
138    (JoinChannelChatResponse, Foreground),
139    (JoinProject, Foreground),
140    (JoinProjectResponse, Foreground),
141    (JoinRoom, Foreground),
142    (JoinRoomResponse, Foreground),
143    (LanguageServerLog, Foreground),
144    (LanguageServerPromptRequest, Foreground),
145    (LanguageServerPromptResponse, Foreground),
146    (LeaveChannelBuffer, Background),
147    (LeaveChannelChat, Foreground),
148    (LeaveProject, Foreground),
149    (LeaveRoom, Foreground),
150    (LinkedEditingRange, Background),
151    (LinkedEditingRangeResponse, Background),
152    (ListRemoteDirectory, Background),
153    (ListRemoteDirectoryResponse, Background),
154    (ListToolchains, Foreground),
155    (ListToolchainsResponse, Foreground),
156    (LoadCommitDiff, Foreground),
157    (LoadCommitDiffResponse, Foreground),
158    (LspExtExpandMacro, Background),
159    (LspExtExpandMacroResponse, Background),
160    (LspExtOpenDocs, Background),
161    (LspExtOpenDocsResponse, Background),
162    (LspExtRunnables, Background),
163    (LspExtRunnablesResponse, Background),
164    (LspExtSwitchSourceHeader, Background),
165    (LspExtSwitchSourceHeaderResponse, Background),
166    (LspExtGoToParentModule, Background),
167    (LspExtGoToParentModuleResponse, Background),
168    (LspExtCancelFlycheck, Background),
169    (LspExtRunFlycheck, Background),
170    (LspExtClearFlycheck, Background),
171    (MarkNotificationRead, Foreground),
172    (MoveChannel, Foreground),
173    (ReorderChannel, Foreground),
174    (MultiLspQuery, Background),
175    (MultiLspQueryResponse, Background),
176    (OnTypeFormatting, Background),
177    (OnTypeFormattingResponse, Background),
178    (OpenBufferById, Background),
179    (OpenBufferByPath, Background),
180    (OpenBufferForSymbol, Background),
181    (OpenBufferForSymbolResponse, Background),
182    (OpenBufferResponse, Background),
183    (OpenCommitMessageBuffer, Background),
184    (OpenContext, Foreground),
185    (OpenContextResponse, Foreground),
186    (OpenNewBuffer, Foreground),
187    (OpenServerSettings, Foreground),
188    (PerformRename, Background),
189    (PerformRenameResponse, Background),
190    (Ping, Foreground),
191    (PrepareRename, Background),
192    (PrepareRenameResponse, Background),
193    (ProjectEntryResponse, Foreground),
194    (RefreshInlayHints, Foreground),
195    (RegisterBufferWithLanguageServers, Background),
196    (RejoinChannelBuffers, Foreground),
197    (RejoinChannelBuffersResponse, Foreground),
198    (RejoinRemoteProjects, Foreground),
199    (RejoinRemoteProjectsResponse, Foreground),
200    (RejoinRoom, Foreground),
201    (RejoinRoomResponse, Foreground),
202    (ReloadBuffers, Foreground),
203    (ReloadBuffersResponse, Foreground),
204    (RemoveChannelMember, Foreground),
205    (RemoveChannelMessage, Foreground),
206    (RemoveContact, Foreground),
207    (RemoveProjectCollaborator, Foreground),
208    (RemoveWorktree, Foreground),
209    (RenameChannel, Foreground),
210    (RenameChannelResponse, Foreground),
211    (RenameProjectEntry, Foreground),
212    (RequestContact, Foreground),
213    (ResolveCompletionDocumentation, Background),
214    (ResolveCompletionDocumentationResponse, Background),
215    (ResolveInlayHint, Background),
216    (ResolveInlayHintResponse, Background),
217    (GetDocumentColor, Background),
218    (GetDocumentColorResponse, Background),
219    (GetColorPresentation, Background),
220    (GetColorPresentationResponse, Background),
221    (RefreshCodeLens, Background),
222    (GetCodeLens, Background),
223    (GetCodeLensResponse, Background),
224    (RespondToChannelInvite, Foreground),
225    (RespondToContactRequest, Foreground),
226    (RestartLanguageServers, Foreground),
227    (StopLanguageServers, Background),
228    (RoomUpdated, Foreground),
229    (SaveBuffer, Foreground),
230    (SendChannelMessage, Background),
231    (SendChannelMessageResponse, Background),
232    (SetChannelMemberRole, Foreground),
233    (SetChannelVisibility, Foreground),
234    (SetRoomParticipantRole, Foreground),
235    (ShareProject, Foreground),
236    (ShareProjectResponse, Foreground),
237    (ShowContacts, Foreground),
238    (ShutdownRemoteServer, Foreground),
239    (Stage, Background),
240    (StartLanguageServer, Foreground),
241    (SubscribeToChannels, Foreground),
242    (SyncExtensions, Background),
243    (SyncExtensionsResponse, Background),
244    (BreakpointsForFile, Background),
245    (ToggleBreakpoint, Foreground),
246    (SynchronizeBuffers, Foreground),
247    (SynchronizeBuffersResponse, Foreground),
248    (SynchronizeContexts, Foreground),
249    (SynchronizeContextsResponse, Foreground),
250    (TaskContext, Background),
251    (TaskContextForLocation, Background),
252    (Test, Foreground),
253    (Toast, Background),
254    (Unfollow, Foreground),
255    (UnshareProject, Foreground),
256    (Unstage, Background),
257    (Stash, Background),
258    (StashPop, 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    (UpdateWorktree, Foreground),
279    (UpdateWorktreeSettings, Foreground),
280    (UpdateRepository, Foreground),
281    (RemoveRepository, Foreground),
282    (UsersResponse, Foreground),
283    (GitReset, Background),
284    (GitCheckoutFiles, Background),
285    (GitShow, Background),
286    (GitCommitDetails, Background),
287    (SetIndexText, Background),
288    (Push, Background),
289    (Fetch, Background),
290    (GetRemotes, Background),
291    (GetRemotesResponse, Background),
292    (Pull, Background),
293    (RemoteMessageResponse, Background),
294    (AskPassRequest, Background),
295    (AskPassResponse, Background),
296    (GitCreateBranch, Background),
297    (GitChangeBranch, Background),
298    (CheckForPushedCommits, Background),
299    (CheckForPushedCommitsResponse, Background),
300    (GitDiff, Background),
301    (GitDiffResponse, Background),
302    (GitInit, Background),
303    (GetDebugAdapterBinary, Background),
304    (DebugAdapterBinary, Background),
305    (RunDebugLocators, Background),
306    (DebugRequest, Background),
307    (LogToDebugConsole, Background),
308    (GetDocumentDiagnostics, Background),
309    (GetDocumentDiagnosticsResponse, Background),
310    (PullWorkspaceDiagnostics, Background),
311    (GetDefaultBranch, Background),
312    (GetDefaultBranchResponse, Background),
313    (GitClone, Background),
314    (GitCloneResponse, Background)
315);
316
317request_messages!(
318    (AcceptTermsOfService, AcceptTermsOfServiceResponse),
319    (ApplyCodeAction, ApplyCodeActionResponse),
320    (
321        ApplyCompletionAdditionalEdits,
322        ApplyCompletionAdditionalEditsResponse
323    ),
324    (Call, Ack),
325    (CancelCall, Ack),
326    (Commit, Ack),
327    (CopyProjectEntry, ProjectEntryResponse),
328    (CreateChannel, CreateChannelResponse),
329    (CreateProjectEntry, ProjectEntryResponse),
330    (CreateRoom, CreateRoomResponse),
331    (DeclineCall, Ack),
332    (DeleteChannel, Ack),
333    (DeleteProjectEntry, ProjectEntryResponse),
334    (ExpandProjectEntry, ExpandProjectEntryResponse),
335    (ExpandAllForProjectEntry, ExpandAllForProjectEntryResponse),
336    (Follow, FollowResponse),
337    (ApplyCodeActionKind, ApplyCodeActionKindResponse),
338    (FormatBuffers, FormatBuffersResponse),
339    (FuzzySearchUsers, UsersResponse),
340    (GetChannelMembers, GetChannelMembersResponse),
341    (GetChannelMessages, GetChannelMessagesResponse),
342    (GetChannelMessagesById, GetChannelMessagesResponse),
343    (GetCodeActions, GetCodeActionsResponse),
344    (GetCompletions, GetCompletionsResponse),
345    (GetDefinition, GetDefinitionResponse),
346    (GetDeclaration, GetDeclarationResponse),
347    (GetImplementation, GetImplementationResponse),
348    (GetDocumentHighlights, GetDocumentHighlightsResponse),
349    (GetDocumentSymbols, GetDocumentSymbolsResponse),
350    (GetHover, GetHoverResponse),
351    (GetNotifications, GetNotificationsResponse),
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    (GetDocumentColor, GetDocumentColorResponse),
404    (GetColorPresentation, GetColorPresentationResponse),
405    (RespondToChannelInvite, Ack),
406    (RespondToContactRequest, Ack),
407    (SaveBuffer, BufferSaved),
408    (Stage, Ack),
409    (FindSearchCandidates, FindSearchCandidatesResponse),
410    (SendChannelMessage, SendChannelMessageResponse),
411    (SetChannelMemberRole, Ack),
412    (SetChannelVisibility, Ack),
413    (ShareProject, ShareProjectResponse),
414    (SynchronizeBuffers, SynchronizeBuffersResponse),
415    (TaskContextForLocation, TaskContext),
416    (Test, Test),
417    (Unstage, Ack),
418    (Stash, Ack),
419    (StashPop, Ack),
420    (UpdateBuffer, Ack),
421    (UpdateParticipantLocation, Ack),
422    (UpdateProject, Ack),
423    (UpdateWorktree, Ack),
424    (UpdateRepository, Ack),
425    (RemoveRepository, Ack),
426    (LspExtExpandMacro, LspExtExpandMacroResponse),
427    (LspExtOpenDocs, LspExtOpenDocsResponse),
428    (LspExtRunnables, LspExtRunnablesResponse),
429    (SetRoomParticipantRole, Ack),
430    (BlameBuffer, BlameBufferResponse),
431    (RejoinRemoteProjects, RejoinRemoteProjectsResponse),
432    (MultiLspQuery, MultiLspQueryResponse),
433    (RestartLanguageServers, Ack),
434    (StopLanguageServers, Ack),
435    (OpenContext, OpenContextResponse),
436    (CreateContext, CreateContextResponse),
437    (SynchronizeContexts, SynchronizeContextsResponse),
438    (LspExtSwitchSourceHeader, LspExtSwitchSourceHeaderResponse),
439    (LspExtGoToParentModule, LspExtGoToParentModuleResponse),
440    (LspExtCancelFlycheck, Ack),
441    (LspExtRunFlycheck, Ack),
442    (LspExtClearFlycheck, Ack),
443    (AddWorktree, AddWorktreeResponse),
444    (ShutdownRemoteServer, Ack),
445    (RemoveWorktree, Ack),
446    (OpenServerSettings, OpenBufferResponse),
447    (GetPermalinkToLine, GetPermalinkToLineResponse),
448    (FlushBufferedMessages, Ack),
449    (LanguageServerPromptRequest, LanguageServerPromptResponse),
450    (GitGetBranches, GitBranchesResponse),
451    (UpdateGitBranch, Ack),
452    (ListToolchains, ListToolchainsResponse),
453    (ActivateToolchain, Ack),
454    (ActiveToolchain, ActiveToolchainResponse),
455    (GetPathMetadata, GetPathMetadataResponse),
456    (GetCrashFiles, GetCrashFilesResponse),
457    (CancelLanguageServerWork, Ack),
458    (SyncExtensions, SyncExtensionsResponse),
459    (InstallExtension, Ack),
460    (RegisterBufferWithLanguageServers, Ack),
461    (GitShow, GitCommitDetails),
462    (GitReset, Ack),
463    (GitCheckoutFiles, Ack),
464    (SetIndexText, Ack),
465    (Push, RemoteMessageResponse),
466    (Fetch, RemoteMessageResponse),
467    (GetRemotes, GetRemotesResponse),
468    (Pull, RemoteMessageResponse),
469    (AskPassRequest, AskPassResponse),
470    (GitCreateBranch, Ack),
471    (GitChangeBranch, Ack),
472    (CheckForPushedCommits, CheckForPushedCommitsResponse),
473    (GitDiff, GitDiffResponse),
474    (GitInit, Ack),
475    (ToggleBreakpoint, Ack),
476    (GetDebugAdapterBinary, DebugAdapterBinary),
477    (RunDebugLocators, DebugRequest),
478    (GetDocumentDiagnostics, GetDocumentDiagnosticsResponse),
479    (PullWorkspaceDiagnostics, Ack),
480    (GetDefaultBranch, GetDefaultBranchResponse),
481    (GitClone, GitCloneResponse)
482);
483
484entity_messages!(
485    {project_id, ShareProject},
486    AddProjectCollaborator,
487    AddWorktree,
488    ApplyCodeAction,
489    ApplyCompletionAdditionalEdits,
490    BlameBuffer,
491    BufferReloaded,
492    BufferSaved,
493    CloseBuffer,
494    Commit,
495    GetColorPresentation,
496    CopyProjectEntry,
497    CreateBufferForPeer,
498    CreateProjectEntry,
499    GetDocumentColor,
500    DeleteProjectEntry,
501    ExpandProjectEntry,
502    ExpandAllForProjectEntry,
503    FindSearchCandidates,
504    ApplyCodeActionKind,
505    FormatBuffers,
506    GetCodeActions,
507    GetCodeLens,
508    GetCompletions,
509    GetDefinition,
510    GetDeclaration,
511    GetImplementation,
512    GetDocumentHighlights,
513    GetDocumentSymbols,
514    GetHover,
515    GetProjectSymbols,
516    GetReferences,
517    GetSignatureHelp,
518    OpenUnstagedDiff,
519    OpenUncommittedDiff,
520    GetTypeDefinition,
521    InlayHints,
522    JoinProject,
523    LeaveProject,
524    LinkedEditingRange,
525    LoadCommitDiff,
526    MultiLspQuery,
527    RestartLanguageServers,
528    StopLanguageServers,
529    OnTypeFormatting,
530    OpenNewBuffer,
531    OpenBufferById,
532    OpenBufferByPath,
533    OpenBufferForSymbol,
534    OpenCommitMessageBuffer,
535    PerformRename,
536    PrepareRename,
537    RefreshInlayHints,
538    RefreshCodeLens,
539    ReloadBuffers,
540    RemoveProjectCollaborator,
541    RenameProjectEntry,
542    ResolveCompletionDocumentation,
543    ResolveInlayHint,
544    SaveBuffer,
545    Stage,
546    StartLanguageServer,
547    SynchronizeBuffers,
548    TaskContextForLocation,
549    UnshareProject,
550    Unstage,
551    Stash,
552    StashPop,
553    UpdateBuffer,
554    UpdateBufferFile,
555    UpdateDiagnosticSummary,
556    UpdateDiffBases,
557    UpdateLanguageServer,
558    UpdateProject,
559    UpdateProjectCollaborator,
560    UpdateWorktree,
561    UpdateRepository,
562    RemoveRepository,
563    UpdateWorktreeSettings,
564    LspExtExpandMacro,
565    LspExtOpenDocs,
566    LspExtRunnables,
567    AdvertiseContexts,
568    OpenContext,
569    CreateContext,
570    UpdateContext,
571    SynchronizeContexts,
572    LspExtSwitchSourceHeader,
573    LspExtGoToParentModule,
574    LspExtCancelFlycheck,
575    LspExtRunFlycheck,
576    LspExtClearFlycheck,
577    LanguageServerLog,
578    Toast,
579    HideToast,
580    OpenServerSettings,
581    GetPermalinkToLine,
582    LanguageServerPromptRequest,
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    GetDefaultBranch,
614    GitClone
615);
616
617entity_messages!(
618    {channel_id, Channel},
619    ChannelMessageSent,
620    ChannelMessageUpdate,
621    RemoveChannelMessage,
622    UpdateChannelMessage,
623    UpdateChannelBuffer,
624    UpdateChannelBufferCollaborators,
625);
626
627impl From<Timestamp> for SystemTime {
628    fn from(val: Timestamp) -> Self {
629        UNIX_EPOCH
630            .checked_add(Duration::new(val.seconds, val.nanos))
631            .unwrap()
632    }
633}
634
635impl From<SystemTime> for Timestamp {
636    fn from(time: SystemTime) -> Self {
637        let duration = time.duration_since(UNIX_EPOCH).unwrap_or_default();
638        Self {
639            seconds: duration.as_secs(),
640            nanos: duration.subsec_nanos(),
641        }
642    }
643}
644
645impl From<u128> for Nonce {
646    fn from(nonce: u128) -> Self {
647        let upper_half = (nonce >> 64) as u64;
648        let lower_half = nonce as u64;
649        Self {
650            upper_half,
651            lower_half,
652        }
653    }
654}
655
656impl From<Nonce> for u128 {
657    fn from(nonce: Nonce) -> Self {
658        let upper_half = (nonce.upper_half as u128) << 64;
659        let lower_half = nonce.lower_half as u128;
660        upper_half | lower_half
661    }
662}
663
664#[cfg(any(test, feature = "test-support"))]
665pub const MAX_WORKTREE_UPDATE_MAX_CHUNK_SIZE: usize = 2;
666#[cfg(not(any(test, feature = "test-support")))]
667pub const MAX_WORKTREE_UPDATE_MAX_CHUNK_SIZE: usize = 256;
668
669pub fn split_worktree_update(mut message: UpdateWorktree) -> impl Iterator<Item = UpdateWorktree> {
670    let mut done = false;
671
672    iter::from_fn(move || {
673        if done {
674            return None;
675        }
676
677        let updated_entries_chunk_size = cmp::min(
678            message.updated_entries.len(),
679            MAX_WORKTREE_UPDATE_MAX_CHUNK_SIZE,
680        );
681        let updated_entries: Vec<_> = message
682            .updated_entries
683            .drain(..updated_entries_chunk_size)
684            .collect();
685
686        let removed_entries_chunk_size = cmp::min(
687            message.removed_entries.len(),
688            MAX_WORKTREE_UPDATE_MAX_CHUNK_SIZE,
689        );
690        let removed_entries = message
691            .removed_entries
692            .drain(..removed_entries_chunk_size)
693            .collect();
694
695        let mut updated_repositories = Vec::new();
696        let mut limit = MAX_WORKTREE_UPDATE_MAX_CHUNK_SIZE;
697        while let Some(repo) = message.updated_repositories.first_mut() {
698            let updated_statuses_limit = cmp::min(repo.updated_statuses.len(), limit);
699            let removed_statuses_limit = cmp::min(repo.removed_statuses.len(), limit);
700
701            updated_repositories.push(RepositoryEntry {
702                repository_id: repo.repository_id,
703                branch_summary: repo.branch_summary.clone(),
704                updated_statuses: repo
705                    .updated_statuses
706                    .drain(..updated_statuses_limit)
707                    .collect(),
708                removed_statuses: repo
709                    .removed_statuses
710                    .drain(..removed_statuses_limit)
711                    .collect(),
712                current_merge_conflicts: repo.current_merge_conflicts.clone(),
713            });
714            if repo.removed_statuses.is_empty() && repo.updated_statuses.is_empty() {
715                message.updated_repositories.remove(0);
716            }
717            limit = limit.saturating_sub(removed_statuses_limit + updated_statuses_limit);
718            if limit == 0 {
719                break;
720            }
721        }
722
723        done = message.updated_entries.is_empty()
724            && message.removed_entries.is_empty()
725            && message.updated_repositories.is_empty();
726
727        let removed_repositories = if done {
728            mem::take(&mut message.removed_repositories)
729        } else {
730            Default::default()
731        };
732
733        Some(UpdateWorktree {
734            project_id: message.project_id,
735            worktree_id: message.worktree_id,
736            root_name: message.root_name.clone(),
737            abs_path: message.abs_path.clone(),
738            updated_entries,
739            removed_entries,
740            scan_id: message.scan_id,
741            is_last_update: done && message.is_last_update,
742            updated_repositories,
743            removed_repositories,
744        })
745    })
746}
747
748pub fn split_repository_update(
749    mut update: UpdateRepository,
750) -> impl Iterator<Item = UpdateRepository> {
751    let mut updated_statuses_iter = mem::take(&mut update.updated_statuses).into_iter().fuse();
752    let mut removed_statuses_iter = mem::take(&mut update.removed_statuses).into_iter().fuse();
753    std::iter::from_fn({
754        let update = update.clone();
755        move || {
756            let updated_statuses = updated_statuses_iter
757                .by_ref()
758                .take(MAX_WORKTREE_UPDATE_MAX_CHUNK_SIZE)
759                .collect::<Vec<_>>();
760            let removed_statuses = removed_statuses_iter
761                .by_ref()
762                .take(MAX_WORKTREE_UPDATE_MAX_CHUNK_SIZE)
763                .collect::<Vec<_>>();
764            if updated_statuses.is_empty() && removed_statuses.is_empty() {
765                return None;
766            }
767            Some(UpdateRepository {
768                updated_statuses,
769                removed_statuses,
770                is_last_update: false,
771                ..update.clone()
772            })
773        }
774    })
775    .chain([UpdateRepository {
776        updated_statuses: Vec::new(),
777        removed_statuses: Vec::new(),
778        is_last_update: true,
779        ..update
780    }])
781}
782
783impl MultiLspQuery {
784    pub fn request_str(&self) -> &str {
785        match self.request {
786            Some(multi_lsp_query::Request::GetHover(_)) => "GetHover",
787            Some(multi_lsp_query::Request::GetCodeActions(_)) => "GetCodeActions",
788            Some(multi_lsp_query::Request::GetSignatureHelp(_)) => "GetSignatureHelp",
789            Some(multi_lsp_query::Request::GetCodeLens(_)) => "GetCodeLens",
790            Some(multi_lsp_query::Request::GetDocumentDiagnostics(_)) => "GetDocumentDiagnostics",
791            Some(multi_lsp_query::Request::GetDocumentColor(_)) => "GetDocumentColor",
792            Some(multi_lsp_query::Request::GetDefinition(_)) => "GetDefinition",
793            Some(multi_lsp_query::Request::GetDeclaration(_)) => "GetDeclaration",
794            Some(multi_lsp_query::Request::GetTypeDefinition(_)) => "GetTypeDefinition",
795            Some(multi_lsp_query::Request::GetImplementation(_)) => "GetImplementation",
796            Some(multi_lsp_query::Request::GetReferences(_)) => "GetReferences",
797            None => "<unknown>",
798        }
799    }
800}
801
802#[cfg(test)]
803mod tests {
804    use super::*;
805
806    #[test]
807    fn test_converting_peer_id_from_and_to_u64() {
808        let peer_id = PeerId {
809            owner_id: 10,
810            id: 3,
811        };
812        assert_eq!(PeerId::from_u64(peer_id.as_u64()), peer_id);
813        let peer_id = PeerId {
814            owner_id: u32::MAX,
815            id: 3,
816        };
817        assert_eq!(PeerId::from_u64(peer_id.as_u64()), peer_id);
818        let peer_id = PeerId {
819            owner_id: 10,
820            id: u32::MAX,
821        };
822        assert_eq!(PeerId::from_u64(peer_id.as_u64()), peer_id);
823        let peer_id = PeerId {
824            owner_id: u32::MAX,
825            id: u32::MAX,
826        };
827        assert_eq!(PeerId::from_u64(peer_id.as_u64()), peer_id);
828    }
829
830    #[test]
831    #[cfg(target_os = "windows")]
832    fn test_proto() {
833        use std::path::PathBuf;
834
835        fn generate_proto_path(path: PathBuf) -> PathBuf {
836            let proto = path.to_proto();
837            PathBuf::from_proto(proto)
838        }
839
840        let path = PathBuf::from("C:\\foo\\bar");
841        assert_eq!(path, generate_proto_path(path.clone()));
842
843        let path = PathBuf::from("C:/foo/bar/");
844        assert_eq!(path, generate_proto_path(path.clone()));
845
846        let path = PathBuf::from("C:/foo\\bar\\");
847        assert_eq!(path, generate_proto_path(path.clone()));
848    }
849}