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