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