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