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