proto.rs

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