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