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