proto.rs

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