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