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