proto.rs

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