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