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