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