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