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