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